1 <?xml version="1.0" encoding="UTF-8"?>
   2 <!--
   3   ~ Copyright (c) 2007, 2018, 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    |-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="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 Solaris/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 overriden 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="generate-sources"  depends="-prepare-build,-def-pparse,-def-pcompile">
 199         <subant inheritall="true" target="generate-sources-internal" genericantfile="${make.dir}/build.xml">
 200               <dirset refid="src.module.dirset"/>
 201         </subant>
 202     </target>
 203 
 204     <target name="build-all-classes" depends="generate-sources">
 205         <pathconvert property="xpatch.src.rest" pathsep=" --patch-module=" refid="src.module.dirset">
 206             <regexpmapper from="^.*(/|\\)([^/\\]*)$" to="\2=${src.dir}\1\2/share/classes${path.separator}${build.gensrc}\1\2" />
 207         </pathconvert>
 208         <property name="xpatch.src.cmd" value="--patch-module=${xpatch.src.rest}"/>
 209         <pathconvert pathsep="," property="gensrc.module.dirs">
 210             <dirset dir="${build.gensrc}" includes="${module.names}"/>
 211         </pathconvert>
 212         <multirootfileset id="source.fileset" basedirs="${src.module.dirs},${gensrc.module.dirs}">
 213             <include name="**/*.java"/>
 214             <different targetdir="${build.prevsrc}" ignoreFileTimes="true"/>
 215         </multirootfileset>
 216         <pathconvert pathsep=" " property="source.files" refid="source.fileset"/>
 217         <echo file="${build.dir}/sources.txt">${source.files}</echo>
 218         <exec executable="${langtools.jdk.home}/bin/javac" failonerror="true">
 219             <arg value="-d" />
 220             <arg value="${build.modules}" />
 221             <arg line="${javac.opts}" />
 222             <arg line="${xpatch.src.cmd}" />
 223             <arg line="--module-source-path ." />
 224             <arg line="@${build.dir}/sources.txt" />
 225         </exec>
 226         <delete file="${build.dir}/sources.txt"/>
 227         <delete>
 228             <fileset dir="${build.modules}" includes="**/module-info.class"/>
 229         </delete>
 230         <!-- workaround for incremental compilation -->
 231         <copy todir="${build.prevsrc}" >
 232             <multirootfileset refid="source.fileset"/>
 233         </copy>
 234     </target>
 235 
 236     <target name="build-all-tools" depends="build-all-classes, -def-build-tool">
 237         <build-tool name="javac"/>
 238         <build-tool name="javadoc"/>
 239         <build-tool name="javap"/>
 240         <build-tool name="jdeps"/>
 241         <build-tool name="sjavac"/>
 242         <build-tool name="jshell"/>
 243     </target>
 244 
 245     <target name="jtreg" depends="build-all-tools,-def-jtreg">
 246         <jtreg-tool name="all" tests="${jtreg.tests}"/>
 247     </target>
 248 
 249     <!--
 250     **** IDE support
 251     -->
 252 
 253     <target name="idea" depends="-check-langtools.jdk.home">
 254         <mkdir dir=".idea"/>
 255         <copy todir=".idea" >
 256             <fileset dir="${make.idea.dir}/template">
 257                <exclude name="**/src/**"/>
 258                <exclude name="**/utils/**"/>
 259             </fileset>
 260         </copy>
 261         <condition property="idea.jtreg.home" value="${jtreg.home}" else = "[jtreg.home]">
 262             <isset property="jtreg.home"/>
 263         </condition>
 264         <condition property="idea.target.jdk" value="${langtools.jdk.home}" else = "$JDKPath$">
 265             <isset property="langtools.jdk.home"/>
 266         </condition>
 267         <replace file=".idea/ant.xml" token="@IDEA_TARGET_JDK@" value="${idea.target.jdk}"/>
 268         <replace dir=".idea/runConfigurations" token="@IDEA_TARGET_JDK@" value="${idea.target.jdk}"/>
 269         <replace dir=".idea/runConfigurations" token="@XPATCH@" value="${xpatch.cmd}"/>
 270         <replace file=".idea/misc.xml" token="@IDEA_JTREG_HOME@" value="${idea.jtreg.home}"/>
 271         <replace file=".idea/misc.xml" token="@IDEA_TARGET_JDK@" value="${idea.target.jdk}"/>
 272         <replace file=".idea/misc.xml" token="@XPATCH@" value="${xpatch.cmd}"/>
 273         <mkdir dir=".idea/classes"/>
 274         <javac source="${javac.build.source}"
 275                target="${javac.build.target}"
 276                srcdir="${make.idea.dir}/template/src"
 277                destdir=".idea/classes"/>
 278     </target>
 279 
 280     <!--
 281         **** Utility definitions
 282     -->
 283 
 284     <target name="-def-pparse">
 285         <copy todir="${build.tools}/propertiesparser" >
 286             <fileset dir="${make.tools.dir}/propertiesparser" includes="**/resources/**"/>
 287         </copy>
 288         <javac source="${javac.build.source}"
 289                target="${javac.build.target}"
 290                srcdir="${make.tools.dir}"
 291                includes="propertiesparser/* anttasks/PropertiesParser* anttasks/PathFileSet*"
 292                destdir="${build.tools}"
 293                classpath="${ant.core.lib}"
 294                bootclasspath="${langtools.jdk.home}/jre/lib/rt.jar"
 295                includeantruntime="false">
 296             <compilerarg line="${javac.build.opts} -XDstringConcat=inline"/>
 297         </javac>
 298         <taskdef name="pparse"
 299                  classname="anttasks.PropertiesParserTask"
 300                  classpath="${build.tools}"/>
 301     </target>
 302 
 303      <target name="-def-pcompile">
 304         <javac
 305                source="${javac.build.source}"
 306                target="${javac.build.target}"
 307                srcdir="${make.tools.dir}"
 308                includes="compileproperties/* anttasks/CompileProperties* anttasks/PathFileSet*"
 309                destdir="${build.dir}/toolclasses/"
 310                classpath="${ant.core.lib}"
 311                includeantruntime="false">
 312             <compilerarg line="${javac.build.opts} -XDstringConcat=inline"/>
 313         </javac>
 314         <taskdef name="pcompile"
 315                  classname="anttasks.CompilePropertiesTask"
 316                  classpath="${build.tools}"/>
 317     </target>
 318 
 319     <target name="-def-build-tool">
 320         <macrodef name="build-tool">
 321             <attribute name="name"/>
 322             <attribute name="compilation.kind" default=""/>
 323             <attribute name="bin.dir" default="${build.bin}"/>
 324             <attribute name="java" default="${launcher.java}"/>
 325             <attribute name="main.class" default="${tool.@{name}.main.class}"/>
 326             <attribute name="xpatch" default="${xpatch.cmd}"/>
 327             <sequential>
 328                 <mkdir dir="@{bin.dir}"/>
 329                 <copy file="${make.dir}/launcher.sh-template" tofile="@{bin.dir}/@{name}">
 330                     <filterset begintoken="#" endtoken="#">
 331                         <filter token="PROGRAM" value="@{main.class}"/>
 332                         <filter token="TARGET_JAVA" value="@{java}"/>
 333                         <filter token="PS" value="${path.separator}"/>
 334                         <filter token="XPATCH" value="${xpatch.cmd}"/>
 335                     </filterset>
 336                 </copy>
 337                 <chmod file="@{bin.dir}/@{name}" perm="ugo+rx"/>
 338             </sequential>
 339         </macrodef>
 340     </target>
 341 
 342     <target name="-def-jtreg" unless="jtreg.defined" depends="-check-jtreg.home,-check-langtools.jdk.home">
 343         <taskdef name="jtreg" classname="com.sun.javatest.regtest.Main$$Ant">
 344             <classpath>
 345                 <pathelement location="${jtreg.home}/lib/jtreg.jar"/>
 346                 <pathelement location="${jtreg.home}/lib/javatest.jar"/>
 347             </classpath>
 348         </taskdef>
 349         <macrodef name="jtreg-tool">
 350             <attribute name="name"/>
 351             <attribute name="tests"/>
 352             <attribute name="jdk" default="${langtools.jdk.home}"/>
 353             <attribute name="agentvm" default="true"/>
 354             <attribute name="verbose" default="${default.jtreg.verbose}"/>
 355             <attribute name="options" default="${other.jtreg.options}"/>
 356             <attribute name="ignore" default="-keywords:!ignore -exclude:${test.dir}/ProblemList.txt"/>
 357             <attribute name="jpda.jvmargs" default=""/>
 358             <attribute name="extra.jvmargs" default=""/>
 359             <attribute name="build.modules" default="${build.modules}"/>
 360             <sequential>
 361                 <property name="coverage.options" value=""/>              <!-- default -->
 362                 <property name="coverage.classpath" value=""/>            <!-- default -->
 363                 <property name="default.jtreg.verbose" value="summary"/>  <!-- default -->
 364                 <property name="other.jtreg.options" value=""/>           <!-- default -->
 365                 <property name="jtreg.classfiles.to.modules" value="@{agentvm}"/>
 366                 <jtreg
 367                     dir="${test.dir}"
 368                     workDir="${build.jtreg}/@{name}/work"
 369                     reportDir="${build.jtreg}/@{name}/report"
 370                     jdk="@{jdk}"
 371                     agentvm="@{agentvm}" verbose="@{verbose}"
 372                     failonerror="false" resultproperty="jtreg.@{name}.result"
 373                     vmoptions="${coverage.options} @{extra.jvmargs} ${xpatch.noquotes.cmd}">
 374                     <arg value="-debug:@{jpda.jvmargs}"/>
 375                     <arg line="@{ignore}"/>
 376                     <arg line="@{options}"/>
 377                     <arg line="@{tests}"/>
 378                 </jtreg>
 379                 <!-- the next two properties are for convenience, when only
 380                      a single instance of jtreg will be invoked. -->
 381                 <condition property="jtreg.passed">
 382                     <equals arg1="${jtreg.@{name}.result}" arg2="0"/>
 383                 </condition>
 384                 <property name="jtreg.report" value="${build.jtreg}/@{name}/report"/>
 385             </sequential>
 386         </macrodef>
 387         <property name="jtreg.defined" value="true"/>
 388     </target>
 389 </project>