ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "chris brown" <...@reflexe.fr>
Subject Build numbers - always available (all targets), sometimes incremented (compile target only)
Date Mon, 11 Feb 2002 10:31:18 GMT
I'm trying to create a build file that includes a build number.

The build number should be stored externally.  It should always be loaded
with either the most recent build number, or a default value.  When the
"compile" target is run, the number should be incremented, saved [to disk],
and the new value should be available for the rest of the script.  I would
like the appropriate build number to be included in the documentation
(without incrementing the number by running the "docs" target, because I'm
not really creating a new build, I'm just creating the documentation for
it); and I'd also like the number to be hard-coded (via filtering) into the
source code just before compiling.  However, I've not succeeded in getting
the results I've been looking for...

You can see a test case example of my build file below.  Some problems:

1./
I can't seem to conditionally set a property.  If ${build.number} is
available from a properties file, that's fine.  If it isn't, I'd like it to
be set to 0.  But the only way to conditionally use the <property> task
(AFAIK) is to put it into a conditional target, which seems somewhat clusmy.
Furthermore, it doesn't really work either... If target "A" invokes target
"B", and "B" runs (not blocked by if/unless condition), then the property
defined within target "B" is not available to target "A" when "B" finishes
(scope problem?).

An <if> task would be nice.  It could contain a <tests> element, containing
(possibly recursive) <and>, <or>, and <not> elements, followed by a series
of task elements to execute if the conditions evaluate to true.  Then, by
using a <propertytest property="myproperty" defined="true"/> element, I
could conditionally set my variable in the correct scope.

2./
I can't seem to modify a property's value if it has already been set.  For
example, I'd like to load in the property (here, ${build.number}) using
<property file="..."> to get a current value.  I'd like to do this in the
"init" task for two reasons: avoid duplication, and avoid problems when
executing multiple targets (e.g.: "ant compile docs" from command line).

For build "n", I'd like to apply (with filtering) the number "n" to the docs
target.  For the compile target, I'd like to apply "n+1"... however, even if
I increment this using the <propertyfile> task, then reload it using the
<property> task (with the "file" attribute), the value of the build number
property remains the same during the execution of the build script (even
although the property file is correctly updated on disk), meaning that in
the build script, filtering applies the number of the previous build to the
code...

3./
There's no way to define one property's value relative to another property's
value...  I can't say for example:
<property name="prop1" based-on="prop2" type="int" operation="+"/>

In the real project I'm working on, it's made more complicated by the fact
that it builds a system containing three subcomponents.  Sometimes I'll only
build one, sometimes two, sometimes all.  Each component needs a separate
build number, which should only be incremented when each
"compile-component-1/2/3" target is run (so I need to use <propertyfile> in
several places).

If anyone can suggest solutions (things I'm unaware of or alternative
approaches), it'd be really helpful.  If it's not workable, hopefully any
developers read this list might find some ideas to implement.

Thanks to everyone who takes the time to look into this!

- Chris B.


<project name="BuildNumTest" default="docs" basedir=".">

  <target name="init">
    <property
      name="build.properties.path"
      value="test.props"/>
    <available
      file="${build.properties.path}"
      property="build.properties.exists"/>
    <antcall target="defaults"/>
    <property file="${build.properties.path}"/>
  </target>

  <target name="defaults" unless="build.properties.exists">
    <property name="build.number" value="0"/>
    <echo>First run... ${build.number}</echo>
  </target>

  <target name="docs" depends="init">
    <echo>Docs for build ${build.number}</echo>
  </target>

  <target name="compile" depends="init">
    <propertyfile file="${build.properties.path}">
      <entry key="build.number" type="int"
        operation="+" default="0"/>
    </propertyfile>
    <property file="${build.properties.path}"/>
    <echo>Compiling build ${build.number}</echo>
  </target>

</project>



--
To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>


Mime
View raw message