Archived

This forum has been archived. Please start a new discussion on GitHub.

slice2java ant task not re-running

I have a build.xml file that works fine the first time you run it, but after running an "ant clean" task that deletes the subdirectory that slice2java creates, then successive runs of ant do not rebuild things:
$ ant
Buildfile: build.xml

slice2java:
[slice2java] skipping vnp_subversion.ice

Right now, I need to touch the slice file for it to always regenerate the *.java files.

The top portion of our slice file:
#ifndef VNP_ICE
#define VNP_ICE

[["java:package:com.imageworks.vnp"]]
module SubversionIce
{
    /** Generic exception. */
    exception VnpIceException {
        string message;
    };

and a portion of our build.xml.
<project name="VnpSubversionServer" default="slice2java">

    <property name="ice_home.dir" value="/usr/lib/Ice-3.1.1"/>

    <property name="src.dir" value="src"/>

    <property name="generated.dir"
              value="${src.dir}/com/imageworks/vnp/SubversionIce"/>

    <taskdef name="slice2java"
             classpath="${ice_home.dir}/ant"
             classname="Slice2JavaTask"/>

    <target name="slice2java">
        <!-- We seem to always need to run slice2java otherwise it
             will not create the *.java files if they have been
             deleted. -->
        <slice2java outputdir="${src.dir}">
            <fileset dir="slice" includes="vnp_subversion.ice"/>
        </slice2java>
    </target>

    <target name="clean">
        <delete file=".depend"/>
        <delete dir="${generated.dir}"/>
        <delete dir="${java.build.dir}"/>
        <delete file="${vnp_svn.jar}"/>
        <delete dir="${scala.build.dir}"/>
    </target>

</project>

Any ideas on how to make slice2java rerun if the files it generates are gone?

Regards,
Blair

Comments

  • mes
    mes California
    Hi Blair,

    The Slice2Java ant task uses a dependency file to determine whether a Slice file needs to be recompiled. By default this file is named .depend, or ${outputdir}/.depend if you define the outputdir attribute. In your ant project, this file would be called ${src.dir}/.depend.

    As you've seen, removing the generated files does not prompt the Slice2Java task to execute the translator. However, if you remove the dependency file as part of your clean target, the Slice2Java task will recompile all of your Slice files.

    Hope that helps,
    - Mark
  • Hi Mark,

    Thanks, that did the trick.

    Regards,
    Blair
  • Dependency problem when using --checksum

    I ran into a problem with the ant dependency feature after I enabled checksums. If a built detects that only some of the slice files need to be rebuilt, my checksum class is remade from only the out of date slice files, and the class is then missing entries.

    I made this patch to change the dependency tracking into an all-or-nothing rebuild, if the checksum feature is enabled.
    --- ant/Slice2JavaTask.java     (revision 153092)
    +++ ant/Slice2JavaTask.java     (revision 153093)
    @@ -118,6 +118,7 @@
             // last updated or a slice file it depends on changed).
             //
             java.util.Vector buildList = new java.util.Vector();
    +        java.util.Vector skipList = new java.util.Vector();
             java.util.Iterator p = _fileSets.iterator();
             while(p.hasNext())
             {
    @@ -137,7 +138,27 @@
                     }
                     else
                     {
    -                    log("skipping " + files[i]);
    +                    skipList.addElement(slice);
    +                }
    +            }
    +
    +            if(   _checksum != null && _checksum.length() > 0
    +               && !buildList.isEmpty())
    +            {
    +                //
    +                // If generating a checksum, all slice files must be compiled
    +                // if any are out of date so that the checksum class contains
    +                // all the entities from all the slice files.
    +                //
    +                buildList.addAll(skipList);
    +            }
    +            else
    +            {
    +                java.util.Iterator i = skipList.iterator();
    +                while(i.hasNext())
    +                {
    +                    File file = (File)i.next();
    +                    log("skipping " + file.getName());
                     }
                 }
             }
    
  • I have since discovered a bug in my patch. This bug persists in ice 3.4.0.

    If there are multiple <fileset> elements, it is possible for the same source file to be added to the command line more than once, leading to a runtime assertion in slice2java:
    [exec] slice2java: FileTracker.cpp:97: void Slice::FileTracker::setSource(const std::string&): Assertion `p.second' failed.
    

    This is because the contents of `skipList' may be added to `buildList' more than once. An easy fix is to clear `skipList' each time it is appended to `buildList'.
    --- /tmp/old.java	2010-05-10 22:18:23.213468887 -0700
    +++ Ice-3.4.0/java/src/ant/Slice2JavaTask.java	2010-05-10 22:18:41.904507790 -0700
    @@ -145,6 +145,7 @@
                     // Recompile all Slice files when checksums are used.
                     //
                     buildList.addAll(skipList);
    +                skipList.clear();
                 }
                 else 
                 {
    

    Perhaps a better choice is to move that code out of the while loop, so it only runs once. Hopefully the order of the source files on the command line is not important, because either way the order is not preserved.
    --- /tmp/old.java	2010-05-10 22:18:23.213468887 -0700
    +++ Ice-3.4.0/java/src/ant/Slice2JavaTask.java	2010-05-10 22:23:56.054481220 -0700
    @@ -138,20 +138,20 @@
                         skipList.add(slice);
                     }
                 }
    +        }
     
    -            if(_checksum != null && _checksum.length() > 0 && !buildList.isEmpty())
    -            {
    -                //
    -                // Recompile all Slice files when checksums are used.
    -                //
    -                buildList.addAll(skipList);
    -            }
    -            else 
    +        if(_checksum != null && _checksum.length() > 0 && !buildList.isEmpty())
    +        {
    +            //
    +            // Recompile all Slice files when checksums are used.
    +            //
    +            buildList.addAll(skipList);
    +        }
    +        else 
    +        {
    +            for(File file : skipList)
                 {
    -                for(File file : skipList)
    -                {
    -                    log("skipping " + file.getName());
    -                }
    +                log("skipping " + file.getName());
                 }
             }
    
  • Once ZeroC decides how to patch it, could one of the developers post an official patch so I can patch MacPorts and other distributions with it.

    Thanks,
    Blair
  • mes
    mes California
    Robert,

    Thanks for your post. A few comments:
    • slice2java should not crash when you pass duplicate files. We'll fix this. :)
    • Your patch looks correct, there's no need for that code to be inside the loop.
    • It would also make sense to change the type of buildList and skipList to HashSet, to eliminate duplicates.
    These fixes will be in the next release.

    Regards,
    Mark