[Scons-users] JavaH builder doesn't get output file names right for inner classes

Abigail Bunyan abigail.bunyan at microsoft.com
Mon Feb 20 06:23:38 EST 2017


Given a Java source file like:

    class Outer {
        class Inner {
            public native void f();
        }
    }

javac will create Outer.class and Outer$Inner.class, but javah will create
Outer.h and Outer_Inner.h. However, the SCons JavaH builder expects it to
create Outer$Inner.h, leading to unnecessary rerunning of javah:

    $ echo "JavaH('jni', 'Outer.java')" > SConstruct
    $ scons -Q --debug=explain
    scons: building `Outer/Outer$Inner.class' because it doesn't exist
    javac -d Outer -sourcepath . Outer.java
    scons: building `jni/Outer$Inner.h' because it doesn't exist
    javah -d jni -classpath Outer Outer Outer
    $ ls jni
    Outer.h Outer_Inner.h
    $ scons -Q --debug=explain
    scons: building `jni/Outer$Inner.h' because it doesn't exist
    javah -d jni -classpath Outer Outer Outer

This issue can also cause builds to fail due to the missing dependency:

    $ echo '#include "jni/Outer_Inner.h"' > Outer_Inner.c
    $ echo 'Library("outer", ["outer.c"])' >> SConstruct
    $ rm -rf jni/ Outer/ && scons -Q
    javac -d Outer -sourcepath . Outer.java
    gcc -o outer.o -c outer.c
    outer.c:1:29: fatal error: jni/Outer_Inner.h: No such file or directory
     #include "jni/Outer_Inner.h"
                                 ^
    compilation terminated.
    scons: *** [Outer_Inner.o] Error 1

This is occurring under SCons v2.5.1.


More information about the Scons-users mailing list