diff options
Diffstat (limited to 'src/engine')
-rw-r--r-- | src/engine/SCons/Tool/JavaCommon.py | 73 | ||||
-rw-r--r-- | src/engine/SCons/Tool/jar.py | 12 | ||||
-rw-r--r-- | src/engine/SCons/Tool/javac.py | 17 | ||||
-rw-r--r-- | src/engine/SCons/Tool/javac.xml | 513 | ||||
-rw-r--r-- | src/engine/SCons/Tool/javah.py | 10 | ||||
-rw-r--r-- | src/engine/SCons/Tool/rmic.py | 15 |
6 files changed, 391 insertions, 249 deletions
diff --git a/src/engine/SCons/Tool/JavaCommon.py b/src/engine/SCons/Tool/JavaCommon.py index 23cc43b..3a472a9 100644 --- a/src/engine/SCons/Tool/JavaCommon.py +++ b/src/engine/SCons/Tool/JavaCommon.py @@ -32,6 +32,7 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os import os.path import re +import glob java_parsing = 1 @@ -391,6 +392,78 @@ else: """ return os.path.split(fn) + + +java_win32_version_dir_glob = 'C:/Program Files*/Java/jdk%s*/bin' +java_win32_dir_glob = 'C:/Program Files*/Java/jdk*/bin' + +java_macos_include_dir = '/System/Library/Frameworks/JavaVM.framework/Headers/' +java_macos_version_include_dir = '/System/Library/Frameworks/JavaVM.framework/Versions/%s*/Headers/' + +java_linux_include_dirs = ['/usr/lib/jvm/default-java/include', + '/usr/lib/jvm/java-*-oracle/include'] +java_linux_version_include_dirs = ['/usr/lib/jvm/java-*-sun-%s*/include', + '/usr/lib/jvm/java-%s*-openjdk*/include', + '/usr/java/jdk%s*/include'] + + + +def get_java_install_dirs(platform, version=None): + """ + Using patterns above find the java jdk install dir + :param platform: + :param version: If specified, only look for java sdk's of this version + :return: list of default paths for java. + """ + paths = [] + if platform == 'win32': + if version: + paths = glob.glob(java_win32_version_dir_glob%version) + else: + paths = glob.glob(java_win32_dir_glob) + else: + # do nothing for now + pass + + paths=sorted(paths) + + return paths + +def get_java_include_paths(env, javac, version): + """ + Return java include paths + :param platform: + :param javac: + :return: + """ + paths = [] + if env['PLATFORM'] == 'win32': + javac_bin_dir = os.path.dirname(javac) + java_inc_dir = os.path.normpath(os.path.join(javac_bin_dir, '..', 'include')) + paths = [java_inc_dir, os.path.join(java_inc_dir, 'win32')] + elif env['PLATFORM'] == 'darwin': + if not version: + paths = [java_macos_include_dir] + else: + paths = sorted(glob.glob(java_macos_version_include_dir%version)) + else: + base_paths=[] + if not version: + for p in java_linux_include_dirs: + base_paths.extend(glob.glob(p)) + else: + for p in java_linux_version_include_dirs: + base_paths.extend(glob.glob(p%version)) + + for p in base_paths: + paths.extend([p, os.path.join(p,'linux')]) + + #print("PATHS:%s"%paths) + return paths + + + + # Local Variables: # tab-width:4 # indent-tabs-mode:nil diff --git a/src/engine/SCons/Tool/jar.py b/src/engine/SCons/Tool/jar.py index 481f8f5..e0a6a69 100644 --- a/src/engine/SCons/Tool/jar.py +++ b/src/engine/SCons/Tool/jar.py @@ -32,11 +32,13 @@ selection method. # __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" +import os import SCons.Subst import SCons.Util from SCons.Node.FS import _my_normcase -import os +from SCons.Tool.JavaCommon import get_java_install_dirs + def jarSources(target, source, env, for_signature): """Only include sources that are not a manifest file.""" @@ -206,6 +208,14 @@ def generate(env): env.AddMethod(Jar) + if env['PLATFORM'] == 'win32': + # Ensure that we have a proper path for clang + jar = SCons.Tool.find_program_path(env, 'jar', + default_paths=get_java_install_dirs(env['PLATFORM'])) + if jar: + jar_bin_dir = os.path.dirname(jar) + env.AppendENVPath('PATH', jar_bin_dir) + env['JAR'] = 'jar' env['JARFLAGS'] = SCons.Util.CLVar('cf') env['_JARFLAGS'] = jarFlags diff --git a/src/engine/SCons/Tool/javac.py b/src/engine/SCons/Tool/javac.py index 72c48f7..8d98b54 100644 --- a/src/engine/SCons/Tool/javac.py +++ b/src/engine/SCons/Tool/javac.py @@ -39,7 +39,7 @@ from collections import OrderedDict import SCons.Action import SCons.Builder from SCons.Node.FS import _my_normcase -from SCons.Tool.JavaCommon import parse_java_file +from SCons.Tool.JavaCommon import parse_java_file, get_java_install_dirs, get_java_include_paths import SCons.Util def classname(path): @@ -208,6 +208,21 @@ def generate(env): env.AddMethod(Java) + version = env.get('JAVAVERSION', None) + + javac = SCons.Tool.find_program_path(env, 'javac') + if env['PLATFORM'] == 'win32': + # Ensure that we have a proper path for javac + paths=get_java_install_dirs(env['PLATFORM'], version=version) + javac = SCons.Tool.find_program_path(env, 'javac', + default_paths=paths) + if javac: + javac_bin_dir = os.path.dirname(javac) + env.AppendENVPath('PATH', javac_bin_dir) + + env['JAVAINCLUDES'] = get_java_include_paths(env, javac, version) + + env['JAVAC'] = 'javac' env['JAVACFLAGS'] = SCons.Util.CLVar('') env['JAVABOOTCLASSPATH'] = [] diff --git a/src/engine/SCons/Tool/javac.xml b/src/engine/SCons/Tool/javac.xml index 543d669..97ec7d2 100644 --- a/src/engine/SCons/Tool/javac.xml +++ b/src/engine/SCons/Tool/javac.xml @@ -7,279 +7,298 @@ See its __doc__ string for a discussion of the format. --> <!DOCTYPE sconsdoc [ -<!ENTITY % scons SYSTEM '../../../../doc/scons.mod'> -%scons; -<!ENTITY % builders-mod SYSTEM '../../../../doc/generated/builders.mod'> -%builders-mod; -<!ENTITY % functions-mod SYSTEM '../../../../doc/generated/functions.mod'> -%functions-mod; -<!ENTITY % tools-mod SYSTEM '../../../../doc/generated/tools.mod'> -%tools-mod; -<!ENTITY % variables-mod SYSTEM '../../../../doc/generated/variables.mod'> -%variables-mod; -]> + <!ENTITY % scons SYSTEM '../../../../doc/scons.mod'> + %scons; + <!ENTITY % builders-mod SYSTEM '../../../../doc/generated/builders.mod'> + %builders-mod; + <!ENTITY % functions-mod SYSTEM '../../../../doc/generated/functions.mod'> + %functions-mod; + <!ENTITY % tools-mod SYSTEM '../../../../doc/generated/tools.mod'> + %tools-mod; + <!ENTITY % variables-mod SYSTEM '../../../../doc/generated/variables.mod'> + %variables-mod; + ]> <sconsdoc xmlns="http://www.scons.org/dbxsd/v1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.scons.org/dbxsd/v1.0 http://www.scons.org/dbxsd/v1.0/scons.xsd"> -<tool name="javac"> -<summary> -<para> -Sets construction variables for the &javac; compiler. -</para> -</summary> -<sets> -<item>JAVAC</item> -<item>JAVACFLAGS</item> -<item>JAVACCOM</item> -<item>JAVACLASSSUFFIX</item> -<item>JAVASUFFIX</item> -<item>JAVABOOTCLASSPATH</item> -<item>JAVACLASSPATH</item> -<item>JAVASOURCEPATH</item> -</sets> -<uses> -<item>JAVACCOMSTR</item> -</uses> -</tool> + <tool name="javac"> + <summary> + <para> + Sets construction variables for the &javac; compiler. + </para> + </summary> + <sets> + <item>JAVAC</item> + <item>JAVACFLAGS</item> + <item>JAVACCOM</item> + <item>JAVACLASSSUFFIX</item> + <item>JAVAINCLUDES</item> + <item>JAVASUFFIX</item> + <item>JAVABOOTCLASSPATH</item> + <item>JAVACLASSPATH</item> + <item>JAVASOURCEPATH</item> + </sets> + <uses> + <item>JAVACCOMSTR</item> + </uses> + </tool> -<builder name="Java"> -<summary> -<para> -Builds one or more Java class files. -The sources may be any combination of explicit -<filename>.java</filename> files, -or directory trees which will be scanned -for <filename>.java</filename> files. -</para> + <builder name="Java"> + <summary> + <para> + Builds one or more Java class files. + The sources may be any combination of explicit + <filename>.java</filename> + files, + or directory trees which will be scanned + for <filename>.java</filename> files. + </para> -<para> -SCons will parse each source <filename>.java</filename> file -to find the classes -(including inner classes) -defined within that file, -and from that figure out the -target <filename>.class</filename> files that will be created. -The class files will be placed underneath -the specified target directory. -</para> + <para> + SCons will parse each source <filename>.java</filename> file + to find the classes + (including inner classes) + defined within that file, + and from that figure out the + target <filename>.class</filename> files that will be created. + The class files will be placed underneath + the specified target directory. + </para> -<para> -SCons will also search each Java file -for the Java package name, -which it assumes can be found on a line -beginning with the string -<literal>package</literal> -in the first column; -the resulting <filename>.class</filename> files -will be placed in a directory reflecting -the specified package name. -For example, -the file -<filename>Foo.java</filename> -defining a single public -<classname>Foo</classname> -class and -containing a package name of -<classname>sub.dir</classname> -will generate a corresponding -<filename>sub/dir/Foo.class</filename> -class file. -</para> + <para> + SCons will also search each Java file + for the Java package name, + which it assumes can be found on a line + beginning with the string + <literal>package</literal> + in the first column; + the resulting <filename>.class</filename> files + will be placed in a directory reflecting + the specified package name. + For example, + the file + <filename>Foo.java</filename> + defining a single public + <classname>Foo</classname> + class and + containing a package name of + <classname>sub.dir</classname> + will generate a corresponding + <filename>sub/dir/Foo.class</filename> + class file. + </para> -<para> -Examples: -</para> + <para> + Examples: + </para> -<example_commands> -env.Java(target = 'classes', source = 'src') -env.Java(target = 'classes', source = ['src1', 'src2']) -env.Java(target = 'classes', source = ['File1.java', 'File2.java']) -</example_commands> + <example_commands> + env.Java(target = 'classes', source = 'src') + env.Java(target = 'classes', source = ['src1', 'src2']) + env.Java(target = 'classes', source = ['File1.java', 'File2.java']) + </example_commands> -<para> -Java source files can use the native encoding for the underlying OS. -Since SCons compiles in simple ASCII mode by default, -the compiler will generate warnings about unmappable characters, -which may lead to errors as the file is processed further. -In this case, the user must specify the <literal>LANG</literal> -environment variable to tell the compiler what encoding is used. -For portibility, it's best if the encoding is hard-coded -so that the compile will work if it is done on a system -with a different encoding. -</para> + <para> + Java source files can use the native encoding for the underlying OS. + Since SCons compiles in simple ASCII mode by default, + the compiler will generate warnings about unmappable characters, + which may lead to errors as the file is processed further. + In this case, the user must specify the + <literal>LANG</literal> + environment variable to tell the compiler what encoding is used. + For portibility, it's best if the encoding is hard-coded + so that the compile will work if it is done on a system + with a different encoding. + </para> -<example_commands> -env = Environment() -env['ENV']['LANG'] = 'en_GB.UTF-8' -</example_commands> -</summary> -</builder> + <example_commands> + env = Environment() + env['ENV']['LANG'] = 'en_GB.UTF-8' + </example_commands> + </summary> + </builder> -<cvar name="JAVABOOTCLASSPATH"> -<summary> -<para> -Specifies the list of directories that -will be added to the -&javac; command line -via the <option>-bootclasspath</option> option. -The individual directory names will be -separated by the operating system's path separate character -(<filename>:</filename> on UNIX/Linux/POSIX, -<filename>;</filename> on Windows). -</para> -</summary> -</cvar> + <cvar name="JAVABOOTCLASSPATH"> + <summary> + <para> + Specifies the list of directories that + will be added to the + &javac; command line + via the <option>-bootclasspath</option> option. + The individual directory names will be + separated by the operating system's path separate character + (<filename>:</filename> on UNIX/Linux/POSIX, + <filename>;</filename> + on Windows). + </para> + </summary> + </cvar> -<cvar name="JAVAC"> -<summary> -<para> -The Java compiler. -</para> -</summary> -</cvar> + <cvar name="JAVAINCLUDES"> + <summary> + <para> + Include path for Java header files (such as jni.h) + </para> + </summary> + </cvar> -<cvar name="JAVACCOM"> -<summary> -<para> -The command line used to compile a directory tree containing -Java source files to -corresponding Java class files. -Any options specified in the &cv-link-JAVACFLAGS; construction variable -are included on this command line. -</para> -</summary> -</cvar> + <cvar name="JAVAC"> + <summary> + <para> + The Java compiler. + </para> + </summary> + </cvar> -<cvar name="JAVACCOMSTR"> -<summary> -<para> -The string displayed when compiling -a directory tree of Java source files to -corresponding Java class files. -If this is not set, then &cv-link-JAVACCOM; (the command line) is displayed. -</para> + <cvar name="JAVACCOM"> + <summary> + <para> + The command line used to compile a directory tree containing + Java source files to + corresponding Java class files. + Any options specified in the &cv-link-JAVACFLAGS; construction variable + are included on this command line. + </para> + </summary> + </cvar> -<example_commands> -env = Environment(JAVACCOMSTR = "Compiling class files $TARGETS from $SOURCES") -</example_commands> -</summary> -</cvar> + <cvar name="JAVACCOMSTR"> + <summary> + <para> + The string displayed when compiling + a directory tree of Java source files to + corresponding Java class files. + If this is not set, then &cv-link-JAVACCOM; (the command line) is displayed. + </para> -<cvar name="JAVACFLAGS"> -<summary> -<para> -General options that are passed to the Java compiler. -</para> -</summary> -</cvar> + <example_commands> + env = Environment(JAVACCOMSTR = "Compiling class files $TARGETS from $SOURCES") + </example_commands> + </summary> + </cvar> -<cvar name="JAVACLASSDIR"> -<summary> -<para> -The directory in which Java class files may be found. -This is stripped from the beginning of any Java .class -file names supplied to the -<literal>JavaH</literal> -builder. -</para> -</summary> -</cvar> + <cvar name="JAVACFLAGS"> + <summary> + <para> + General options that are passed to the Java compiler. + </para> + </summary> + </cvar> -<cvar name="JAVACLASSPATH"> -<summary> -<para> -Specifies the list of directories that -will be searched for Java -<filename>.class</filename> file. -The directories in this list will be added to the -&javac; and &javah; command lines -via the <option>-classpath</option> option. -The individual directory names will be -separated by the operating system's path separate character -(<filename>:</filename> on UNIX/Linux/POSIX, -<filename>;</filename> on Windows). -</para> + <cvar name="JAVACLASSDIR"> + <summary> + <para> + The directory in which Java class files may be found. + This is stripped from the beginning of any Java .class + file names supplied to the + <literal>JavaH</literal> + builder. + </para> + </summary> + </cvar> -<para> -Note that this currently just adds the specified -directory via the <option>-classpath</option> option. -&SCons; does not currently search the -&cv-JAVACLASSPATH; directories for dependency -<filename>.class</filename> files. -</para> -</summary> -</cvar> + <cvar name="JAVACLASSPATH"> + <summary> + <para> + Specifies the list of directories that + will be searched for Java + <filename>.class</filename> + file. + The directories in this list will be added to the + &javac; and &javah; command lines + via the <option>-classpath</option> option. + The individual directory names will be + separated by the operating system's path separate character + (<filename>:</filename> on UNIX/Linux/POSIX, + <filename>;</filename> + on Windows). + </para> -<cvar name="JAVACLASSSUFFIX"> -<summary> -<para> -The suffix for Java class files; -<filename>.class</filename> -by default. -</para> -</summary> -</cvar> + <para> + Note that this currently just adds the specified + directory via the <option>-classpath</option> option. + &SCons; does not currently search the + &cv-JAVACLASSPATH; directories for dependency + <filename>.class</filename> + files. + </para> + </summary> + </cvar> -<cvar name="JAVASOURCEPATH"> -<summary> -<para> -Specifies the list of directories that -will be searched for input -<filename>.java</filename> file. -The directories in this list will be added to the -&javac; command line -via the <option>-sourcepath</option> option. -The individual directory names will be -separated by the operating system's path separate character -(<filename>:</filename> on UNIX/Linux/POSIX, -<filename>;</filename> on Windows). -</para> + <cvar name="JAVACLASSSUFFIX"> + <summary> + <para> + The suffix for Java class files; + <filename>.class</filename> + by default. + </para> + </summary> + </cvar> -<para> -Note that this currently just adds the specified -directory via the <option>-sourcepath</option> option. -&SCons; does not currently search the -&cv-JAVASOURCEPATH; directories for dependency -<filename>.java</filename> files. -</para> -</summary> -</cvar> + <cvar name="JAVASOURCEPATH"> + <summary> + <para> + Specifies the list of directories that + will be searched for input + <filename>.java</filename> + file. + The directories in this list will be added to the + &javac; command line + via the <option>-sourcepath</option> option. + The individual directory names will be + separated by the operating system's path separate character + (<filename>:</filename> on UNIX/Linux/POSIX, + <filename>;</filename> + on Windows). + </para> -<cvar name="JAVASUFFIX"> -<summary> -<para> -The suffix for Java files; -<filename>.java</filename> -by default. -</para> -</summary> -</cvar> + <para> + Note that this currently just adds the specified + directory via the <option>-sourcepath</option> option. + &SCons; does not currently search the + &cv-JAVASOURCEPATH; directories for dependency + <filename>.java</filename> + files. + </para> + </summary> + </cvar> -<cvar name="JAVAVERSION"> -<summary> -<para> -Specifies the Java version being used by the &b-Java; builder. -This is <emphasis>not</emphasis> currently used to select one -version of the Java compiler vs. another. -Instead, you should set this to specify the version of Java -supported by your &javac; compiler. -The default is <literal>1.4</literal>. -</para> + <cvar name="JAVASUFFIX"> + <summary> + <para> + The suffix for Java files; + <filename>.java</filename> + by default. + </para> + </summary> + </cvar> -<para> -This is sometimes necessary because -Java 1.5 changed the file names that are created -for nested anonymous inner classes, -which can cause a mismatch with the files -that &SCons; expects will be generated by the &javac; compiler. -Setting &cv-JAVAVERSION; to <literal>1.5</literal> -(or <literal>1.6</literal>, as appropriate) -can make &SCons; realize that a Java 1.5 or 1.6 -build is actually up to date. -</para> -</summary> -</cvar> + <cvar name="JAVAVERSION"> + <summary> + <para> + Specifies the Java version being used by the &b-Java; builder. + This is <emphasis>not</emphasis> currently used to select one + version of the Java compiler vs. another. + Instead, you should set this to specify the version of Java + supported by your &javac; compiler. + The default is <literal>1.4</literal>. + </para> + + <para> + This is sometimes necessary because + Java 1.5 changed the file names that are created + for nested anonymous inner classes, + which can cause a mismatch with the files + that &SCons; expects will be generated by the &javac; compiler. + Setting &cv-JAVAVERSION; to + <literal>1.5</literal> + (or <literal>1.6</literal>, as appropriate) + can make &SCons; realize that a Java 1.5 or 1.6 + build is actually up to date. + </para> + </summary> + </cvar> </sconsdoc> diff --git a/src/engine/SCons/Tool/javah.py b/src/engine/SCons/Tool/javah.py index c092273..f514479 100644 --- a/src/engine/SCons/Tool/javah.py +++ b/src/engine/SCons/Tool/javah.py @@ -40,6 +40,8 @@ import SCons.Builder import SCons.Node.FS import SCons.Tool.javac import SCons.Util +from SCons.Tool.JavaCommon import get_java_install_dirs + def emit_java_headers(target, source, env): """Create and return lists of Java stub header files that will @@ -120,6 +122,14 @@ def generate(env): java_javah = SCons.Tool.CreateJavaHBuilder(env) java_javah.emitter = emit_java_headers + if env['PLATFORM'] == 'win32': + # Ensure that we have a proper path for clang + javah = SCons.Tool.find_program_path(env, 'javah', + default_paths=get_java_install_dirs(env['PLATFORM'])) + if javah: + javah_bin_dir = os.path.dirname(javah) + env.AppendENVPath('PATH', javah_bin_dir) + env['_JAVAHOUTFLAG'] = JavaHOutFlagGenerator env['JAVAH'] = 'javah' env['JAVAHFLAGS'] = SCons.Util.CLVar('') diff --git a/src/engine/SCons/Tool/rmic.py b/src/engine/SCons/Tool/rmic.py index 4d1bd28..173ef5f 100644 --- a/src/engine/SCons/Tool/rmic.py +++ b/src/engine/SCons/Tool/rmic.py @@ -40,6 +40,9 @@ import SCons.Builder import SCons.Node.FS import SCons.Util +from SCons.Tool.JavaCommon import get_java_install_dirs + + def emit_rmic_classes(target, source, env): """Create and return lists of Java RMI stub and skeleton class files to be created from a set of class files. @@ -105,6 +108,18 @@ def generate(env): """Add Builders and construction variables for rmic to an Environment.""" env['BUILDERS']['RMIC'] = RMICBuilder + if env['PLATFORM'] == 'win32': + version = env.get('JAVAVERSION', None) + default_paths=get_java_install_dirs(env['PLATFORM'], version=version) + + # Ensure that we have a proper path for rmic + rmic = SCons.Tool.find_program_path(env, 'rmic', default_paths=default_paths) + + # print("RMIC: %s"%rmic) + if rmic: + rmic_bin_dir = os.path.dirname(rmic) + env.AppendENVPath('PATH', rmic_bin_dir) + env['RMIC'] = 'rmic' env['RMICFLAGS'] = SCons.Util.CLVar('') env['RMICCOM'] = '$RMIC $RMICFLAGS -d ${TARGET.attributes.java_lookupdir} -classpath ${SOURCE.attributes.java_classdir} ${SOURCES.attributes.java_classname}' |