| 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:
|
| 1824 |
skinsman |
20 |
- "<env>" elements as per the standard "<exec>" Ant task. It's best not to use
|
|
|
21 |
this for modifying Path or PATH.
|
|
|
22 |
- attribute "pathreplacement=" - replace the Path/PATH environment variable
|
|
|
23 |
with the given string. String can contain multiple extra paths
|
| 1820 |
skinsman |
24 |
separated by either ";" or ":".
|
| 1824 |
skinsman |
25 |
- attributes "pathinsertions=" & "pathadditions=" - prepend / append the given
|
|
|
26 |
string to the Path/PATH environment variable. String can contain multiple
|
|
|
27 |
extra paths separated by either ";" or ":".
|
| 1820 |
skinsman |
28 |
|
|
|
29 |
This is used for e.g. ensuring the Borland compiler can find the Borland
|
|
|
30 |
linker (ilink32).
|
|
|
31 |
|
|
|
32 |
Note "using.nocache=true" is set on the new Ant to flag that all ant-using
|
|
|
33 |
caching has already been done on the first Ant, so no need to do it all again.
|
|
|
34 |
-->
|
|
|
35 |
<macrodef name="envchange">
|
|
|
36 |
<attribute name="target"/>
|
| 1824 |
skinsman |
37 |
<attribute name="pathreplacement" default="NOT_SUPPLIED"/>
|
|
|
38 |
<attribute name="pathinsertions" default="NOT_SUPPLIED"/>
|
|
|
39 |
<attribute name="pathadditions" default="NOT_SUPPLIED"/>
|
| 1820 |
skinsman |
40 |
|
|
|
41 |
<!-- Any elements inside <envchange> implicitly are part of <envchange-elements>.
|
|
|
42 |
This is to pick up <env> elements for <exec>. -->
|
|
|
43 |
<element name="envchange-elements" implicit="yes" optional="yes"/>
|
|
|
44 |
<sequential>
|
| 1824 |
skinsman |
45 |
<!-- Replacing the path completely? -->
|
| 1820 |
skinsman |
46 |
<if>
|
| 1824 |
skinsman |
47 |
<not><equals arg1="@{pathreplacement}" arg2="NOT_SUPPLIED"/></not>
|
| 1820 |
skinsman |
48 |
<then>
|
| 1824 |
skinsman |
49 |
<property name="envchange.newpath" value="@{pathreplacement}"/>
|
| 1820 |
skinsman |
50 |
</then>
|
|
|
51 |
<else>
|
| 1824 |
skinsman |
52 |
<!-- Changing existing path - Get existing Path/PATH env var -->
|
|
|
53 |
<if>
|
|
|
54 |
<isset property="windows"/>
|
|
|
55 |
<then>
|
|
|
56 |
<property name="envchange.oldpath" value="${env.Path}"/>
|
|
|
57 |
</then>
|
|
|
58 |
<else>
|
|
|
59 |
<property name="envchange.oldpath" value="${env.PATH}"/>
|
|
|
60 |
</else>
|
|
|
61 |
</if>
|
| 1820 |
skinsman |
62 |
|
| 1824 |
skinsman |
63 |
<!-- Add specified additions to old path, or just use old path
|
|
|
64 |
if no additions were specified -->
|
|
|
65 |
<if>
|
|
|
66 |
<equals arg1="@{pathinsertions}" arg2="NOT_SUPPLIED"/>
|
|
|
67 |
<then>
|
|
|
68 |
<property name="tmppath" value="${envchange.oldpath}"/>
|
|
|
69 |
</then>
|
|
|
70 |
<else>
|
|
|
71 |
<property name="tmppath" value="@{pathinsertions};${envchange.oldpath}"/>
|
|
|
72 |
</else>
|
|
|
73 |
</if>
|
|
|
74 |
<if>
|
|
|
75 |
<equals arg1="@{pathadditions}" arg2="NOT_SUPPLIED"/>
|
|
|
76 |
<then>
|
|
|
77 |
<property name="envchange.newpath" value="${tmppath}"/>
|
|
|
78 |
</then>
|
|
|
79 |
<else>
|
|
|
80 |
<property name="envchange.newpath" value="${tmppath};@{pathadditions}"/>
|
|
|
81 |
</else>
|
|
|
82 |
</if>
|
| 1820 |
skinsman |
83 |
</else>
|
|
|
84 |
</if>
|
|
|
85 |
<if>
|
|
|
86 |
<isset property="windows"/>
|
|
|
87 |
<then>
|
|
|
88 |
|
|
|
89 |
<!-- Note we can't use executable=ant.bat because we don't get error codes
|
|
|
90 |
propagated back to detect build failures. This is an inconsistency in
|
|
|
91 |
Windows - that you'll get the error code of the batch file's last command
|
|
|
92 |
even if it's something irrelevant like a goto! However if you run a batch
|
|
|
93 |
file in an existing shell then an error code will be maintained. e.g.
|
|
|
94 |
if from the cmd line you echo %ERRRORLEVEL%. So that's why we need to
|
|
|
95 |
exec cmd.exe instead and call the batch file from there.
|
|
|
96 |
-->
|
|
|
97 |
<exec executable="cmd.exe" failonerror="true">
|
|
|
98 |
<arg value="/c"/>
|
|
|
99 |
<arg value="call ant.bat -f ${ant.file} -Dusing.nocache=true @{target}"/>
|
|
|
100 |
<env key="Path" path="${envchange.newpath}"/> <!-- Windows: use "Path" env var -->
|
|
|
101 |
<envchange-elements/>
|
|
|
102 |
</exec>
|
|
|
103 |
</then>
|
|
|
104 |
<else>
|
|
|
105 |
<!-- Not Windows - so invoke ant directly -->
|
|
|
106 |
<exec executable="ant" failonerror="true">
|
|
|
107 |
<arg value="-f"/>
|
|
|
108 |
<arg value="${ant.file}"/>
|
|
|
109 |
<arg value="-Dusing.nocache=true"/>
|
|
|
110 |
<arg value="@{target}"/>
|
|
|
111 |
<env key="PATH" path="${envchange.newpath}"/> <!-- Unix: use "PATH" env var -->
|
|
|
112 |
<envchange-elements/>
|
|
|
113 |
</exec>
|
|
|
114 |
</else>
|
|
|
115 |
</if>
|
|
|
116 |
</sequential>
|
|
|
117 |
</macrodef>
|
|
|
118 |
|
|
|
119 |
</project>
|