#8 <cc>Absolute src filenames can't be used

closed-out-of-date
nobody
None
5
2004-04-22
2002-06-14
No

I want to be able to use the ForEach method to compile
multiple test targets, for example:

<foreach target="BuildTest" param="testsrc">
<fileset dir="." includes="*_test.c"/>
</foreach>

<target name="BuildTest" description="Build one unit
test">
<echo message="Building test: ${testsrc}"/>
<cc outfile="${testsrc}_test" debug="${debug}">
<fileset dir="." includes="${testsrc}"/>
</cc>
</target>

The problem is that the value of ${testsrc} which
appears in the BuildTest target is absolute, including
the leading directory separator. Changing the dir
attribute in the fileset element in BuildTest to "/"
doesn't fix things either. I poked around in the ANT
source and the various Java File class constructors
looking for a value which would get around this, but
had no success.

The work around I used was to declare an attribute
"absolute" for the cpptasks ConditionalFileSet type and
then set it to false to change the filename to be
relative to the specified directory.

/**
* Add the ability to make an include relative to
the current directory.
*/
public void setIncludes(String includes) {
if (!absoluteCond.equals("true")) {
String dir = getDir(getProject()).toString() +
File.separator;
if (includes.startsWith(dir)) {
includes = includes.substring(dir.length());;
}
}
super.setIncludes(includes);
}

Can anyone suggest a better way to compile hundreds of
C unit test files?

~Matt
doar@pobox.com

Discussion

  • Curt Arnold

    Curt Arnold - 2004-04-22

    Logged In: YES
    user_id=27193

    This was a limitation prior to Ant 1.6 with added a file
    attribute to fileset that resolves this problem.

    <cc>
    <fileset file="${testsrc}"/>
    </cc>

     
  • Curt Arnold

    Curt Arnold - 2004-04-22
    • status: open --> closed-out-of-date
     
  • Curt Arnold

    Curt Arnold - 2004-04-22

    Logged In: YES
    user_id=27193

    This was a limitation prior to Ant 1.6 with added a file
    attribute to fileset that resolves this problem.

    <cc>
    <fileset file="${testsrc}"/>
    </cc>

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks