Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1820 skinsman 1
<project name="envchange-task">
2
 
3
	<!--	C O P Y R I G H T   N O T I C E
4
			This material is confidential to ERG and may not be disclosed in whole
5
			or in part to any third party nor used in any manner whatsoever other
6
			than for the purposes expressly consented to by ERG in writing.
7
 
8
			This material is also copyright and may not be reproduced, stored in a
9
			retrieval system or transmitted in any form or by any means in whole or
10
			in part without the express written consent of ERG.
11
	-->
12
 
13
	<!-- "REPLACE_ANT_WINDOWS" below gets replaced by ant-windows version when
14
		 this package is released. -->
15
	<using name="ant-windows" version="REPLACE_ANT_WINDOWS"/>
16
 
17
 
18
	<!-- Invoke another copy of Ant and run the specified target.
19
		 This allows modification of the environment by:
20
		  - attribute "pathadditions=" - append the given string to the Path/PATH
21
		    environment variable.  String can contain multiple extra paths
22
		    separated by either ";" or ":".
23
		  - "<env>" elements as per the standard "<exec>" Ant task.
24
 
25
		 This is used for e.g. ensuring the Borland compiler can find the Borland
26
		 linker (ilink32).
27
 
28
		 Note "using.nocache=true" is set on the new Ant to flag that all ant-using
29
		 caching has already been done on the first Ant, so no need to do it all again.
30
	 -->
31
	<macrodef name="envchange">
32
		<attribute name="target"/>
33
		<attribute name="pathadditions" default="NO_ADDITIONS"/>
34
 
35
		<!-- Any elements inside <envchange> implicitly are part of <envchange-elements>.
36
			 This is to pick up <env> elements for <exec>. -->
37
		<element name="envchange-elements" implicit="yes" optional="yes"/>
38
		<sequential>
39
			<!-- Get existing Path/PATH env var -->
40
			<if>
41
				<isset property="windows"/>
42
				<then>
43
					<property name="envchange.oldpath" value="${env.Path}"/>
44
				</then>
45
				<else>
46
					<property name="envchange.oldpath" value="${env.PATH}"/>
47
				</else>
48
			</if>
49
 
50
			<!-- Add specified additions to old path, or just use old path as is
51
				 if no additions were specified -->
52
			<if>
53
				<equals arg1="@{pathadditions}" arg2="NO_ADDITIONS"/>
54
				<then>
55
					<property name="envchange.newpath" value="${envchange.oldpath}"/>
56
				</then>
57
				<else>
58
					<property name="envchange.newpath" value="${envchange.oldpath};@{pathadditions}"/>
59
				</else>
60
			</if>
61
			<if>
62
				<isset property="windows"/>
63
				<then>
64
 
65
					<!-- Note we can't use executable=ant.bat because we don't get error codes
66
					     propagated back to detect build failures.  This is an inconsistency in
67
					     Windows - that you'll get the error code of the batch file's last command
68
					     even if it's something irrelevant like a goto!  However if you run a batch
69
					     file in an existing shell then an error code will be maintained.  e.g.
70
					     if from the cmd line you echo %ERRRORLEVEL%.  So that's why we need to
71
					     exec cmd.exe instead and call the batch file from there.
72
					 -->
73
				    <exec executable="cmd.exe" failonerror="true">
74
				    	<arg value="/c"/>
75
						<arg value="call ant.bat -f ${ant.file} -Dusing.nocache=true @{target}"/>
76
						<env key="Path" path="${envchange.newpath}"/>	<!-- Windows: use "Path" env var -->
77
						<envchange-elements/>
78
		    		</exec>
79
		    	</then>
80
		 	   <else>
81
		 	   		<!-- Not Windows - so invoke ant directly -->
82
				    <exec executable="ant" failonerror="true">
83
						<arg value="-f"/>
84
						<arg value="${ant.file}"/>
85
						<arg value="-Dusing.nocache=true"/>
86
						<arg value="@{target}"/>
87
						<env key="PATH" path="${envchange.newpath}"/>	<!-- Unix: use "PATH" env var -->
88
						<envchange-elements/>
89
		    		</exec>
90
		 	   </else>
91
		    </if>
92
		</sequential>
93
	</macrodef>
94
 
95
</project>