1
votes

I recently I followed this great guide to integrate the subversion revision into exe/dll files generated from my c++/c# visual studio projects. Now I can easily right-click on an exe-file to find which revision was used to build the binary (see image below). I love this feature.

Is this possible to do the same in flash/flex when building air/stand-alone applications? I would like to tag both exe file and dlls.

Details with svn revision information
(source: zachburlingame.com)


Update with solution:

Although the ANT-based solutions provided here aren't as smooth as the one where the svn info is burnt into .exe/.dll files (in my opinion), it has solved my problem and is now implemented in our productions. My setup is based both on Kevin's and frankhermes's answeres but uses SubMCRev.exe instead of svn.exe or jar files.

In our implementation we dump the svn revision to the logfile at startup. The output from the SVN target below looks like this:

Built with SVN Revision: 1.0.0.1181 (local modifications found)

SVN target:

<target name="SVN Revision">
        <exec executable="subWCRev.exe" outputproperty="revision">
            <arg value="${basedir}\\.." />
            <redirector>
                <outputfilterchain>
                    <linecontainsregexp>
                        <regexp pattern='^([Last]|[Local])' />
                    </linecontainsregexp>
                    <tokenfilter>
                        <replaceregex pattern='[\D]+([\d]+)' replace="Built with SVN Revision: 1.0.0.\1" />
                        <replaceregex pattern='Local modifications found' replace=" (local modifications found)" />
                    </tokenfilter>
                    <striplinebreaks />
                </outputfilterchain>
            </redirector>
        </exec>
    </target>

Compile target:

<target name="compile" depends="init, SVN Revision">
        <mxmlc file="..." output="...">
            <define name="compile::REVISION" value="'${revision}'" />
        ....        
        </mxmlc>
    </target>
2
This might not be possible directly... but you can use this cool autoupate feature integrated by default in AIR gregsramblings.com/2008/08/16/…Neeraj
Incase you feel this is the right thing. please ask me to put it up as an answer and mark it as correct.Neeraj
Thanks for the answere Neeraj. While this is indeed a nice feature it does not match my current configuration and it would not be effortless to implement in my setup. I appreciate your comment and I will look into it more deeply later on, but it does not directly help me. If you make this into an answere I will however give you a vote-up :)Avada Kedavra
hey..i got what you are looking for, though this might not be automated... there will be a file under your src folder by the name <app_name>.xml e.g lets say your project is by the name 'myproject' then there will be a file myproject.xml (not mxml but xml) in your src folder, here there are various properties like version, name etc that you can configure, this might reflect in the properties of the .exe file that is generated after installing the .air.I am not sure, but this seems like something that will put a version in the properties the resultant files.Neeraj
you can get more details here livedocs.adobe.com/flex/3/html/…Neeraj

2 Answers

4
votes

I was actually looking to do this myself, so I figured I'd investigate it. I use ANT and mxmlc to do my builds. Here is an ANT snippet I found here to get the revision number:.

<target name="find_revision" description="Sets property 'revision.number' to the head svn revision">
        <property name="revision" value="HEAD"/>

        <!-- find out revision number of HEAD, need svn.exe installed on local machine -->
   <exec executable="svn" outputproperty="revision.number">
        <arg line="info -r ${revision}"/>
        <redirector>
           <outputfilterchain>
              <linecontainsregexp>
                 <regexp pattern='^Revision' />
              </linecontainsregexp>
              <tokenfilter>
                <replaceregex pattern='[\D]+([\d]+)' replace="\1" />
              </tokenfilter>
           </outputfilterchain>
        </redirector>
   </exec>
</target>

With the revision number found one could pass the variable as a global constant at compilation time. This is accomplished via the mxmlc parameter:.

 define=NAMESPACE::variable,value

This variable can be retrieved in AS3 and used in whatever way you want. See using conditional compilation for details.

I haven't found a way to set an AIR Application's descriptors programmatically yet, so you might have to edit/create your XML descriptor file via ANT before compilation.

Let me know if this method works for you so I can use it myself =D

1
votes

We use the following method (and it's pretty similar to Kevin's answer but I can confirm that it works):

a snippet from my build.xml: this uses two jar files (svnkit and svntask) instead of svn.exe (so it runs cross-platform) - these jars are checked in via svn too so you can't lose them or misinstall.

<!-- SVN revision stuff -->
<typedef resource="com/googlecode/svntask/svntask.xml">
    <classpath>
        <fileset dir="${basedir}/util">
            <include name="svnkit.jar"/>
            <include name="svntask.jar"/>
        </fileset>
    </classpath>
 </typedef>

<target name="revision">
    <svn><info path="${basedir}" revisionProperty="revision" /></svn>
    <echo>${revision}</echo>
</target>
<!-- /SVN revision stuff -->

Now we have the revision in a property that we include in the mxmlc task as a conditional compiler variable:

        <mxmlc file="${src.dir}/@{appfile}.@{ext}"
            output="@{output}/@{appfile}.swf"
            debug="@{debug}"
            target-player="${version_major}"
            optimize="true"
            locale=""
            use-network="true"
        >
            <define name="compile::REVISION" value="'${revision}'"/>
            [... rest snipped]
        </mxmlc>

Then you can use that variable in AS:

var version:String = "1.0."+compile::REVISION;

For the code to work in Flash Builder too, you'd have to add the following line to your additional compiler arguments:

-define+=compile::REVISION,'dev' 

That way your development code will have the revision 'dev', indicating that it was not necessarily built from a committed version of the code.