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