From 984e3f58b9f2c33cc551e2a3d2962c5f6420b3c8 Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Tue, 18 Oct 2022 11:33:36 -0600 Subject: Java scanner: fixes per review comments Signed-off-by: Mats Wichmann --- RELEASE.txt | 13 +++++++++---- SCons/Scanner/Java.py | 10 +++++++++- SCons/Tool/javac.xml | 27 ++++++++++++++------------- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/RELEASE.txt b/RELEASE.txt index a8541e6..8bdbe43 100644 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -43,10 +43,15 @@ FIXES - A list argument as the source to the Copy() action function is now handled. Both the implementation and the strfunction which prints the progress message were adjusted. -- The Java scanner processing of JAVACLASSPATH for dependencies (introduced - in 4.4.0) is adjusted to split on the system's search path separator - instead of on space - the latter disallowed passing a completed search - string as a scalar value, and broke on paths with embedded spaces. +- The Java Scanner processing of JAVACLASSPATH for dependencies (behavior + that was introduced in SCons 4.4.0) is adjusted to split on the system's + search path separator instead of on a space. The previous behavior meant + that a path containing spaces (e.g. r"C:\somepath\My Classes") would + lead to unexpected errors. If the split-on-space behavior is desired, + pre-split the value: instead of: env["JAVACLASSPATH"] = "foo bar baz" + use: env["JAVACLASSPATH"] = env.Split("foo bar baz") + There is no change in how JAVACLASSPATH gets turned into the -classpath + argument passed to the JDK tools. IMPROVEMENTS ------------ diff --git a/SCons/Scanner/Java.py b/SCons/Scanner/Java.py index 0c6df37..f6edf93 100644 --- a/SCons/Scanner/Java.py +++ b/SCons/Scanner/Java.py @@ -33,7 +33,7 @@ def _subst_paths(env, paths) -> list: """Return a list of substituted path elements. If *paths* is a string, it is split on the search-path separator - (this makes the interpretation system-specitic - this is warned about + (this makes the interpretation system-specific - this is warned about in the manpage). This helps support behavior like pulling in the external ``CLASSPATH`` and setting it directly into ``JAVACLASSPATH``. Otherwise, substitution is done on string-valued list elements @@ -44,6 +44,7 @@ def _subst_paths(env, paths) -> list: if SCons.Util.is_String(paths): paths = paths.split(os.pathsep) else: + # TODO: may want to revisit splitting list-element strings if requested paths = flatten(paths) paths = [env.subst(path) if is_String(path) else path for path in paths] return paths @@ -73,6 +74,9 @@ def scan(node, env, libpath=()) -> list: result = [] for path in classpath: if is_String(path) and "*" in path: + # This matches more than the Java docs describe: a '*' only + # matches jar files. The filter later should trim this down. + # TODO: should we filter here? use .endswith('*') rather than "in"? libs = env.Glob(path) else: libs = [path] @@ -91,6 +95,10 @@ def scan(node, env, libpath=()) -> list: def JavaScanner(): + """Scanner for .java files. + + .. versionadded:: 4.4 + """ return SCons.Scanner.Base(scan, 'JavaScanner', skeys=['.java']) # Local Variables: diff --git a/SCons/Tool/javac.xml b/SCons/Tool/javac.xml index 922ae2b..014d905 100644 --- a/SCons/Tool/javac.xml +++ b/SCons/Tool/javac.xml @@ -140,10 +140,10 @@ env['ENV']['LANG'] = 'en_GB.UTF-8' search path separator characters (: for POSIX systems or ; for Windows), it will not be modified; + and so is inherently system-specific; to supply the path in a system-independent manner, give &cv-JAVABOOTCLASSPATH; as a list of paths instead. - Can only be used when compiling for releases prior to JDK 9. @@ -239,12 +239,13 @@ env = Environment(JAVACCOMSTR="Compiling class files $TARGETS from $SOURCES") If &cv-JAVACLASSPATH; is a single string containing search path separator characters (: for POSIX systems or - ; for Windows), it will not be modified; + ; for Windows), + it will be split on the separator into a list of individual + paths for dependency scanning purposes. + It will not be modified for JDK command-line usage, + so such a string is inherently system-specific; to supply the path in a system-independent manner, give &cv-JAVACLASSPATH; as a list of paths instead. - Such a string will, however, - be split on the separator into a list of individual paths - for dependency scanning purposes. @@ -289,24 +290,24 @@ env = Environment(JAVACCOMSTR="Compiling class files $TARGETS from $SOURCES") The value will be added to the JDK command lines - via the option. - The JDK option requires a - system-specific search path separator, - which will be supplied by &SCons; as needed when it + via the option, + which requires a system-specific search path separator, + This will be supplied by &SCons; as needed when it constructs the command line if &cv-JAVASOURCEPATH; is provided in list form. If &cv-JAVASOURCEPATH; is a single string containing search path separator characters (: for POSIX systems or - ; for Windows), it will not be modified; + ; for Windows), it will not be modified, + and so is inherently system-specific; to supply the path in a system-independent manner, give &cv-JAVASOURCEPATH; as a list of paths instead. - Note that this currently just adds the specified - directories via the option. + Note that the specified directories are only added to + the command line via the option. &SCons; does not currently search the - &cv-JAVASOURCEPATH; directories for dependency + &cv-JAVASOURCEPATH; directories for dependent .java files. -- cgit v0.12