1 <?xml version="1.0" encoding="UTF-8"?>
  2 <!--
  3   ~ Copyright (c) 2007, 2024, 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 etc.)
 45    |-gensrc (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="make/langtools/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/langtools"/>
 76     <property name="make.idea.dir" location="make/ide/idea/langtools"/>
 77     <property name="make.conf.dir" location="${make.dir}/conf"/>
 78     <property name="make.tools.dir" location="${make.dir}/tools"/>
 79     <property name="build.dir" location="build/langtools"/>
 80     <property name="build.modules" location="${build.dir}/modules"/>
 81     <property name="build.gensrc" location="${build.dir}/gensrc"/>
 82     <property name="build.tools" location="${build.dir}/toolclasses"/>
 83     <property name="build.bin" location="${build.dir}/bin"/>
 84     <property name="build.jtreg" location="${build.dir}/jtreg"/>
 85     <property name="build.prevsrc" location="${build.dir}/prevsrc"/>
 86 
 87     <dirset id="src.module.dirset" dir="${src.dir}" includes="${module.names}"/>
 88 
 89     <pathconvert pathsep="," property="src.module.dirs" refid="src.module.dirset"/>
 90 
 91     <pathconvert property="xpatch.rest" pathsep=" --patch-module=" refid="src.module.dirset">
 92         <regexpmapper from="^.*(/|\\)([^/\\]*)$" to='\2="${build.modules}\1\2"' />
 93     </pathconvert>
 94 
 95     <pathconvert property="xpatch.noquotes.rest" pathsep=" --patch-module=" refid="src.module.dirset">
 96         <regexpmapper from="^([^/\\]*)(/|\\).*" to="\1=${build.modules}\2\1" />
 97     </pathconvert>
 98 
 99     <property name="xpatch.cmd" value="--patch-module=${xpatch.rest}"/>
100     <property name="xpatch.noquotes.cmd" value="--patch-module=${xpatch.noquotes.rest}"/>
101 
102     <!-- java.marker is set to a marker file to check for within a Java install dir.
103          The best file to check for across Linux/Windows/MacOS is one of the
104          executables; regrettably, that is OS-specific. -->
105     <condition property="java.marker" value="bin/java">
106         <os family="unix"/>
107     </condition>
108     <condition property="java.marker" value="bin/java.exe">
109         <os family="windows"/>
110     </condition>
111 
112     <!-- Standard property values, if not overridden by earlier settings. -->
113     <property file="${make.dir}/build.properties"/>
114 
115     <condition property="langtools.jdk.home" value="${jdk.home}">
116         <isset property="jdk.home" />
117     </condition>
118 
119     <!-- launcher.java is used in the launcher scripts provided to run
120         the tools' jar files.  If it has not already been set, then
121         default it to use ${langtools.jdk.home}, if available, otherwise
122         quietly default to simply use "java". -->
123     <condition property="launcher.java"
124         value="${langtools.jdk.home}/bin/java" else="java">
125         <isset property="langtools.jdk.home"/>
126     </condition>
127 
128     <!--
129         **** Check targets
130     -->
131 
132     <target name="-def-check">
133       <macrodef name="check">
134           <attribute name="name"/>
135           <attribute name="property"/>
136           <attribute name="marker" default=""/>
137             <sequential>
138                 <fail message="Cannot locate @{name}: please set @{property} to its location">
139                     <condition>
140                         <not>
141                             <isset property="@{property}"/>
142                         </not>
143                     </condition>
144                 </fail>
145                 <fail message="@{name} is not installed in ${@{property}}">
146                     <condition>
147                         <and>
148                             <not>
149                                 <equals arg1="@{marker}" arg2=""/>
150                             </not>
151                             <not>
152                                 <available file="${@{property}}/@{marker}"/>
153                             </not>
154                         </and>
155                     </condition>
156                 </fail>
157             </sequential>
158         </macrodef>
159     </target>
160 
161     <target name="-check-langtools.jdk.home" depends="-def-check">
162         <check name="target java" property="langtools.jdk.home" marker="${java.marker}"/>
163     </target>
164 
165     <target name="-check-jtreg.home" depends="-def-check">
166         <check name="jtreg" property="jtreg.home" marker="lib/jtreg.jar"/>
167     </target>
168 
169     <!--
170         **** Primary targets
171     -->
172 
173     <target name="clean" description="Delete all generated files">
174         <delete dir="${build.dir}"/>
175     </target>
176 
177     <target name="build" depends="build-all-tools"/>
178 
179     <target name="-prepare-build" depends="-check-langtools.jdk.home">
180         <mkdir dir="${build.modules}"/>
181         <mkdir dir="${build.tools}"/>
182         <mkdir dir="${build.gensrc}"/>
183         <mkdir dir="${build.bin}"/>
184         <mkdir dir="${build.prevsrc}"/>
185     </target>
186 
187     <target name="generate-sources-internal">
188         <basename property="module.name" file="${basedir}"/>
189         <mkdir dir="${build.gensrc}/${module.name}"/>
190         <pparse destdir="${build.gensrc}/${module.name}" includes="${langtools.resource.includes}">
191             <src path="./share/classes"/>
192         </pparse>
193         <pcompile destdir="${build.gensrc}/${module.name}" includes="**/*.properties">
194             <src path="./share/classes"/>
195         </pcompile>
196     </target>
197 
198     <target name="copy-cr-sources">
199         <exec executable="/bin/bash">
200             <arg value="cr-util/copy-to-compiler.sh"/>
201             <arg value="src/java.base/share/classes"/>
202             <arg value="${build.gensrc}/jdk.compiler"/>
203         </exec>
204     </target>
205 
206     <target name="generate-sources"  depends="copy-cr-sources,-prepare-build,-def-pparse,-def-pcompile">
207         <subant inheritall="true" target="generate-sources-internal" genericantfile="${make.dir}/build.xml">
208               <dirset refid="src.module.dirset"/>
209         </subant>
210     </target>
211 
212     <target name="build-all-classes" depends="generate-sources">
213         <pathconvert property="xpatch.src.rest" pathsep=" --patch-module=" refid="src.module.dirset">
214             <regexpmapper from="^.*(/|\\)([^/\\]*)$" to="\2=${src.dir}\1\2/share/classes${path.separator}${build.gensrc}\1\2" />
215         </pathconvert>
216         <property name="xpatch.src.cmd" value="--patch-module=${xpatch.src.rest}"/>
217         <pathconvert pathsep="," property="gensrc.module.dirs">
218             <dirset dir="${build.gensrc}" includes="${module.names}"/>
219         </pathconvert>
220         <multirootfileset id="source.fileset" basedirs="${src.module.dirs},${gensrc.module.dirs}">
221             <include name="**/*.java"/>
222             <different targetdir="${build.prevsrc}" ignoreFileTimes="true"/>
223         </multirootfileset>
224         <pathconvert pathsep=" " property="source.files" refid="source.fileset"/>
225         <echo file="${build.dir}/sources.txt">${source.files}</echo>
226         <exec executable="${langtools.jdk.home}/bin/javac" failonerror="true">
227             <arg value="-d" />
228             <arg value="${build.modules}" />
229             <arg line="${javac.opts}" />
230             <arg line="${xpatch.src.cmd}" />
231             <arg line="--module-source-path ." />
232             <arg line="@${build.dir}/sources.txt" />
233         </exec>
234         <delete file="${build.dir}/sources.txt"/>
235         <delete>
236             <fileset dir="${build.modules}" includes="**/module-info.class"/>
237         </delete>
238         <!-- workaround for incremental compilation -->
239         <copy todir="${build.prevsrc}" >
240             <multirootfileset refid="source.fileset"/>
241         </copy>
242     </target>
243 
244     <target name="build-all-tools" depends="build-all-classes, -def-build-tool">
245         <build-tool name="javac"/>
246         <build-tool name="javadoc"/>
247         <build-tool name="javap"/>
248         <build-tool name="jdeps"/>
249         <build-tool name="jshell"/>
250     </target>
251 
252     <target name="jtreg" depends="build-all-tools,-def-jtreg">
253         <jtreg-tool name="all" tests="${jtreg.tests}"/>
254     </target>
255 
256     <!--
257     **** IDE support
258     -->
259 
260     <target name="idea" depends="-check-langtools.jdk.home">
261         <mkdir dir=".idea"/>
262         <copy todir=".idea" >
263             <fileset dir="${make.idea.dir}/template">
264                <exclude name="**/src/**"/>
265                <exclude name="**/utils/**"/>
266             </fileset>
267         </copy>
268         <condition property="idea.jtreg.home" value="${jtreg.home}" else = "[jtreg.home]">
269             <isset property="jtreg.home"/>
270         </condition>
271         <condition property="idea.target.jdk" value="${langtools.jdk.home}" else = "$JDKPath$">
272             <isset property="langtools.jdk.home"/>
273         </condition>
274         <replace file=".idea/ant.xml" token="@IDEA_TARGET_JDK@" value="${idea.target.jdk}"/>
275         <replace dir=".idea/runConfigurations" token="@IDEA_TARGET_JDK@" value="${idea.target.jdk}"/>
276         <replace dir=".idea/runConfigurations" token="@XPATCH@" value="${xpatch.cmd}"/>
277         <replace file=".idea/misc.xml" token="@IDEA_JTREG_HOME@" value="${idea.jtreg.home}"/>
278         <replace file=".idea/misc.xml" token="@IDEA_TARGET_JDK@" value="${idea.target.jdk}"/>
279         <replace file=".idea/misc.xml" token="@XPATCH@" value="${xpatch.cmd}"/>
280         <mkdir dir=".idea/classes"/>
281         <javac source="${javac.build.source}"
282                target="${javac.build.target}"
283                srcdir="${make.idea.dir}/template/src"
284                destdir=".idea/classes"/>
285     </target>
286 
287     <!--
288         **** Utility definitions
289     -->
290 
291     <target name="-def-pparse">
292         <copy todir="${build.tools}/propertiesparser" >
293             <fileset dir="${make.tools.dir}/propertiesparser" includes="**/resources/**"/>
294         </copy>
295         <javac source="${javac.build.source}"
296                target="${javac.build.target}"
297                srcdir="${make.tools.dir}"
298                includes="propertiesparser/* anttasks/PropertiesParser* anttasks/PathFileSet*"
299                destdir="${build.tools}"
300                classpath="${ant.core.lib}"
301                bootclasspath="${langtools.jdk.home}/jre/lib/rt.jar"
302                includeantruntime="false">
303             <compilerarg line="${javac.build.opts} -XDstringConcat=inline"/>
304         </javac>
305         <taskdef name="pparse"
306                  classname="anttasks.PropertiesParserTask"
307                  classpath="${build.tools}"/>
308     </target>
309 
310      <target name="-def-pcompile">
311         <javac
312                source="${javac.build.source}"
313                target="${javac.build.target}"
314                srcdir="${make.tools.dir}"
315                includes="compileproperties/* anttasks/CompileProperties* anttasks/PathFileSet*"
316                destdir="${build.dir}/toolclasses/"
317                classpath="${ant.core.lib}"
318                includeantruntime="false">
319             <compilerarg line="${javac.build.opts} -XDstringConcat=inline"/>
320         </javac>
321         <taskdef name="pcompile"
322                  classname="anttasks.CompilePropertiesTask"
323                  classpath="${build.tools}"/>
324     </target>
325 
326     <target name="-def-build-tool">
327         <macrodef name="build-tool">
328             <attribute name="name"/>
329             <attribute name="compilation.kind" default=""/>
330             <attribute name="bin.dir" default="${build.bin}"/>
331             <attribute name="java" default="${launcher.java}"/>
332             <attribute name="main.class" default="${tool.@{name}.main.class}"/>
333             <attribute name="xpatch" default="${xpatch.cmd}"/>
334             <sequential>
335                 <mkdir dir="@{bin.dir}"/>
336                 <copy file="${make.dir}/launcher.sh-template" tofile="@{bin.dir}/@{name}">
337                     <filterset begintoken="#" endtoken="#">
338                         <filter token="PROGRAM" value="@{main.class}"/>
339                         <filter token="TARGET_JAVA" value="@{java}"/>
340                         <filter token="PS" value="${path.separator}"/>
341                         <filter token="XPATCH" value="${xpatch.cmd}"/>
342                     </filterset>
343                 </copy>
344                 <chmod file="@{bin.dir}/@{name}" perm="ugo+rx"/>
345             </sequential>
346         </macrodef>
347     </target>
348 
349     <target name="-def-jtreg" unless="jtreg.defined" depends="-check-jtreg.home,-check-langtools.jdk.home">
350         <taskdef name="jtreg" classname="com.sun.javatest.regtest.Main$$Ant">
351             <classpath>
352                 <pathelement location="${jtreg.home}/lib/jtreg.jar"/>
353                 <pathelement location="${jtreg.home}/lib/javatest.jar"/>
354             </classpath>
355         </taskdef>
356         <macrodef name="jtreg-tool">
357             <attribute name="name"/>
358             <attribute name="tests"/>
359             <attribute name="jdk" default="${langtools.jdk.home}"/>
360             <attribute name="agentvm" default="true"/>
361             <attribute name="verbose" default="${default.jtreg.verbose}"/>
362             <attribute name="options" default="${other.jtreg.options}"/>
363             <attribute name="ignore" default="-keywords:!ignore -exclude:${test.dir}/ProblemList.txt"/>
364             <attribute name="jpda.jvmargs" default=""/>
365             <attribute name="extra.jvmargs" default=""/>
366             <attribute name="build.modules" default="${build.modules}"/>
367             <sequential>
368                 <property name="coverage.options" value=""/>              <!-- default -->
369                 <property name="coverage.classpath" value=""/>            <!-- default -->
370                 <property name="default.jtreg.verbose" value="summary"/>  <!-- default -->
371                 <property name="other.jtreg.options" value=""/>           <!-- default -->
372                 <property name="jtreg.classfiles.to.modules" value="@{agentvm}"/>
373                 <jtreg
374                     dir="${test.dir}"
375                     workDir="${build.jtreg}/@{name}/work"
376                     reportDir="${build.jtreg}/@{name}/report"
377                     jdk="@{jdk}"
378                     agentvm="@{agentvm}" verbose="@{verbose}"
379                     failonerror="false" resultproperty="jtreg.@{name}.result"
380                     vmoptions="${coverage.options} @{extra.jvmargs} ${xpatch.noquotes.cmd}">
381                     <arg value="-debug:@{jpda.jvmargs}"/>
382                     <arg line="@{ignore}"/>
383                     <arg line="@{options}"/>
384                     <arg line="@{tests}"/>
385                 </jtreg>
386                 <!-- the next two properties are for convenience, when only
387                      a single instance of jtreg will be invoked. -->
388                 <condition property="jtreg.passed">
389                     <equals arg1="${jtreg.@{name}.result}" arg2="0"/>
390                 </condition>
391                 <property name="jtreg.report" value="${build.jtreg}/@{name}/report"/>
392             </sequential>
393         </macrodef>
394         <property name="jtreg.defined" value="true"/>
395     </target>
396 </project>