build.xml revision 3411:0b233e7be137
1<?xml version="1.0" encoding="UTF-8"?>
2<!--
3  ~ Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
4  ~ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  ~
6  ~ This code is free software; you can redistribute it and/or modify it
7  ~ under the terms of the GNU General Public License version 2 only, as
8  ~ published by the Free Software Foundation.  Oracle designates this
9  ~ particular file as subject to the "Classpath" exception as provided
10  ~ by Oracle in the LICENSE file that accompanied this code.
11  ~
12  ~ This code is distributed in the hope that it will be useful, but WITHOUT
13  ~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  ~ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15  ~ version 2 for more details (a copy is included in the LICENSE file that
16  ~ accompanied this code).
17  ~
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=" -Xpatch:">
92        <regexpmapper from="${file.separator}([^${file.separator}]+)$" to="\1=${build.modules}${file.separator}\1" />
93        <dirset dir="${src.dir}" includes="*.*"/>
94    </pathconvert>
95
96    <property name="xpatch.cmd" value="-Xpatch:${xpatch.rest}"/>
97
98    <!-- java.marker is set to a marker file to check for within a Java install dir.
99         The best file to check for across Solaris/Linux/Windows/MacOS is one of the
100         executables; regrettably, that is OS-specific. -->
101    <condition property="java.marker" value="bin/java">
102        <os family="unix"/>
103    </condition>
104    <condition property="java.marker" value="bin/java.exe">
105        <os family="windows"/>
106    </condition>
107
108    <!-- Standard property values, if not overriden by earlier settings. -->
109    <property file="${make.dir}/build.properties"/>
110
111    <condition property="langtools.jdk.home" value="${jdk.home}">
112        <isset property="jdk.home" />
113    </condition>
114
115    <!-- launcher.java is used in the launcher scripts provided to run
116        the tools' jar files.  If it has not already been set, then
117        default it to use ${langtools.jdk.home}, if available, otherwise
118        quietly default to simply use "java". -->
119    <condition property="launcher.java"
120        value="${langtools.jdk.home}/bin/java" else="java">
121        <isset property="langtools.jdk.home"/>
122    </condition>
123
124    <!--
125        **** Check targets
126    -->
127
128    <target name="-def-check">
129      <macrodef name="check">
130          <attribute name="name"/>
131          <attribute name="property"/>
132          <attribute name="marker" default=""/>
133            <sequential>
134                <fail message="Cannot locate @{name}: please set @{property} to its location">
135                    <condition>
136                        <not>
137                            <isset property="@{property}"/>
138                        </not>
139                    </condition>
140                </fail>
141                <fail message="@{name} is not installed in ${@{property}}">
142                    <condition>
143                        <and>
144                            <not>
145                                <equals arg1="@{marker}" arg2=""/>
146                            </not>
147                            <not>
148                                <available file="${@{property}}/@{marker}"/>
149                            </not>
150                        </and>
151                    </condition>
152                </fail>
153            </sequential>
154        </macrodef>
155    </target>
156
157    <target name="-check-langtools.jdk.home" depends="-def-check">
158        <check name="target java" property="langtools.jdk.home" marker="${java.marker}"/>
159    </target>
160
161    <target name="-check-jtreg.home" depends="-def-check">
162        <check name="jtreg" property="jtreg.home" marker="lib/jtreg.jar"/>
163    </target>
164
165    <!--
166        **** Primary targets
167    -->
168
169    <target name="clean" description="Delete all generated files">
170        <delete dir="${build.dir}"/>
171    </target>
172
173    <target name="build" depends="build-all-tools"/>
174
175    <target name="-prepare-build" depends="-check-langtools.jdk.home">
176        <mkdir dir="${build.modules}"/>
177        <mkdir dir="${build.tools}"/>
178        <mkdir dir="${build.gensrc}"/>
179        <mkdir dir="${build.bin}"/>
180        <mkdir dir="${build.prevsrc}"/>
181    </target>
182
183    <target name="generate-sources-internal">
184        <basename property="module.name" file="${basedir}"/>
185        <pparse destdir="${build.gensrc}/${module.name}" includes="${langtools.resource.includes}">
186            <src path="./share/classes"/>
187        </pparse>
188        <pcompile destdir="${build.gensrc}/${module.name}" includes="**/*.properties">
189            <src path="./share/classes"/>
190        </pcompile>
191    </target>
192
193    <target name="generate-sources"  depends="-prepare-build,-def-pparse,-def-pcompile">
194        <subant inheritall="true" target="generate-sources-internal" genericantfile="${make.dir}/build.xml">
195              <dirset dir="${src.dir}" includes="*.*"/>
196        </subant>
197    </target>
198
199    <target name="build-all-classes" depends="generate-sources">
200        <exec executable="${langtools.jdk.home}/bin/javac" failonerror="true">
201            <arg line="-source ${javac.source} -target ${javac.target}" />
202            <arg value="-d" />
203            <arg value="${build.modules}" />
204            <arg line="${javac.opts} -modulesourcepath ${src.dir}${file.separator}*${file.separator}share${file.separator}classes:${build.gensrc} -m ${modules.names}" />
205        </exec>
206        <delete>
207            <fileset dir="${build.modules}" includes="**/module-info.class"/>
208        </delete>
209    </target>
210
211    <target name="build-all-tools" depends="build-all-classes, -def-build-tool">
212        <build-tool name="javac"/>
213        <build-tool name="javadoc"/>
214        <build-tool name="javap"/>
215        <build-tool name="javah"/>
216        <build-tool name="jdeps"/>
217        <build-tool name="sjavac"/>
218        <build-tool name="jshell"/>
219    </target>
220
221    <target name="jtreg" depends="build-all-tools,-def-jtreg">
222        <jtreg-tool name="all" tests="${jtreg.tests}"/>
223    </target>
224
225    <!--
226    **** IDE support
227    -->
228
229    <target name="idea" depends="-check-langtools.jdk.home">
230        <mkdir dir=".idea"/>
231        <copy todir=".idea" >
232            <fileset dir="make/intellij" excludes="**/src/**"/>
233        </copy>
234        <condition property="idea.jtreg.home" value="${jtreg.home}" else = "[jtreg.home]">
235            <isset property="jtreg.home"/>
236        </condition>
237        <condition property="idea.target.jdk" value="${langtools.jdk.home}" else = "$JDKPath$">
238            <isset property="langtools.jdk.home"/>
239        </condition>
240        <replace file=".idea/ant.xml" token="@IDEA_JTREG_HOME@" value="${idea.jtreg.home}"/>
241        <replace file=".idea/ant.xml" token="@IDEA_TARGET_JDK@" value="${idea.target.jdk}"/>
242        <replace dir=".idea/runConfigurations" token="@IDEA_TARGET_JDK@" value="${idea.target.jdk}"/>
243        <replace dir=".idea/runConfigurations" token="@XPATCH@" value="${xpatch.cmd}"/>
244        <mkdir dir=".idea/classes"/>
245        <javac source="${javac.build.source}"
246               target="${javac.build.target}"
247               srcdir="make/intellij/src"
248               destdir=".idea/classes"/>
249    </target>
250
251    <!--
252        **** Utility definitions
253    -->
254
255    <target name="-def-pparse">
256        <copy todir="${build.tools}/propertiesparser" >
257            <fileset dir="${make.tools.dir}/propertiesparser" includes="**/resources/**"/>
258        </copy>
259        <javac source="${javac.build.source}"
260               target="${javac.build.target}"
261               srcdir="${make.tools.dir}"
262               includes="propertiesparser/* anttasks/PropertiesParser* anttasks/PathFileSet*"
263               destdir="${build.tools}"
264               classpath="${ant.core.lib}"
265               bootclasspath="${langtools.jdk.home}/jre/lib/rt.jar"
266               includeantruntime="false">
267            <compilerarg line="${javac.opts} -XDstringConcat=inline"/>
268        </javac>
269        <taskdef name="pparse"
270                 classname="anttasks.PropertiesParserTask"
271                 classpath="${build.tools}"/>
272    </target>
273
274     <target name="-def-pcompile">
275        <javac
276               source="${javac.build.source}"
277               target="${javac.build.target}"
278               srcdir="${make.tools.dir}"
279               includes="compileproperties/* anttasks/CompileProperties* anttasks/PathFileSet*"
280               destdir="${build.dir}/toolclasses/"
281               classpath="${ant.core.lib}"
282               includeantruntime="false">
283            <compilerarg line="${javac.opts} -XDstringConcat=inline"/>
284        </javac>
285        <taskdef name="pcompile"
286                 classname="anttasks.CompilePropertiesTask"
287                 classpath="${build.tools}"/>
288    </target>
289
290    <target name="-def-build-tool">
291        <macrodef name="build-tool">
292            <attribute name="name"/>
293            <attribute name="compilation.kind" default=""/>
294            <attribute name="bin.dir" default="${build.bin}"/>
295            <attribute name="java" default="${launcher.java}"/>
296            <attribute name="main.class" default="${tool.@{name}.main.class}"/>
297            <attribute name="xpatch" default="${xpatch.cmd}"/>
298            <sequential>
299                <mkdir dir="@{bin.dir}"/>
300                <copy file="${make.dir}/launcher.sh-template" tofile="@{bin.dir}/@{name}">
301                    <filterset begintoken="#" endtoken="#">
302                        <filter token="PROGRAM" value="@{main.class}"/>
303                        <filter token="TARGET_JAVA" value="@{java}"/>
304                        <filter token="PS" value="${path.separator}"/>
305                        <filter token="XPATCH" value="${xpatch.cmd}"/>
306                    </filterset>
307                </copy>
308                <chmod file="@{bin.dir}/@{name}" perm="ugo+rx"/>
309            </sequential>
310        </macrodef>
311    </target>
312
313    <target name="-def-jtreg" unless="jtreg.defined" depends="-check-jtreg.home,-check-langtools.jdk.home">
314        <taskdef name="jtreg" classname="com.sun.javatest.regtest.Main$$Ant">
315            <classpath>
316                <pathelement location="${jtreg.home}/lib/jtreg.jar"/>
317                <pathelement location="${jtreg.home}/lib/javatest.jar"/>
318            </classpath>
319        </taskdef>
320        <macrodef name="jtreg-tool">
321            <attribute name="name"/>
322            <attribute name="tests"/>
323            <attribute name="jdk" default="${langtools.jdk.home}"/>
324            <attribute name="agentvm" default="true"/>
325            <attribute name="verbose" default="${default.jtreg.verbose}"/>
326            <attribute name="options" default="${other.jtreg.options}"/>
327            <attribute name="keywords" default="-keywords:!ignore"/>
328            <attribute name="jpda.jvmargs" default=""/>
329            <attribute name="extra.jvmargs" default=""/>
330            <attribute name="build.modules" default="${build.modules}"/>
331            <sequential>
332                <property name="coverage.options" value=""/>              <!-- default -->
333                <property name="coverage.classpath" value=""/>            <!-- default -->
334                <property name="default.jtreg.verbose" value="summary"/>  <!-- default -->
335                <property name="other.jtreg.options" value=""/>           <!-- default -->
336                <property name="jtreg.classfiles.to.modules" value="@{agentvm}"/>
337                <jtreg
338                    dir="${test.dir}"
339                    workDir="${build.jtreg}/@{name}/work"
340                    reportDir="${build.jtreg}/@{name}/report"
341                    jdk="@{jdk}"
342                    agentvm="@{agentvm}" verbose="@{verbose}"
343                    failonerror="false" resultproperty="jtreg.@{name}.result"
344                    vmoptions="${coverage.options} @{extra.jvmargs} ${xpatch.cmd}">
345                    <arg value="-debug:@{jpda.jvmargs}"/>
346                    <arg line="@{keywords}"/>
347                    <arg line="@{options}"/>
348                    <arg line="@{tests}"/>
349                </jtreg>
350                <!-- the next two properties are for convenience, when only
351                     a single instance of jtreg will be invoked. -->
352                <condition property="jtreg.passed">
353                    <equals arg1="${jtreg.@{name}.result}" arg2="0"/>
354                </condition>
355                <property name="jtreg.report" value="${build.jtreg}/@{name}/report"/>
356            </sequential>
357        </macrodef>
358        <property name="jtreg.defined" value="true"/>
359    </target>
360</project>
361