build.xml 26.4 KB
Newer Older
1
<project name="disl" default="build" basedir=".">
2

3
	<property name="build.sysclasspath" value="ignore" />
4

5
	<property file="disl.version" />
6
	<property file="build.local.properties" />
7
	<property file="build.properties" />
8

9

10 11 12 13 14 15 16 17 18 19 20 21 22
	<!--
		Define additional tasks from ant-contrib.
	-->
	<taskdef resource="${ant-contrib.resource}">
		<classpath>
			<pathelement location="${ant-contrib.path}" />
		</classpath>
	</taskdef>


	<!--
		Define various class path elements.
	-->
23
	<path id="asm.classpath">
24
		<pathelement location="${asm.path}" />
25 26
	</path>

27 28 29 30
	<path id="log4j.classpath">
		<pathelement location="${log4j.path}" />
	</path>

31
	<path id="junit.classpath">
František Haas's avatar
František Haas committed
32 33 34 35
		<pathelement location="${junit.core.path}" />
		<pathelement location="${junit.hamcrest.path}" />
	</path>

36 37 38 39 40 41 42 43 44
	<path id="util.classpath">
		<pathelement location="${build.util}" />
	</path>

	<path id="disl.classpath">
		<pathelement location="${build.disl}" />
	</path>

	<path id="disl.bypass.classpath">
45
		<pathelement location="${build.disl.bypass}/dynamic" />
46 47 48 49 50 51 52 53 54 55
	</path>

	<path id="shvm.classpath">
		<pathelement location="${build.shvm}" />
		<pathelement location="${build.shvm.dispatch}" />
	</path>


	<!-- Initialization -->

56
	<target name="determine-lib-names">
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
		<!--
			Determine the names of native agent libraries.
			Mac OS X (Darwin) is considered a Unix family.
		-->
		<if>
			<os family="windows" />
			<then>
				<property name="dl.prefix" value="" />
				<property name="dl.suffix" value=".dll" />
			</then>
			<else><if>
				<os family="unix" />
				<then>
					<property name="dl.prefix" value="lib" />
					<if>
						<os family="mac" />
						<then>
							<property name="dl.suffix" value=".jnilib" />
						</then>
						<else>
							<property name="dl.suffix" value=".so" />
						</else>
					</if>
				</then>
				<else>
					<fail message="Unsupported operating system: ${os.name}" />
				</else>
			</if></else>
		</if>

87 88
		<property name="disl.agent.lib" value="${dl.prefix}${disl.agent.lib.base}${dl.suffix}" />
		<property name="shvm.agent.lib" value="${dl.prefix}${shvm.agent.lib.base}${dl.suffix}" />
89 90 91
	</target>


92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
	<!--
		Looks for a class file or a source file with a given name, and
		sets the value of a given property to the fully qualified
		class name when a matching class (or source) file is found.
	-->
	<macrodef name="find-class">
		<attribute name="dir" />
		<attribute name="name" />
		<attribute name="property" />
		<attribute name="suffix" default=".class" />
		<attribute name="setonempty" default="true" />
		<sequential>
			<pathconvert property="@{property}" setonempty="@{setonempty}">
				<fileset dir="@{dir}" includes="**/@{name}@{suffix}" />
				<mapper type="package" from="${basedir}/@{dir}/*@{suffix}" to="*" />
			</pathconvert>
		</sequential>
	</macrodef>


112 113 114 115 116 117 118 119 120 121 122 123 124
	<!-- Build tools -->

	<target name="compile-tools">
		<mkdir dir="${build.tools}" />
		<javac destdir="${build.tools}" srcdir="${src.tools}">
			<classpath>
				<path refid="asm.classpath" />
				<path location="${ant.core.lib}" />
			</classpath>
		</javac>
	</target>


125 126
	<!-- DiSL bypass -->

127 128 129 130 131 132 133 134
	<!--
		To compile DiSL bypass code, we need an extended Thread class
		containing a public "bypass" field used by the dynamic bypass
		code. When running an application with DiSL instrumentation,
		the Thread class will be extended at load time, but we need
		one also for compilation.

		Here we first check if the extended Thread class exists, and
135 136
		if not, we use a thread extended from build tools to generate
		the extended Thread class.
137
	-->
138
	<pathconvert property="build.disl.thread.available" setonempty="false">
139 140
		<fileset dir="." includes="${build.disl.thread}/**/Thread.class" />
	</pathconvert>
141

142
	<target name="prepare-disl-thread" unless="build.disl.thread.available">
143 144
		<antcall target="create-disl-thread" />
	</target>
145

146
	<target name="create-disl-thread" depends="compile-tools">
147
		<local name="extender.class" />
148
		<find-class property="extender.class" dir="${build.tools}" name="ExtendThread" />
149 150

		<mkdir dir="${build.disl.thread}" />
151
		<java classname="${extender.class}" fork="true">
152
			<classpath>
153
				<path location="${build.tools}" />
154 155 156
				<path refid="asm.classpath" />
			</classpath>
			<arg value="${basedir}/${build.disl.thread}" />
157
		</java>
Lukáš Marek's avatar
Lukáš Marek committed
158 159 160
	</target>


161 162 163 164 165 166
	<!--
		Compile multiple versions of the bypass code: one which always
		bypasses the instrumentation, one which never bypasses the
		instrumentation, and one that checks the "bypass" field in
		the extended Thread class to determine whether to bypass the
		instrumentation or not.
Lukáš Marek's avatar
Lukáš Marek committed
167

168 169 170 171 172 173 174
		After compiling, create a file set of default bypass classes.
		The DiSL agent requires those so that instrumented application
		can find the BypassCheck class, and after switch to dynamic
		bypass performed by the agent, also the DynamicBypass class.
		The DiSL server requires both classes to create class literals
		in the weaver code.
	-->
175
	<target name="compile-disl-bypass" depends="prepare-disl-thread">
176 177 178
		<for list="always,never,dynamic" param="variant">
			<sequential>
				<mkdir dir="${build.disl.bypass}/@{variant}" />
179
				<javac destdir="${build.disl.bypass}/@{variant}" srcdir="${src.disl.bypass}/@{variant}" debug="true" source="${target.disl.bypass}" target="${target.disl.bypass}">
180 181 182 183
					<compilerarg value="-Xbootclasspath/p:${basedir}/${build.disl.thread}" />
				</javac>
			</sequential>
		</for>
184

185 186 187 188
		<union id="disl.bypass.files">
			<fileset dir="${build.disl.bypass}/always" includes="**/BypassCheck.class" />
			<fileset dir="${build.disl.bypass}/dynamic" includes="**/DynamicBypass.class" />
		</union>
189 190
	</target>

191

192 193 194 195 196 197 198 199
	<!--
		Package the default variant of the bypass code which will
		be included in the boot classpath. By default, we include
		a BypassCheck variant that always bypasses instrumentation.
		We also include DynamicBypass class that is needed by the
		dynamic variant of the BypassCheck class, which will be
		substituted by the DiSL agent in place of the default on.
	-->
200
	<target name="build-disl-bypass" depends="compile-disl-bypass">
201 202
		<jar destfile="${out.lib}/${disl.bypass.lib}">
			<resources refid="disl.bypass.files" />
203
		</jar>
204 205
	</target>

206 207 208

	<!-- Shared utility code -->

209
	<target name="compile-util">
210
		<mkdir dir="${build.util}" />
211 212 213
		<javac destdir="${build.util}" srcdir="${src.util}" debug="true">
			<classpath refid="log4j.classpath" />
		</javac>
214 215
	</target>

216 217 218

	<!-- DiSL -->

219 220 221
	<target name="compile-disl" depends="compile-util,compile-disl-bypass">
		<mkdir dir="${build.disl}" />
		<javac destdir="${build.disl}" srcdir="${src.disl}" debug="true">
222 223
			<classpath>
				<path refid="disl.bypass.classpath" />
224
				<path refid="util.classpath" />
225 226
				<path refid="asm.classpath" />
			</classpath>
227 228 229
		</javac>
	</target>

Lukáš Marek's avatar
Lukáš Marek committed
230

231
	<target name="build-disl" depends="compile-disl,build-disl-bypass">
232 233 234 235 236
		<local name="server.class" />
		<find-class property="server.class" dir="${build.disl}" name="DiSLServer" />
		
		<local name="classfinder.class" />
		<find-class property="classfinder.class" dir="${build.disl}" name="DislClassFinder" />
237 238

		<jar destfile="${out.lib}/${disl.lib}">
239
			<manifest>
240
				<attribute name="Class-Path" value="${asm.lib}" />
241
				<attribute name="Main-Class" value="${server.class}" />
242
				<attribute name="DiSL-Version" value="${disl.version}" />
243
			</manifest>
244

245
			<service type="javax.annotation.processing.Processor" provider="${classfinder.class}" />
246

247
			<fileset dir="${build.util}" />
248
			<fileset dir="${build.disl}" />
249
			<resources refid="disl.bypass.files" />
250 251 252
		</jar>
	</target>

253 254 255

	<!-- DiSL agent -->

256 257 258 259 260
	<!--
		The DiSL agent requires a header file containing flags for
		various code generation options. This target generates the
		header using "javah" after compiling DiSL.
	-->
261 262
	<property name="build.disl.agent.codeflags.path" value="${src.disl.agent}/codeflags.h" />
	<uptodate property="disl.agent.codeflags.uptodate" targetfile="${build.disl.agent.codeflags.path}">
263 264 265
		<srcfiles dir="${src.disl}" includes="**/DiSL.java" />
	</uptodate>

266 267 268 269 270 271
	<target name="prepare-disl-agent-codeflags" unless="disl.agent.codeflags.uptodate">
		<antcall target="generate-disl-agent-codeflags" />
	</target>


	<target name="generate-disl-agent-codeflags" depends="compile-disl">
272 273 274
		<local name="flags.class" />
		<find-class property="flags.class" dir="${build.disl}" name="*CodeOption$Flag" />

275
		<javah outputFile="${build.disl.agent.codeflags.path}">
276 277 278 279 280 281 282 283
			<class name="${flags.class}" />
			<classpath refid="disl.classpath" />
		</javah>
	</target>


	<!--
		The DiSL agent requires the bytecode of several bypass
284 285
		classes. This target generates the "bytecode.c" containing
		the necessary bytecode.
286
	-->
287 288
	<property name="build.disl.agent.bytecode.path" value="${src.disl.agent}/bytecode.c" />
	<uptodate property="build.disl.agent.bytecode.uptodate" targetfile="${build.disl.agent.bytecode.path}">
289 290
		<srcfiles dir="${src.disl.bypass}" />
	</uptodate>
291

292
	<target name="prepare-disl-agent-bytecode" unless="build.disl.agent.bytecode.uptodate">
293
		<antcall target="generate-disl-agent-bytecode" />
294 295 296
	</target>


297
	<target name="generate-disl-agent-bytecode" depends="compile-tools,compile-disl">
298 299 300
		<local name="output.file" />
		<property name="output.file" value="${build.disl.agent.bytecode.path}" />

301 302 303 304 305 306
		<taskdef name="bytedump" classname="ch.usi.dag.disl.tools.ByteDumpTask">
			<classpath>
				<pathelement location="${build.tools}" />
			</classpath>
		</taskdef>

307 308 309 310 311 312
		<echo file="${output.file}">/**${line.separator}</echo>
		<echo file="${output.file}" append="true"> * DO NOT EDIT!${line.separator}</echo>
		<echo file="${output.file}" append="true"> *${line.separator}</echo>
		<echo file="${output.file}" append="true"> * This file was generated using the 'generate-disl-agent-bytecode' target.${line.separator}</echo>
		<echo file="${output.file}" append="true"> */${line.separator}</echo>
		<echo file="${output.file}" append="true">#include &lt;jvmti.h&gt;${line.separator}</echo>
313

314
		<for param="file.path">
315 316 317 318 319
			<path>
				<fileset dir="${build.disl.bypass}" includes="**/BypassCheck.class" />
				<!-- fileset dir="${build.disl.bypass}" includes="**/DynamicBypass.class" /-->
			</path>
			<sequential>
320 321 322 323 324
				<!-- Variant of the class, i.e., the top-level directory name. -->
				<local name="file.variant" />
				<pathconvert property="file.variant">
					<path path="@{file.path}" />
					<mapper type="regexp" from="${basedir}/${build.disl.bypass}/([^/]+)/.*" to="\1" />
325
				</pathconvert>
326 327 328 329 330 331 332 333 334 335 336 337

				<!-- Name of the class. -->
				<local name="file.class" />
				<pathconvert property="file.class">
					<path path="@{file.path}" />
					<mapper type="regexp" from=".*/([^/]+).class" to="\1" />
				</pathconvert>

				<local name="file.length" />
				<length property="file.length" file="@{file.path}" />

				<!-- Define a structure for each class file. -->
338 339 340
				<echo file="${output.file}" append="true">${line.separator}jvmtiClassDefinition ${file.variant}_${file.class}_classdef = {${line.separator}</echo>
				<echo file="${output.file}" append="true">&#9;.class_byte_count = ${file.length},${line.separator}</echo>
				<echo file="${output.file}" append="true">&#9;.class_bytes = (unsigned char *)${line.separator}</echo>
341
				<bytedump
342
					srcFile="@{file.path}" destFile="${output.file}" append="true"
343 344 345
					blockLength="16"  byteFormat="\x%02x"
					blockPrefix="&#9;&#9;&quot;" blockSuffix="&quot;${line.separator}" lastSuffix="&quot;,${line.separator}"
				/>
346
				<echo file="${output.file}" append="true">};${line.separator}</echo>
347 348 349 350
			</sequential>
		</for>
	</target>

351

352
	<target name="prepare-disl-agent" depends="prepare-disl-agent-codeflags,prepare-disl-agent-bytecode" />
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368


	<target name="compile-disl-agent" depends="prepare-disl-agent,determine-lib-names">
		<exec executable="make" dir="${src.disl.agent}">
			<arg value="WHOLE=1" />
		</exec>
	</target>


	<!--
		This target cross-compiles the DiSL agent library for
		Windows using MinGW. It is currently not used in the
		default build, but should be used for binary releases.
	-->
	<target name="compile-disl-agent-mingw" depends="prepare-disl-agent,determine-lib-names">
		<exec executable="make" dir="${src.disl.agent}">
369
			<arg value="WHOLE=1" />
370 371
			<arg value="TARGET_ENV=MinGW" />
		</exec>
372 373 374
	</target>


375
	<target name="build-disl-agent" depends="compile-disl-agent">
376
		<copy file="${src.disl.agent}/${disl.agent.lib}" todir="${out.lib}" />
377
	</target>
378 379


380
	<!-- Shadow VM -->
381

382 383
	<target name="compile-shvm-dispatch">
		<mkdir dir="${build.shvm.dispatch}" />
384
		<javac destdir="${build.shvm.dispatch}" srcdir="${src.shvm.dispatch}" debug="true" source="${target.shvm.dispatch}" target="${target.shvm.dispatch}" />
385 386 387
	</target>


388
	<target name="build-shvm-dispatch" depends="compile-shvm-dispatch">
389 390 391 392
		<jar destfile="${out.lib}/${shvm.dispatch.lib}" basedir="${build.shvm.dispatch}" />
	</target>


393
	<target name="compile-shvm" depends="compile-util,compile-shvm-dispatch">
394
		<mkdir dir="${build.shvm}" />
395
		<javac destdir="${build.shvm}" srcdir="${src.shvm}" debug="true">
396
			<classpath refid="util.classpath" />
397
			<classpath refid="asm.classpath" />
398
		</javac>
399 400
	</target>

401

402
	<target name="build-shvm" depends="compile-shvm,build-shvm-dispatch">
403 404 405
		<local name="shvm.server.class" />
		<find-class property="shvm.server.class" dir="${build.shvm}" name="DiSLREServer" />

406
		<jar destfile="${out.lib}/${shvm.lib}">
407
			<manifest>
408
				<attribute name="Class-Path" value="${asm.lib}" />
409
				<attribute name="Main-Class" value="${shvm.server.class}" />
410
				<attribute name="DiSL-Version" value="${disl.version}" />
411
			</manifest>
412 413 414

			<fileset dir="${build.util}" />
			<fileset dir="${build.shvm}" />
415 416 417
		</jar>
	</target>

418
	<!-- Shadow VM agent -->
Lukáš Marek's avatar
Lukáš Marek committed
419

420
	<target name="compile-shvm-agent" depends="determine-lib-names">
421 422 423
		<exec executable="make" dir="${src.shvm.agent}">
			<arg value="WHOLE=1" />
		</exec>
424 425 426
	</target>


427
	<target name="build-shvm-agent" depends="compile-shvm-agent">
428
		<copy file="${src.shvm.agent}/${shvm.agent.lib}" todir="${out.lib}" />
429
	</target>
František Haas's avatar
František Haas committed
430

431

432
	<!-- JUnit tests and DiSL/Shadow VM test suites -->
433

434 435 436 437 438 439 440 441
	<path id="test.classpath">
		<path refid="util.classpath" />
		<path refid="disl.classpath" />
		<path refid="shvm.classpath" />
		<path refid="junit.classpath" />
		<path refid="asm.classpath" />
	</path>

442
	<target name="compile-test" depends="compile-util,compile-disl,compile-shvm">
443
		<mkdir dir="${build.test}" />
444
		<javac destdir="${build.test}" srcdir="${src.test}" debug="true">
445
			<classpath refid="test.classpath" />
446
		</javac>
František Haas's avatar
František Haas committed
447

448 449 450 451 452 453
		<!-- Copy test resource files from source to class output directory. -->
		<copy todir="${build.test}">
			<fileset dir="${src.test}">
				<include name="**/*.resource" />
			</fileset>
		</copy>
František Haas's avatar
František Haas committed
454 455 456
	</target>


457 458 459 460 461 462 463 464 465 466
	<macrodef name="package2path">
		<attribute name="package" />
		<attribute name="property" />
		<sequential>
			<pathconvert property="@{property}">
				<path path="@{package}" />
				<mapper type="unpackage" from="${basedir}/*" to="*" />
			</pathconvert>
		</sequential>
	</macrodef>
František Haas's avatar
František Haas committed
467

František Haas's avatar
František Haas committed
468

469
	<target name="build-test" depends="compile-test">
470 471 472 473 474 475
		<property name="suite.base.pkg" value="ch.usi.dag.disl.test.suite" />
		<package2path package="${suite.base.pkg}" property="suite.base.path" />

		<condition property="test.suites" value="${test.name}" else="*">
			<isset property="test.name" />
		</condition>
František Haas's avatar
František Haas committed
476

477
		<for param="suite.path">
František Haas's avatar
František Haas committed
478
			<path>
479 480
				<dirset dir="${src.test}/${suite.base.path}">
					<include name="${test.suites}" />
František Haas's avatar
František Haas committed
481 482 483
				</dirset>
			</path>
			<sequential>
484 485
				<local name="suite.name" />
				<basename file="@{suite.path}" property="suite.name" />
486
				<antcall target="build-test-suite">
487 488 489
					<param name="test.suite.name" value="${suite.name}" />
					<param name="test.suite.path" value="${suite.base.path}/${suite.name}" />
					<param name="test.suite.pkg" value="${suite.base.pkg}.${suite.name}" />
František Haas's avatar
František Haas committed
490 491 492 493 494
				</antcall>
			</sequential>
		</for>
	</target>

František Haas's avatar
František Haas committed
495

496
	<target name="build-test-suite">
497 498 499
		<!-- Package target application classes. -->
		<jar destfile="${out.test}/${test.suite.name}-app.jar">
			<fileset dir="${build.test}" includes="${test.suite.path}/app/**" />
500 501 502 503
			<manifest>
				<attribute name="Main-Class" value="${test.suite.pkg}.app.TargetClass" />
			</manifest>
		</jar>
František Haas's avatar
František Haas committed
504

505 506

		<!--
507 508 509 510 511 512 513
			Process annotations to find DiSL classes.

			Use an empty directory as destination for the classes to
			make the "javac" task actually execute "javac" with the
			source files. Using the normal build destination directory
			would result in "javac" task excluding all source files
			for which it could find up-to-date class files.
514
		-->
515 516 517 518 519
		<local name="classfinder.output" />
		<tempfile property="classfinder.output" destDir="${out.dir}" createFile="true" deleteOnExit="true" />

		<local name="classfinder.class" />
		<find-class property="classfinder.class" dir="${build.disl}" name="DislClassFinder" />
520 521 522 523 524 525

		<mkdir dir="${out.dir}/empty" />
		<javac srcdir="${src.test}" destDir="${out.dir}/empty">
			<classpath refid="test.classpath" />

			<compilerArg value="-proc:only" />
526 527
			<compilerArg line="-processor ${classfinder.class}" />
			<compilerArg value="-Adisl.classfinder.output=${classfinder.output}" />
528 529 530 531 532
			<compilerArg value="-Adisl.classfinder.separator=," />

			<include name="${test.suite.path}/**/*.java" />
		</javac>

533
		<loadfile property="disl.classes" srcFile="${classfinder.output}" />
534 535 536


		<!-- Package instrumentation classes. -->
537
		<jar destfile="${out.test}/${test.suite.name}-inst.jar">
538 539 540 541 542 543
			<manifest>
				<attribute name="DiSL-Classes" value="${disl.classes}" />
			</manifest>

			<fileset dir="${build.test}" includes="${test.suite.path}/instr/**" />
		</jar>
František Haas's avatar
František Haas committed
544
	</target>
František Haas's avatar
František Haas committed
545 546


547
	<target name="test" depends="build,build-test" description="Runs all tests or a selected (-Dtest.name=...) test suite.">
548 549 550 551 552
		<!--
			If test.name is set to a name of a test suite, only include the test suite
			in the batch of tests to be run, otherwise include all tests and suites.
		-->
		<if>
František Haas's avatar
František Haas committed
553
			<isset property="test.name" />
554 555 556
			<then>
				<echo>Running a single test suite: ${test.name}</echo>
				<fileset id="test.batch" dir="${src.test}">
557
					<include name="**/suite/${test.name}/junit/*Test.java" />
558 559 560 561
				</fileset>
			</then><else>
				<echo>Running all tests.</echo>
				<fileset id="test.batch" dir="${src.test}">
562
					<include name="**/junit/*Test.java" />
563 564 565
				</fileset>
			</else>
		</if>
František Haas's avatar
František Haas committed
566

567 568 569
		<!--
			Run the batch of junit tests and junit-wrapped test suites.
		-->
František Haas's avatar
František Haas committed
570
		<junit haltonfailure="no" haltonerror="no" failureproperty="junit.failure">
František Haas's avatar
František Haas committed
571
			<formatter type="brief" usefile="false" />
572 573 574 575 576 577 578 579 580 581

			<classpath>
				<path refid="asm.classpath" />
				<path refid="junit.classpath" />
				<pathelement location="${build.test}" />
				<pathelement location="${build.util}" />
				<pathelement location="${build.disl}" />
				<pathelement location="${build.shvm}" />
			</classpath>

582
			<!-- pass properties starting with "disl.", "dislserver.", and "dislreserver." to the tests -->
František Haas's avatar
František Haas committed
583
			<syspropertyset>
584 585 586
				<propertyref prefix="disl." />
				<propertyref prefix="dislserver." />
				<propertyref prefix="dislreserver." />
František Haas's avatar
František Haas committed
587
			</syspropertyset>
588

589 590 591 592 593
			<sysproperty key="runner.disl.lib.dir" value="${out.lib}" />
			<sysproperty key="runner.lib.dir" value="${out.test}" />
			<sysproperty key="runner.disl.agent.lib" value="${disl.agent.lib}" />
			<sysproperty key="runner.shvm.agent.lib" value="${shvm.agent.lib}" />
			<sysproperty key="runner.debug" value="${test.debug}" />
594
			<sysproperty key="test.verbose" value="${test.verbose}" />
595

František Haas's avatar
František Haas committed
596
			<batchtest fork="yes">
597
				<fileset refid="test.batch" />
František Haas's avatar
František Haas committed
598 599 600
			</batchtest>
		</junit>
	</target>
601 602 603 604


	<!-- Eclipse support -->

605
	<target name="build-eclipse-agent">
606 607 608 609
		<local name="agent.class" />
		<find-class property="agent.class" dir="${src.test}" name="Agent" suffix=".java" />

		<jar destfile="${out.lib}/${eclipse.agent.lib}">
610
			<manifest>
611
				<attribute name="Premain-Class" value="${agent.class}" />
612 613 614 615 616 617 618
			</manifest>
		</jar>
	</target>


	<!-- Documentation -->

619 620 621 622 623 624 625
	<macrodef name="pdflatex">
		<attribute name="dir" default="." />
		<element name="exec-elements" implicit="yes" />
		<sequential>
			<local name="pdflatex.output" />
			<local name="pdflatex.result" />

626
			<exec executable="pdflatex" dir="@{dir}" outputProperty="pdflatex.output" resultProperty="pdflatex.result">
627 628 629 630 631 632 633 634 635 636 637 638 639 640
				<exec-elements />
			</exec>
			<fail message="${pdflatex.output}">
				<condition><isfailure code="${pdflatex.result}" /></condition>
			</fail>
		</sequential>
	</macrodef>


	<target name="check-doc">
		<property name="doc.intro.tex" value="dislintro.tex" />
		<property name="doc.intro.pdf" value="${build.doc.intro}/dislintro.pdf" />
		<fileset id="doc.intro.files" dir="${src.doc.intro}" />

641
		<uptodate property="doc.intro.uptodate" targetFile="${doc.intro.pdf}">
642 643 644 645 646 647
			<srcfiles refid="doc.intro.files" />
		</uptodate>
	</target>


	<target name="build-doc" depends="check-doc" unless="doc.intro.uptodate">
648 649
		<delete dir="${build.doc.intro}" />
		<copy todir="${build.doc.intro}">
650
			<fileset refid="doc.intro.files" />
651
		</copy>
652 653 654 655 656 657 658 659 660 661

		<echo>Compiling Introduction to Instrumentation with DiSL</echo>
		<pdflatex dir="${build.doc.intro}">
			<arg value="-draftmode" />
			<arg value="${doc.intro.tex}" />
		</pdflatex>

		<pdflatex dir="${build.doc.intro}">
			<arg value="${doc.intro.tex}" />
		</pdflatex>
662 663 664 665
	</target>


	<target name="build-jdoc" depends="compile">
666 667 668
		<mkdir dir="${out.doc.jdoc}" />
		<javadoc destdir="${out.doc.jdoc}"
			access="public" author="true" version="true" use="true"
669 670
			noDeprecated="false" nodeprecatedlist="false"
			noIndex="false" splitIndex="true" noNavbar="false" noTree="false"
671
			overview="${src.doc.jdoc}/overview.html"
672
			source="1.8"
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687
		>
			<sourcepath>
				<pathelement path="${src.disl}" />
			</sourcepath>

			<sourcefiles>
				<fileset dir="${src.disl}">
					<include name="**/DiSL.java" />
					<include name="**/Scope.java" />
					<include name="**/ScopeImpl.java" />
					<include name="**/Shadow.java" />
				</fileset>
				<fileset dir="${src.disl.bypass}">
					<include name="**/DynamicBypass.java" />
				</fileset>
688 689 690 691 692 693 694 695 696 697 698

				<fileset dir="${src.shvm}">
					<include name="**/RemoteAnalysis.java" />
					<include name="**/ShadowObject.java" />
					<include name="**/ShadowString.java" />
					<include name="**/ShadowThread.java" />
					<include name="**/ShadowClass.java" />
				</fileset>
				<fileset dir="${src.shvm.dispatch}">
					<include name="**/REDispatch.java" />
				</fileset>
699 700 701 702
			</sourcefiles>

			<classpath>
				<path refid="disl.bypass.classpath" />
703 704
				<path refid="shvm.classpath" />
				<path refid="util.classpath" />
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722
				<path refid="asm.classpath" />
			</classpath>

			<package name="ch.usi.dag.disl.annotation" />
			<package name="ch.usi.dag.disl.marker" />
			<package name="ch.usi.dag.disl.guardcontext" />
			<package name="ch.usi.dag.disl.staticcontext" />
			<package name="ch.usi.dag.disl.dynamiccontext" />
			<package name="ch.usi.dag.disl.classcontext" />
			<package name="ch.usi.dag.disl.processorcontext" />
			<package name="ch.usi.dag.disl.transformer" />
		</javadoc>
	</target>


	<!-- Miscellaneous -->

	<target name="copy-asm">
723
		<copy file="${asm.path}" tofile="${out.lib}/${asm.lib}" />
724 725 726 727
	</target>


	<target name="package-src">
728
		<zip destfile="${out.src}/src.zip">
729
			<zipfileset dir="${src.disl}" />
730
			<zipfileset dir="${src.disl.bypass}/dynamic" />
731 732 733 734 735 736 737 738 739
			<zipfileset dir="${src.shvm}" />
			<zipfileset dir="${src.shvm.dispatch}" />
			<zipfileset dir="${src.util}" />
		</zip>
	</target>


	<!-- Releases -->

740
	<target name="release-bin" depends="build,package-src">
741
		<!-- Collect the artifacts from output and source directories. -->
742
		<zip destfile="${release.bin.zip}">
743
			<zipfileset prefix="${disl.prefix}/${dist.bin}" dir="${src.bin}" fileMode="755" />
744 745 746 747 748 749 750 751 752
			<zipfileset prefix="${disl.prefix}/${dist.lib}" dir="${out.lib}">
				<include name="${asm.lib}" />
				<include name="${disl.lib}" />
				<include name="${disl.bypass.lib}" />
				<include name="${disl.agent.lib}" />
				<include name="${shvm.lib}" />
				<include name="${shvm.dispatch.lib}" />
				<include name="${shvm.agent.lib}" />
			</zipfileset>
753
			<zipfileset prefix="${disl.prefix}/${dist.doc.intro}" file="${doc.intro.pdf}" />
754 755 756 757 758 759 760 761 762 763
			<zipfileset prefix="${disl.prefix}/${dist.doc.jdoc}" dir="${out.doc.jdoc}" />
			<zipfileset prefix="${disl.prefix}/${dist.examples}" dir="${src.examples}">
				<exclude name="build-override.properties" />
			</zipfileset>
			<zipfileset prefix="${disl.prefix}/${dist.src}" dir="${out.src}" />
			<zipfileset prefix="${disl.prefix}" dir=".">
				<include name="COPYING" />
				<include name="README" />
				<include name="USER_ERRORS" />
			</zipfileset>
764 765
		</zip>

766
		<!-- Convert the zip archive to bzip2 compressed tar. -->
767 768 769 770 771 772
		<tar destfile="${release.bin.tar}" compression="bzip2">
			<zipfileset src="${release.bin.zip}" />
		</tar>
	</target>


773
	<target name="release-src" depends="clean-examples">
774 775
		<zip destfile="${release.src.zip}">
			<zipfileset prefix="disl-${disl.version}" dir=".">
776 777 778 779 780
				<include name="${src.bin}/" />
				<include name="${src.doc}/" />
				<include name="${src.examples}/" />
				<include name="${lib.dir}/*.jar" />
				<include name="${lib.dir}/*.txt" />
781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804
				<include name="COPYING" />
				<include name="README" />
				<include name="README_TESTS" />
				<include name="USER_ERRORS" />
				<include name="build.properties" />
				<include name="build.xml" />
				<include name="disl.version" />
				<include name=".settings/" />
				<include name=".project" />
				<include name=".classpath" />
				<include name="eclipse.*" />
			</zipfileset>
			<zipfileset prefix="disl-${disl.version}" dir="." includes="src*/" excludes="**/var,**/find.sh,**/*.so,**.jnilib,**/*.o" />
			<zipfileset prefix="disl-${disl.version}" dir="." includes="src*/**/find.sh" filemode="755" />
		</zip>

		<tar destfile="${release.src.tar}" compression="bzip2">
			<zipfileset src="${release.src.zip}" />
		</tar>
	</target>


	<!-- Summary targets -->

805
	<target name="compile" depends="compile-disl,compile-disl-agent,compile-shvm,compile-shvm-agent" description="Compiles DiSL, Shadow VM, and the JVM agents for both." />
806

807
	<target name="build" depends="build-disl,build-disl-agent,build-shvm,build-shvm-agent,copy-asm" description="Builds DiSL and Shadow VM, without documentation." />
808

809
	<target name="eclipse" depends="build-eclipse-agent,build-disl-bypass" description="Creates libraries for developing DiSL under Eclipse." />
810

811
	<target name="doc" depends="build-doc,build-jdoc" description="Builds DiSL documentation (requires javadoc and pdflatex)." />
812

813
	<target name="release" depends="doc,release-bin,release-src" description="Produces DiSL source and binary release archives." />
814 815 816 817


	<!-- Clean up -->

818 819 820 821 822 823
	<target name="clean-examples">
		<ant dir="${src.examples}" target="clean" />
	</target>


	<target name="clean" depends="clean-examples">
824
		<exec executable="make" dir="${src.disl.agent}">
825
			<arg value="cleanall" />
826 827 828
		</exec>

		<exec executable="make" dir="${src.shvm.agent}">
829
			<arg value="cleanall" />
830
		</exec>
831 832

		<delete dir="${out.dir}" />
833 834
	</target>

835
</project>