2
votes

I have an AS3 project making use of compile time constants. This has worked well in FDT and adding compiler arguments like:

-define=CONFIG::buildver,"0.1"

But when trying to replicate this when build with an ant script:

<project name="ProjectName" default="compileMain" basedir=".">
<property file="build.properties" />    
<target name="compileMain">
    <exec executable="${mxmlc}">

        <arg line='-define=CONFIG::testvar,"0.1"' />
        <arg line="-source-path '${classesdir}'" />
        <arg line="-library-path '${flex3libsdir}'" />
        <arg line="-output '${bindir}/TestSwf.swf'" />
        <arg line="-file-specs '${classesdir}/Test_Main.as'" />

    </exec>
</target>   

I get "Error: The initializer for a configuration value must be a compile time constant."

I have tried using -define+=CONFIG, but get the same response.

Does anyone with experience with compile time constants and ant have any suggestions?

2

2 Answers

2
votes

I'm using it like this:

<define name="CONFIG::LOGGING" value="false" />

but in <compc> so not sure will it work or not in exec... but you can try ;)

1
votes

I'm using arg with the value attribute and alternating key/value on each line. Not sure if this is best practice (it seems rather shoddy to me) but I do remember trying a bunch of different options back when I set up my Ant script a couple years ago and this is what stuck.

Due to the "Ain't Broke, Don't Fix" Principle I've left it be and been using it quite happily for over two years now.

Using your sample it would look something like this:

<project name="ProjectName" default="compileMain" basedir=".">
<property file="build.properties" />    
<target name="compileMain">
    <exec executable="${mxmlc}">

    <arg value="-define=CONFIG::testvar,0.1"/>
    <arg value="-source-path"/>
    <arg value="${classesdir}"/>
    <arg value="-library-path"/>
    <arg value="${flex3libsdir}"/>
    <arg value="-output"/>
    <arg value="${bindir}/TestSwf.swf"/>
    <arg valye="-file-specs"/>
    <arg value="${classesdir}/Test_Main.as"/>

    </exec>
</target>