build.xml revision 3379:55d555868636
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 file=".idea/workspace.xml" token="@IDEA_TARGET_JDK@" value="${idea.target.jdk}"/>
243        <replace file=".idea/workspace.xml" token="@XPATCH@" value="${xpatch.cmd}"/>
244        <replace file=".idea/workspace.xml" token="@PATH_SEP@" value="${path.separator}"/>
245        <mkdir dir=".idea/classes"/>
246        <javac srcdir="make/intellij/src"
247               destdir=".idea/classes"/>
248    </target>
249
250    <!--
251        **** Utility definitions
252    -->
253
254    <target name="-def-pparse">
255        <copy todir="${build.tools}/propertiesparser" >
256            <fileset dir="${make.tools.dir}/propertiesparser" includes="**/resources/**"/>
257        </copy>
258        <javac fork="true"
259               source="${javac.source}"
260               target="${javac.target}"
261               executable="${langtools.jdk.home}/bin/javac"
262               srcdir="${make.tools.dir}"
263               includes="propertiesparser/* anttasks/PropertiesParser* anttasks/PathFileSet*"
264               destdir="${build.tools}"
265               classpath="${ant.core.lib}"
266               bootclasspath="${langtools.jdk.home}/jre/lib/rt.jar"
267               includeantruntime="false">
268            <compilerarg line="${javac.opts} -XDstringConcat=inline"/>
269        </javac>
270        <taskdef name="pparse"
271                 classname="anttasks.PropertiesParserTask"
272                 classpath="${build.tools}"/>
273    </target>
274
275     <target name="-def-pcompile">
276        <javac fork="true"
277               source="${javac.source}"
278               target="${javac.target}"
279               executable="${langtools.jdk.home}/bin/javac"
280               srcdir="${make.tools.dir}"
281               includes="compileproperties/* anttasks/CompileProperties* anttasks/PathFileSet*"
282               destdir="${build.dir}/toolclasses/"
283               classpath="${ant.core.lib}"
284               includeantruntime="false">
285            <compilerarg line="${javac.opts} -XDstringConcat=inline"/>
286        </javac>
287        <taskdef name="pcompile"
288                 classname="anttasks.CompilePropertiesTask"
289                 classpath="${build.tools}"/>
290    </target>
291
292    <target name="-def-build-tool">
293        <macrodef name="build-tool">
294            <attribute name="name"/>
295            <attribute name="compilation.kind" default=""/>
296            <attribute name="bin.dir" default="${build.bin}"/>
297            <attribute name="java" default="${launcher.java}"/>
298            <attribute name="main.class" default="${tool.@{name}.main.class}"/>
299            <attribute name="xpatch" default="${xpatch.cmd}"/>
300            <sequential>
301                <mkdir dir="@{bin.dir}"/>
302                <copy file="${make.dir}/launcher.sh-template" tofile="@{bin.dir}/@{name}">
303                    <filterset begintoken="#" endtoken="#">
304                        <filter token="PROGRAM" value="@{main.class}"/>
305                        <filter token="TARGET_JAVA" value="@{java}"/>
306                        <filter token="PS" value="${path.separator}"/>
307                        <filter token="XPATCH" value="${xpatch.cmd}"/>
308                    </filterset>
309                </copy>
310                <chmod file="@{bin.dir}/@{name}" perm="ugo+rx"/>
311            </sequential>
312        </macrodef>
313    </target>
314
315    <target name="-def-jtreg" unless="jtreg.defined" depends="-check-jtreg.home,-check-langtools.jdk.home">
316        <taskdef name="jtreg" classname="com.sun.javatest.regtest.Main$$Ant">
317            <classpath>
318                <pathelement location="${jtreg.home}/lib/jtreg.jar"/>
319                <pathelement location="${jtreg.home}/lib/javatest.jar"/>
320            </classpath>
321        </taskdef>
322        <macrodef name="jtreg-tool">
323            <attribute name="name"/>
324            <attribute name="tests"/>
325            <attribute name="jdk" default="${langtools.jdk.home}"/>
326            <attribute name="agentvm" default="true"/>
327            <attribute name="verbose" default="${default.jtreg.verbose}"/>
328            <attribute name="options" default="${other.jtreg.options}"/>
329            <attribute name="keywords" default="-keywords:!ignore"/>
330            <attribute name="jpda.jvmargs" default=""/>
331            <attribute name="extra.jvmargs" default=""/>
332            <attribute name="build.modules" default="${build.modules}"/>
333            <sequential>
334                <property name="coverage.options" value=""/>              <!-- default -->
335                <property name="coverage.classpath" value=""/>            <!-- default -->
336                <property name="default.jtreg.verbose" value="summary"/>  <!-- default -->
337                <property name="other.jtreg.options" value=""/>           <!-- default -->
338                <property name="jtreg.classfiles.to.modules" value="@{agentvm}"/>
339                <jtreg
340                    dir="${test.dir}"
341                    workDir="${build.jtreg}/@{name}/work"
342                    reportDir="${build.jtreg}/@{name}/report"
343                    jdk="@{jdk}"
344                    agentvm="@{agentvm}" verbose="@{verbose}"
345                    failonerror="false" resultproperty="jtreg.@{name}.result"
346                    vmoptions="${coverage.options} @{extra.jvmargs} ${xpatch.cmd}">
347                    <arg value="-debug:@{jpda.jvmargs}"/>
348                    <arg line="@{keywords}"/>
349                    <arg line="@{options}"/>
350                    <arg line="@{tests}"/>
351                </jtreg>
352                <!-- the next two properties are for convenience, when only
353                     a single instance of jtreg will be invoked. -->
354                <condition property="jtreg.passed">
355                    <equals arg1="${jtreg.@{name}.result}" arg2="0"/>
356                </condition>
357                <property name="jtreg.report" value="${build.jtreg}/@{name}/report"/>
358            </sequential>
359        </macrodef>
360        <property name="jtreg.defined" value="true"/>
361    </target>
362</project>
363