[Scons-users] building Java classes from two directories

Rob Boehne robb at datalogics.com
Wed Feb 3 20:10:57 EST 2016


Scons users,

I have a Java builder that compiles classes from a few java files that are hand-written and a slew of SWIG generated java files.  The generated files depend on the hand-written ones.
Here is a snippet:


    def gen_java_source_list(target, source, env, for_signature):
        """If given a directory, simply glob all files in the directory, otherwise return a list
        of source files.

        E.g., when JARCHDIR is set, generate something like
        > jar cf foo.jar -C $JARCHDIR .
        otherwise
        > jar cf foo.jar first.class second.class ...
        """
        jarchdir = env.subst('$JARCHDIR')
        if jarchdir:
            return "-C %s ." % (jarchdir,)
        else:
            result = []
            for src in source:
                contents = src.get_contents()
                if contents[:16] != "Manifest-Version":
                    result.append(src)
            return result

    javaenv.Replace(_JARSOURCES=gen_java_source_list)
    classes = javaenv.Java('classes', [javaenv.Dir('#$GENDIR/java'), javaenv.Dir('$SOURCEPATH.abspath')])
    jar = javaenv.Jar('${JAVAPACKAGE}.jar', classes, JARCHDIR=javaenv.Dir('classes').path)

With a much older version of SCons (0.97) and python 2.5.6, the Java builder builds everything in the two directories, but only passes one directory in -sourcepath.

javac -encoding UTF-8 -target 1.5 -source 1.5 -d build\win-x86-32\Debug\classes -sourcepath gen\pdfl\java gen\pdfl\java\Action.java gen\pdfl\java\AddPageFlags.java <SNIP out 100 or so java files in gen\pdfl\java />  gen\pdfl\java\WritingMode.java gen\pdfl\java\XPSConvertParams.java Source\Interface\CJavaStreamFileImpl.java Source\Interface\Callback.java Source\Interface\ConstantName.java Source\Interface\Director.java Source\Interface\JavaInputNozzle.java Source\Interface\JavaOutputNozzle.java Source\Interface\PDFAConvertResult.java Source\Interface\PDFStreamInputAdapter.java Source\Interface\com\datalogics\PDFL\LibraryException.java

This effectively compiles.
Using the same Scons scripts with scons-2.4.1 & Python 2.7.11 (on Windows 7 with VS2013 here) the 'javac' command leaves off the second directory specified (or rather leaves out the java sources in it) which results in java compile errors for a package they define.

Using tempfile c:\users\robb\appdata\local\temp\tmp_0ip_q.lnk for command line:
javac -encoding UTF-8 -target 1.5 -source 1.5 -d build\win-x86-32\Debug\classes -sourcepath gen\pdfl\java gen\pdfl\java\Action.java gen\pdfl\java\AddPageFlags.java  <SNIP out 100 or so java files in gen\pdfl\java /> gen\pdfl\java\WritingMode.java gen\pdfl\java\XPSConvertParams.java
javac @c:\users\robb\appdata\local\temp\tmp_0ip_q.lnk
gen\pdfl\java\Action.java:10: package com.datalogics.metadata does not exist
import java.util.EnumSet;import com.datalogics.metadata.*;
                         ^
gen\pdfl\java\Document.java:10: package com.datalogics.metadata does not exist
import java.util.EnumSet;import com.datalogics.metadata.*;
                         ^
gen\pdfl\java\PDFDict.java:10: package com.datalogics.metadata does not exist
import java.util.EnumSet;import com.datalogics.metadata.*;
                         ^
gen\pdfl\java\PDFObject.java:10: package com.datalogics.metadata does not exist
import java.util.EnumSet;import com.datalogics.metadata.*;
                         ^
<SNIP>

My reading of the documentation suggests this should work, sources can be a list of directories as it is here.
Another interesting fact, if I change the order the two directories are specified in, it generates a command that only includes the sources from Source/Interface/.

Does anyone have a suggestion for a workaround or a fix?





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20160204/10a3f2c1/attachment.html>


More information about the Scons-users mailing list