Compiler refid problem

Help
saber850
2004-04-21
2004-04-21
  • saber850
    saber850
    2004-04-21

    It seems that if I use the 'refid' attribute of a <compiler> element, the referenced <compiler> element is not inserted/used unless it's the only <compiler> element or if it includes a <fileset> element.
    More specifically, if the referenced <compiler> element consists solely of <defineset>, <includepath>, and/or <sysincludepath> element(s), it is not inserted/used.
    For example:

    CASE 1: ---

    <compiler id="extcompile" >
    <defineset define="foo" />
    <includepath path="p1" />
    </compiler>

    <!-- Does not include contents of 'extcompile' in build. -->
    <target name="build">
    <cc ...>
       <compiler name="g++" />
       <compiler refid="extcompile" />
       <fileset dir="src" includes="*.cpp" />
    </cc>
    </target>

    <!-- Includes contents of 'extcompile' in build. -->
    <target name="build">
    <cc ...>
       <compiler refid="extcompile" />
       <fileset dir="src" includes="*.cpp" />
    </cc>
    </target>

    CASE 2: ---

    <compiler id="extcompile2" >
    <defineset define="foo" />
    <includepath path="p1" />
    <fileset dir="src2" includes="*.cpp">
    </compiler>

    <!-- Includes contents of 'extcompile2' in build. -->
    <target name="build">
    <cc ...>
       <compiler name="g++" />
       <compiler refid="extcompile2" />
       <fileset dir="src" includes="*.cpp" />
    </cc>
    </target>

    <!-- Includes contents of 'extcompile2' in build. -->
    <target name="build">
    <cc ...>
       <compiler refid="extcompile2" />
       <fileset dir="src" includes="*.cpp" />
    </cc>
    </target>

     
    • Curt Arnold
      Curt Arnold
      2004-04-21

      Nested compiler definitions are used to establish a bidding sequence when files are presented to the task for compilation.  Each compiler will bid a value based on its recognition of the file extension.  A FORTRAN compiler would make a non-zero bid for a .f file, a C++ compiler would bid on .cpp and .c and make a token bid on .h.  A resource compiler would bid on .rc's etc.  If multiple compilers make the same bid, the first one wins.

      In your first example, you establish a bidding order of:

      g++ (first nested compiler)
      extcompile (gcc with defineset and include path)
      default compiler based on <cc name=""/>)

      Since g++ is not going to be out-bid by extcompile or the default compiler (assuming that the default  is a C compiler), it will win every bid and compile every file that is specified in the filesets within the cc element.

      If a compiler has a nested fileset, that indicates that those files should only be processed by that compiler.

      The behavior that you are describing seem to be as designed.

       
      • saber850
        saber850
        2004-04-21

        Now I understand; I wasn't aware of the bidding process inside a <cc> task.  As you said, <cc> task seems to be performing properly; thank you.