This repository was archived by the owner on Jul 18, 2024. It is now read-only.
forked from kaitai-io/kaitai_struct_gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.xml
104 lines (77 loc) · 4 KB
/
build.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<project name="kaitai-struct-gui">
<!-- https://ant.apache.org/manual/ -->
<property name="java.output.package" value="compiled_from_ksy"/>
<!-- This property is set automatically when run Ant is run through Maven.
Here we are setting it manually for when you want to run the Ant script alone. -->
<property name="project.build.testSourceDirectory" value="src/test/java"/>
<property name="ksy.source.dir" value="src/test/resources/ksy"/>
<!-- Make environment variables accessible using the 'env' prefix -->
<property environment="env"/>
<target name="-check.ksc.home.is.set">
<condition property="is.ksc.home.set">
<isset property="env.KAITAI_STRUCT_COMPILER_HOME"/>
</condition>
</target>
<target name="-check.ksc.available" depends="-check.ksc.home.is.set" if="is.ksc.home.set">
<!-- On Windows use .bat file, otherwise use shell script. -->
<condition property="ksc.file.name" value="kaitai-struct-compiler.bat" else="kaitai-struct-compiler">
<os family="windows"/>
</condition>
<property name="ksc.absolute.path" value="${env.KAITAI_STRUCT_COMPILER_HOME}\bin\${ksc.file.name}"/>
<available property="is.ksc.available" file="${ksc.absolute.path}"/>
</target>
<target name="-get.list.of.ksy.files">
<pathconvert pathsep=" " property="ksy.files">
<path>
<fileset dir="${ksy.source.dir}">
<include name="*.ksy"/>
</fileset>
</path>
<mapper>
<globmapper from="*" to=""*""/> <!-- Wrap each path in quotes -->
</mapper>
</pathconvert>
</target>
<!--
<target name="check-if-up-to-date" depends="-get.list.of.ksy.files">
<uptodate property="already.up.to.date">
<srcfiles dir="${ksy.source.dir}" includes="*.ksy"/>
<chainedmapper>
<flattenmapper/>
<scriptmapper language="javascript" setbeans="false">
// map ksy file name to java file name
firstCharacterUppercase = source.charAt(0).toUpperCase() + source.substring(1);
regex = /_[a-z]/g;
result = firstCharacterUppercase.replace(regex, function(str) {
return str.substring(1).toUpperCase();
});
self.addMappedName(result);
</scriptmapper>
<globmapper from="*.ksy" to="${ksy.source.dir}/${java.output.package}/*.java"/>
</chainedmapper>
</uptodate>
<echo level="info" message="${already.up.to.date}"/>
</target>
-->
<target name="-run.ksc" depends="-check.ksc.available, -get.list.of.ksy.files" if="is.ksc.available">
<exec executable="${ksc.absolute.path}" outputproperty="ksc-output"
failifexecutionfails="true" failonerror="false" resultproperty="ksc.return.code">
<arg line="--target java --outdir "${project.build.testSourceDirectory}" --java-package ${java.output.package} --read-pos ${ksy.files} "/>
</exec>
<condition property="ksc.failed">
<not>
<equals arg1="${ksc.return.code}" arg2="0"/>
</not>
</condition>
</target>
<target name="-check.ksc.error" if="ksc.failed" depends="-run.ksc">
<echo level="error" message="====================== Output from kaitai-struct-compiler: ================="/>
<echo level="error" message="${ksc-output}"/>
<echo level="error" message="============================================================================"/>
<fail message="kaitai-struct-compiler returned error code ${ksc.return.code}"/>
</target>
<target name="compile.ksy.files.to.java" depends="-run.ksc, -check.ksc.error"/>
<target name="clean.java.files.compiled.from.ksy">
<delete dir="${project.build.testSourceDirectory}/${java.output.package}"/>
</target>
</project>