build.xml revision 3618:64182008b2d0
1231990Smp<?xml version="1.0" encoding="UTF-8"?>
283098Smp<!--
383098Smp  ~ Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
483098Smp  ~ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
583098Smp  ~
683098Smp  ~ This code is free software; you can redistribute it and/or modify it
783098Smp  ~ under the terms of the GNU General Public License version 2 only, as
883098Smp  ~ published by the Free Software Foundation.  Oracle designates this
983098Smp  ~ particular file as subject to the "Classpath" exception as provided
10231990Smp  ~ by Oracle in the LICENSE file that accompanied this code.
11231990Smp  ~
1283098Smp  ~ This code is distributed in the hope that it will be useful, but WITHOUT
13231990Smp  ~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14231990Smp  ~ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15231990Smp  ~ version 2 for more details (a copy is included in the LICENSE file that
16231990Smp  ~ accompanied this code).
1783098Smp  ~
18  ~ You should have received a copy of the GNU General Public License version
19  ~ 2 along with this work; if not, write to the Free Software Foundation,
20  ~ Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21  ~
22  ~ Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
23  ~ or visit www.oracle.com if you need additional information or have any
24  ~ questions.
25  -->
26
27<!--
28 This is a convenience build file supporting development in the langtools
29 repository. It can be run either standalone, or from IDEs. This build script
30 is for a developer use only, it is not used to build the production version
31 of javac or other langtools tools.
32
33 External dependencies are specified via properties. These can be given
34 on the command line, or by providing a local build.properties file.
35 (They can also be edited into make/build.properties, although that is not
36 recommended.)  At a minimum, langtools.jdk.home must be set to the installed
37 location of the version of JDK used to build this repository. Additional
38 properties may be required, depending on the targets that are built.
39 For example, to run any of the jtreg tests you must set jtreg.home.
40
41 The output of the build is as follows:
42
43 build
44   |-bin (scripts to invoke various tools, javac, javah etc.)
45   |-genrsc (generated sources - i.e. properties)
46   |-modules (compiled classes in a modular layout)
47   |-jtreg (test work/results)
48   |-toolclasses (tools used for building - like the property compiler)
49
50 This file is organized into sections as follows:
51 - global property definitions
52 - primary top level targets (cleaning, building)
53 - utility definitions
54 -->
55
56<project name="langtools" default="build" basedir="..">
57    <!--
58    **** Global property definitions.
59    -->
60
61    <!-- The following locations can be used to override default property values. -->
62
63    <!-- Use this location for customizations specific to this instance of this workspace -->
64    <property file="build.properties"/>
65
66    <!-- Use this location for customizations common to all OpenJDK langtools workspaces -->
67    <property file="${user.home}/.openjdk/${ant.project.name}-build.properties"/>
68
69    <!-- Use this location for customizations common to all OpenJDK workspaces -->
70    <property file="${user.home}/.openjdk/build.properties"/>
71
72    <!-- Convenient shorthands for standard locations within the workspace. -->
73    <property name="src.dir" location="src"/>
74    <property name="test.dir" location="test"/>
75    <property name="make.dir" location="make"/>
76    <property name="make.conf.dir" location="${make.dir}/conf"/>
77    <property name="make.tools.dir" location="${make.dir}/tools"/>
78    <property name="build.dir" location="build"/>
79    <property name="build.modules" location="${build.dir}/modules"/>
80    <property name="build.gensrc" location="${build.dir}/gensrc"/>
81    <property name="build.tools" location="${build.dir}/toolclasses"/>
82    <property name="build.bin" location="${build.dir}/bin"/>
83    <property name="build.jtreg" location="${build.dir}/jtreg"/>
84    <property name="build.prevsrc" location="${build.dir}/prevsrc"/>
85
86    <pathconvert property="modules.names" pathsep=",">
87        <globmapper from="${src.dir}/*" to="*" />
88        <dirset dir="${src.dir}" includes="*.*"/>
89    </pathconvert>
90
91    <pathconvert property="xpatch.rest" pathsep=" --patch-module=">
92        <regexpmapper from="${file.separator}([^${file.separator}]+)$" to='\1="${build.modules}${file.separator}\1"' />
93        <dirset dir="${src.dir}" includes="*.*"/>
94    </pathconvert>
95
96    <pathconvert property="xpatch.noquotes.rest" pathsep=" --patch-module=">
97        <regexpmapper from="${file.separator}([^${file.separator}]+)$" to="\1=${build.modules}${file.separator}\1" />
98        <dirset dir="${src.dir}" includes="*.*"/>
99    </pathconvert>
100
101    <property name="xpatch.cmd" value="--patch-module=${xpatch.rest}"/>
102    <property name="xpatch.noquotes.cmd" value="--patch-module=${xpatch.noquotes.rest}"/>
103
104    <!-- java.marker is set to a marker file to check for within a Java install dir.
105         The best file to check for across Solaris/Linux/Windows/MacOS is one of the
106         executables; regrettably, that is OS-specific. -->
107    <condition property="java.marker" value="bin/java">
108        <os family="unix"/>
109    </condition>
110    <condition property="java.marker" value="bin/java.exe">
111        <os family="windows"/>
112    </condition>
113
114    <!-- Standard property values, if not overriden by earlier settings. -->
115    <property file="${make.dir}/build.properties"/>
116
117    <condition property="langtools.jdk.home" value="${jdk.home}">
118        <isset property="jdk.home" />
119    </condition>
120
121    <!-- launcher.java is used in the launcher scripts provided to run
122        the tools' jar files.  If it has not already been set, then
123        default it to use ${langtools.jdk.home}, if available, otherwise
124        quietly default to simply use "java". -->
125    <condition property="launcher.java"
126        value="${langtools.jdk.home}/bin/java" else="java">
127        <isset property="langtools.jdk.home"/>
128    </condition>
129
130    <!--
131        **** Check targets
132    -->
133
134    <target name="-def-check">
135      <macrodef name="check">
136          <attribute name="name"/>
137          <attribute name="property"/>
138          <attribute name="marker" default=""/>
139            <sequential>
140                <fail message="Cannot locate @{name}: please set @{property} to its location">
141                    <condition>
142                        <not>
143                            <isset property="@{property}"/>
144                        </not>
145                    </condition>
146                </fail>
147                <fail message="@{name} is not installed in ${@{property}}">
148                    <condition>
149                        <and>
150                            <not>
151                                <equals arg1="@{marker}" arg2=""/>
152                            </not>
153                            <not>
154                                <available file="${@{property}}/@{marker}"/>
155                            </not>
156                        </and>
157                    </condition>
158                </fail>
159            </sequential>
160        </macrodef>
161    </target>
162
163    <target name="-check-langtools.jdk.home" depends="-def-check">
164        <check name="target java" property="langtools.jdk.home" marker="${java.marker}"/>
165    </target>
166
167    <target name="-check-jtreg.home" depends="-def-check">
168        <check name="jtreg" property="jtreg.home" marker="lib/jtreg.jar"/>
169    </target>
170
171    <!--
172        **** Primary targets
173    -->
174
175    <target name="clean" description="Delete all generated files">
176        <delete dir="${build.dir}"/>
177    </target>
178
179    <target name="build" depends="build-all-tools"/>
180
181    <target name="-prepare-build" depends="-check-langtools.jdk.home">
182        <mkdir dir="${build.modules}"/>
183        <mkdir dir="${build.tools}"/>
184        <mkdir dir="${build.gensrc}"/>
185        <mkdir dir="${build.bin}"/>
186        <mkdir dir="${build.prevsrc}"/>
187    </target>
188
189    <target name="generate-sources-internal">
190        <basename property="module.name" file="${basedir}"/>
191        <pparse destdir="${build.gensrc}/${module.name}" includes="${langtools.resource.includes}">
192            <src path="./share/classes"/>
193        </pparse>
194        <pcompile destdir="${build.gensrc}/${module.name}" includes="**/*.properties">
195            <src path="./share/classes"/>
196        </pcompile>
197    </target>
198
199    <target name="generate-sources"  depends="-prepare-build,-def-pparse,-def-pcompile">
200        <subant inheritall="true" target="generate-sources-internal" genericantfile="${make.dir}/build.xml">
201              <dirset dir="${src.dir}" includes="*.*"/>
202        </subant>
203    </target>
204
205    <target name="build-all-classes" depends="generate-sources">
206        <exec executable="${langtools.jdk.home}/bin/javac" failonerror="true">
207            <arg line="-source ${javac.source} -target ${javac.target}" />
208            <arg value="-d" />
209            <arg value="${build.modules}" />
210            <arg line="${javac.opts} --module-source-path ${src.dir}${file.separator}*${file.separator}share${file.separator}classes:${build.gensrc} -m ${modules.names}" />
211        </exec>
212        <delete>
213            <fileset dir="${build.modules}" includes="**/module-info.class"/>
214        </delete>
215    </target>
216
217    <target name="build-all-tools" depends="build-all-classes, -def-build-tool">
218        <build-tool name="javac"/>
219        <build-tool name="javadoc"/>
220        <build-tool name="javap"/>
221        <build-tool name="javah"/>
222        <build-tool name="jdeps"/>
223        <build-tool name="sjavac"/>
224        <build-tool name="jshell"/>
225    </target>
226
227    <target name="jtreg" depends="build-all-tools,-def-jtreg">
228        <jtreg-tool name="all" tests="${jtreg.tests}"/>
229    </target>
230
231    <!--
232    **** IDE support
233    -->
234
235    <target name="idea" depends="-check-langtools.jdk.home">
236        <mkdir dir=".idea"/>
237        <copy todir=".idea" >
238            <fileset dir="make/intellij">
239               <exclude name="**/src/**"/>
240               <exclude name="**/utils/**"/>
241            </fileset>
242        </copy>
243        <condition property="idea.jtreg.home" value="${jtreg.home}" else = "[jtreg.home]">
244            <isset property="jtreg.home"/>
245        </condition>
246        <condition property="idea.target.jdk" value="${langtools.jdk.home}" else = "$JDKPath$">
247            <isset property="langtools.jdk.home"/>
248        </condition>
249        <replace file=".idea/ant.xml" token="@IDEA_TARGET_JDK@" value="${idea.target.jdk}"/>
250        <replace dir=".idea/runConfigurations" token="@IDEA_TARGET_JDK@" value="${idea.target.jdk}"/>
251        <replace dir=".idea/runConfigurations" token="@XPATCH@" value="${xpatch.cmd}"/>
252        <replace file=".idea/misc.xml" token="@IDEA_JTREG_HOME@" value="${idea.jtreg.home}"/>
253        <replace file=".idea/misc.xml" token="@IDEA_TARGET_JDK@" value="${idea.target.jdk}"/>
254        <replace file=".idea/misc.xml" token="@XPATCH@" value="${xpatch.cmd}"/>
255        <mkdir dir=".idea/classes"/>
256        <javac source="${javac.build.source}"
257               target="${javac.build.target}"
258               srcdir="make/intellij/src"
259               destdir=".idea/classes"/>
260    </target>
261
262    <!--
263        **** Utility definitions
264    -->
265
266    <target name="-def-pparse">
267        <copy todir="${build.tools}/propertiesparser" >
268            <fileset dir="${make.tools.dir}/propertiesparser" includes="**/resources/**"/>
269        </copy>
270        <javac source="${javac.build.source}"
271               target="${javac.build.target}"
272               srcdir="${make.tools.dir}"
273               includes="propertiesparser/* anttasks/PropertiesParser* anttasks/PathFileSet*"
274               destdir="${build.tools}"
275               classpath="${ant.core.lib}"
276               bootclasspath="${langtools.jdk.home}/jre/lib/rt.jar"
277               includeantruntime="false">
278            <compilerarg line="${javac.opts} -XDstringConcat=inline"/>
279        </javac>
280        <taskdef name="pparse"
281                 classname="anttasks.PropertiesParserTask"
282                 classpath="${build.tools}"/>
283    </target>
284
285     <target name="-def-pcompile">
286        <javac
287               source="${javac.build.source}"
288               target="${javac.build.target}"
289               srcdir="${make.tools.dir}"
290               includes="compileproperties/* anttasks/CompileProperties* anttasks/PathFileSet*"
291               destdir="${build.dir}/toolclasses/"
292               classpath="${ant.core.lib}"
293               includeantruntime="false">
294            <compilerarg line="${javac.opts} -XDstringConcat=inline"/>
295        </javac>
296        <taskdef name="pcompile"
297                 classname="anttasks.CompilePropertiesTask"
298                 classpath="${build.tools}"/>
299    </target>
300
301    <target name="-def-build-tool">
302        <macrodef name="build-tool">
303            <attribute name="name"/>
304            <attribute name="compilation.kind" default=""/>
305            <attribute name="bin.dir" default="${build.bin}"/>
306            <attribute name="java" default="${launcher.java}"/>
307            <attribute name="main.class" default="${tool.@{name}.main.class}"/>
308            <attribute name="xpatch" default="${xpatch.cmd}"/>
309            <sequential>
310                <mkdir dir="@{bin.dir}"/>
311                <copy file="${make.dir}/launcher.sh-template" tofile="@{bin.dir}/@{name}">
312                    <filterset begintoken="#" endtoken="#">
313                        <filter token="PROGRAM" value="@{main.class}"/>
314                        <filter token="TARGET_JAVA" value="@{java}"/>
315                        <filter token="PS" value="${path.separator}"/>
316                        <filter token="XPATCH" value="${xpatch.cmd}"/>
317                    </filterset>
318                </copy>
319                <chmod file="@{bin.dir}/@{name}" perm="ugo+rx"/>
320            </sequential>
321        </macrodef>
322    </target>
323
324    <target name="-def-jtreg" unless="jtreg.defined" depends="-check-jtreg.home,-check-langtools.jdk.home">
325        <taskdef name="jtreg" classname="com.sun.javatest.regtest.Main$$Ant">
326            <classpath>
327                <pathelement location="${jtreg.home}/lib/jtreg.jar"/>
328                <pathelement location="${jtreg.home}/lib/javatest.jar"/>
329            </classpath>
330        </taskdef>
331        <macrodef name="jtreg-tool">
332            <attribute name="name"/>
333            <attribute name="tests"/>
334            <attribute name="jdk" default="${langtools.jdk.home}"/>
335            <attribute name="agentvm" default="true"/>
336            <attribute name="verbose" default="${default.jtreg.verbose}"/>
337            <attribute name="options" default="${other.jtreg.options}"/>
338            <attribute name="keywords" default="-keywords:!ignore"/>
339            <attribute name="jpda.jvmargs" default=""/>
340            <attribute name="extra.jvmargs" default=""/>
341            <attribute name="build.modules" default="${build.modules}"/>
342            <sequential>
343                <property name="coverage.options" value=""/>              <!-- default -->
344                <property name="coverage.classpath" value=""/>            <!-- default -->
345                <property name="default.jtreg.verbose" value="summary"/>  <!-- default -->
346                <property name="other.jtreg.options" value=""/>           <!-- default -->
347                <property name="jtreg.classfiles.to.modules" value="@{agentvm}"/>
348                <jtreg
349                    dir="${test.dir}"
350                    workDir="${build.jtreg}/@{name}/work"
351                    reportDir="${build.jtreg}/@{name}/report"
352                    jdk="@{jdk}"
353                    agentvm="@{agentvm}" verbose="@{verbose}"
354                    failonerror="false" resultproperty="jtreg.@{name}.result"
355                    vmoptions="${coverage.options} @{extra.jvmargs} ${xpatch.noquotes.cmd}">
356                    <arg value="-debug:@{jpda.jvmargs}"/>
357                    <arg line="@{keywords}"/>
358                    <arg line="@{options}"/>
359                    <arg line="@{tests}"/>
360                </jtreg>
361                <!-- the next two properties are for convenience, when only
362                     a single instance of jtreg will be invoked. -->
363                <condition property="jtreg.passed">
364                    <equals arg1="${jtreg.@{name}.result}" arg2="0"/>
365                </condition>
366                <property name="jtreg.report" value="${build.jtreg}/@{name}/report"/>
367            </sequential>
368        </macrodef>
369        <property name="jtreg.defined" value="true"/>
370    </target>
371</project>
372