Skip to content

SWIG Java dependency issue #1672

Closed
Closed

Description

@bdbaddog

This issue was originally created at: 2007-05-30 07:56:44.
This issue was reported by: toolshed.
toolshed said at 2007-05-30 07:56:44

Note: also observed in 0.96.1
Note: checking 0.97 now, will update with results

I'm running in to the exact same issue that this person ran in to concerning
SWIG and Java:
http://scons.tigris.org/servlets/ReadMsg?listName=users&msgNo=1118
related: http://scons.tigris.org/servlets/ReadMsg?list=users&&msgNo=1150

The build actually works but requires SCons to be run twice for it to succeed,
the first build ending in the following failure:

jar cf Core/ClientSMLSWIG/Java/sml.jar -C Core/ClientSMLSWIG/Java/classes .
Core/ClientSMLSWIG/Java/classes/. : no such file or directory
scons: *** [Core/ClientSMLSWIG/Java/sml.jar] Error 1
scons: building terminated because of errors.

Basically, here's how I see what is happening (keep in mind that I'm fairly new
to SCons so I may be way off here):

  • Key parts of my configuration file (Core/ClientSMLSWIG/Java/SConscript):
    swigflags = '-c++ -java ... -outdir Core/ClientSMLSWIG/Java/build
    env.SharedLibrary('Java_sml_ClientInterface', 'Java_sml_ClientInterface.i',
    SWIGFLAGS = swigflags, ... )
    env.Java('classes', 'build')
    env['JARCHDIR'] = 'Core/ClientSMLSWIG/Java/classes'
    env.Jar('sml.jar', 'classes')

  • First run:
    ** scons runs generating dependency tree
    ** scons finds nothing in 'build' so assumes 'classes' is up to date
    ** scons runs building things
    ** Java_sml_ClientInterface is built correctly, producing java files in build
    ** the env.Jar command is attempted but classes doesn't exist (it is created by
    the env.Java step) so it fails, scons quits.

  • Second run
    ** scons runs generating dependency tree
    ** scons finds java files in 'build'
    ** scons runs building things
    ** env.Java runs compiling the java files in build producing class files in classes
    ** env.Jar command succeeds

I have tried many different things like Depends and AlwaysBuild, but these
things do not seem to work because, I think, there are no java files in 'build'
when dependencies are generated so the target is assumed up to date no matter
what. I don't know.

The only thing I have been able to use as a workaround (besides running scons
twice) is to have a two-stage build:

  • scons Core/ClientSMLSWIG/Java/libJava_sml_ClientInterface.so
    ** (build succeeds)
  • scons
    ** (build succeeds)

stevenknight said at 2007-06-09 05:54:35

Thanks for the report. There are several issues affecting this.

The first issue that I can readily identify is that SCons doesn't know about the
swig -outdir option, so it doesn't know that the output files will end up in
-outdir. There are (at least) two ways we can add support for this. One would
be to have you set it in $SWIGFLAGS, like you're doing, and pluck the directory
from it. The second would be to add a $SWIGOUTDIR variable.

The second issue is that SCons really doesn't know or understand that the -java
option will cause generation of the .java files, regardless of whether -outdir
is used or not. From SCons' point of view, they're essentially created as an
unknown side effect of the build. It so happens that the Java builder will look
on disk for files, though, so they get swept up by the rebuild, but that's more
or less by accident. (The whole thing kind of works because the generated
*_wrap.{c,cc} file acts as an up-to-date build marker for all of the files
created by the swig call.)

However, IIUC, the name(s) of the generated Java file(s) actually get
constructed from the %module definition in the .i file. Is that right? If so,
then we actually need to use a scanner to fetch the %module name and use that to
generate the correctly-named Nodes for the Java files. That means creating a
$SWIGOUTDIR variable will be a lot more viable than just setting it in $SWIGFLAGS.

Taking care of those two issues might be sufficient, or it might need some
additional work once we see the actual behavior with -outdir and generated Java
output files in the dependency graph.

As we work on this, I may throw a patch or two your way for live testing, to
make sure that the test cases I'll write reflect reality.

Thanks again,

   --SK

stevenknight said at 2007-07-13 08:02:53

I'm getting back to this one, but I'm having trouble creating the proper test
case (mainly due to gaps in my swig + java knowledge).

Could you (or anyone) describe a "Hello world" test case for this? I need to
know what the initial directory layout looks like, where the files are, and
simplest-possible contents for those files.

Thanks,

   --SK

toolshed said at 2007-07-13 08:06:46

I'll see if I can whip up a simple case today or by Monday.

toolshed said at 2007-07-13 11:54:59

Created an attachment (id=204)
linux scons swig java problem illustration

toolshed said at 2007-07-13 12:03:30

I've attached a simple test case. It could possibly be further simplified, I'm
actually not the SWIG guy here and I'm still pretty new at SCons but I gave it
my best shot.

To illustrate this bug on a linux system:

  1. install swig >= 1.3.31
  2. extract scons-swig-test.tar.gz
  3. scons
  4. scons should error out with this message or very similar:

g++ -o java/Java_foo_interface_wrap.os -c -fPIC -g -Wall -Ifoo
-I/usr/lib/jvm/java-6-sun-1.6.0.00/include
-I/usr/lib/jvm/java-6-sun-1.6.0.00/include/linux java/Java_foo_interface_wrap.cpp
jar cf java/foopack.jar -C java/classes .
java/classes/. : no such file or directory
scons: *** [java/foopack.jar] Error 1
scons: building terminated because of errors.

4a) if you have a java error other than something like "no such file or
directory", consider installing sun-jdk >= 1.5 and setting JAVA_HOME to
/path/to/jdk before running scons

  1. run scons again, it should succeed (because the java file in classes/ is
    there during the source scan this time)

  2. remove the tree and return to step 2 to repeat, I didn't include the code for
    scons -c to clean everything.

stevenknight said at 2007-07-13 20:02:09

Many thanks for the test case. I used it to strip down a minimal case for
implementing $SWIGOUTDIR, just checked in as revision 2134:

http://scons.tigris.org/servlets/ReadMsg?list=dev&msgNo=3894
http://scons.tigris.org/servlets/ReadMsg?list=commits&msgNo=701

This is only a first step. The next should be to hook up the generated .java
files that SCons now knows about with the Java() and Jar() builders.

stevenknight said at 2007-07-16 18:53:26

See http://scons.tigris.org/issues/show_bug.cgi?id=1578 for another bug
concerning SWIG dependencies (in that case failure to identify %include
dependencies).

stevenknight said at 2007-08-07 15:06:56

This problem should be fixed by revision #2222:

http://scons.tigris.org/servlets/ReadMsg?list=dev&msgNo=4014
http://scons.tigris.org/servlets/ReadMsg?list=commits&msgNo=789

Which was the final step in a series of patches (largely contributed by Leanid
Nazdrynau) which turned the chain of Java-related Builders into a "multi-step"
builders so you can also do things like pass a .i file name directly to
env.Jar() (for example) and have the intermediate files generated automatically,
without having to call the intervening Builders by hand.

The interactions between these different tools get pretty complicated, so there
are probably corner cases that aren't handled correctly. If you stumble on any
of these, please open up a new Issue for each one (preferably with a
reproducible test case, of course).

Many thanks for the test case, which has been incorporated (in a further
stripped-down form) into the test suite.

   --SK

stevenknight said at 2007-08-07 15:09:25

Make this a blocking issue for the 0.97.1 task.

stevenknight said at 2007-08-07 20:25:58

*** Issue 1486 has been marked as a duplicate of this issue. ***

Votes for this issue: 40.

toolshed attached scons-swig-test.tar.gz at 2007-07-13 11:54:59.

linux scons swig java problem illustration

stevenknight said this issue blocks #1664 at 2007-08-07 15:09:25.

stevenknight said this issue is duplicated by #1486 at 2007-08-07 20:25:58.

Activity

  1. added
    Java
    and removed on Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    JavaVersion: 0.96.96bugswig

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions