[Scons-users] building Java classes from two directories

Rob Boehne robb at datalogics.com
Mon Feb 8 12:48:41 EST 2016


I modified my build to create a list of all the files in both directories, but the resulting javac command has only a single source file included.
Would that be expected?  If not I’ll have to create a toy project to demonstrate the problem.

From: Scons-users <scons-users-bounces at scons.org<mailto:scons-users-bounces at scons.org>> on behalf of William Blevins <wblevins001 at gmail.com<mailto:wblevins001 at gmail.com>>
Reply-To: SCons users mailing list <scons-users at scons.org<mailto:scons-users at scons.org>>
Date: Thursday, February 4, 2016 at 10:05 AM
To: SCons users mailing list <scons-users at scons.org<mailto:scons-users at scons.org>>
Subject: Re: [Scons-users] building Java classes from two directories

Notes that SCons expands the directories passed to javac as the list of files.... so javac A/B becomes javac A/B/**/*.java if I remember my Java regex correctly...

V/R,
William

On Thu, Feb 4, 2016 at 4:03 PM, William Blevins <wblevins001 at gmail.com<mailto:wblevins001 at gmail.com>> wrote:
Rob,

If I remember correctly Java sources are handled a bit unintuitively. If you pass in *.java files then I think they are all built together, but if you pass in directories, all the directories are "assumed" to be parallelizable; thus, if you pass in two directories, those directories will appear as separate javac commands.

If your code looks like:

A/B
A/C

source = [ A/B, A/C ] yields javac A/B and javac A/C // I don't personally like this behavior

source = [ A ] yields javac A

source = [ "all java files" ] yields javac F1 F2 ... FN

V/R,
William

On Thu, Feb 4, 2016 at 1:10 AM, Rob Boehne <robb at datalogics.com<mailto:robb at datalogics.com>> wrote:
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?






_______________________________________________
Scons-users mailing list
Scons-users at scons.org<mailto:Scons-users at scons.org>
https://pairlist4.pair.net/mailman/listinfo/scons-users



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20160208/2dbfedb4/attachment-0001.html>


More information about the Scons-users mailing list