Modify build.xml: want a precompile option

Hi,

when developing an extension sometimes a wrong version is executed. Either I forgot to upload the new version or I didn't restart the Companion or ...

When developing other programs, I have an automatic system that increases the version number (build number) before compiling. Concrete, a self written program is started before compiling that replaces some text (the version name) in the source code. Displaying the version name in the log or on the screen helps to detect such errors.

I build the extension with ant ("ant extensions"). The specifications for the build process come from "build.xml".

However, I am not familiar with "ant" or with "build.xml". Can someone tell me how to modify "build.xml" so that an external program is started once at the beginning of build? This program needs the path to the sources as a parameter. An alternative would be to start a program for each file before it is passed to the compiler.

Kind regards Ulrich

Ant structures all of its commands using XML. The XML tag indicates what code is to be run. Most tasks are implemented in Java. However, there is an "escape hatch," so to speak. You can use the <exec> task to execute external tools. For example, we execute git to create a build ID in common/build.xml:

This then sets up a filter that is use to replace tokens in a Java file. Using this information, you could do something like:

  <target name="BumpExtensionVersion" if="autoversion">
    <exec executable="date" outputproperty="ext.version">
      <arg line="+%s"/>
    </exec>
    <exec executable="sed">
      <arg value="-i"/>
      <arg value=""/> <!-- change to ".bak" for additional safety -->
      <arg value="s/version *= *[1-9][0-9]*,/version = ${ext.version},/"/>
      <arg value="src/edu//mit/appinventor/ai/personalimageclassifier/PersonalImageClassifier.java"/>
    </exec>
  </target>

and then make the AndroidRuntime target depend on this. Note this assumes a Unix-like environment with date and sed available. Once you've done that, running ant -Dautoversion=1 extensions will set the version number in your extension's source code to the number of seconds since the Unix epoch. Running ant extensions won't bump the version number.

2 Likes

Thanks for the explanation. I will try it.

Here it is: AI2VersionUpdate

1 Like