Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
arguments would yield an exception. This issue was found via qt4 and qt5 tools in
scons-contrib https://github.com/SCons/scons-contrib/issues/45


From David H:
- Add JavaScanner to include JAVACLASSPATH as a dependency when using the Java tool.
- Fix incorrect Java classpath generation when a NodeList is used as part of any JAVA*PATH variables.

From Daniel Moody:
- Add cache-debug messages for push failures.
Expand Down Expand Up @@ -296,7 +298,7 @@ RELEASE 4.2.0 - Sat, 31 Jul 2021 18:12:46 -0700
- Fix Issue #3906 - `IMPLICIT_COMMAND_DEPENDENCIES` was not properly disabled when
set to any string value (For example ['none','false','no','off'])
Also previously 'All' wouldn't have the desired affect.

From Ivan Kravets:
- Provide a custom argument escape function for `TempFileMunge` using a new
`TEMPFILEARGESCFUNC` variable. Useful if you need to apply extra operations on
Expand Down
2 changes: 2 additions & 0 deletions RELEASE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ CHANGED/ENHANCED EXISTING FUNCTIONALITY
output format written to stdout to include more information about the source for each
message of MSVC initialization debugging output. A single space was added before the
message for all debugging output records written to stdout and to files.
- Add JavaScanner to include JAVACLASSPATH as a dependency when using the Java tool.
- The build argument (i.e., x86) is no longer passed to the MSVC 6.0 to 7.1 batch
files. This may improve the effectiveness of the internal msvc cache when using
MSVC detection and when bypassing MSVC detection as the MSVC 6.0 to 7.1 batch files
Expand Down Expand Up @@ -121,6 +122,7 @@ FIXES
that link has been modified (issue #3880)
- Fix typo in ninja scons daemon startup which causes ConnectionRefusedError to not retry
to connect to the server during start up.
- Fix incorrect Java classpath generation when a NodeList is used as part of any JAVA*PATH variables.
- The system environment variable names imported for MSVC 7.0 and 6.0 were updated to be
consistent with the variables names defined by their respective installers. This fixes an
error caused when bypassing MSVC detection by specifying the MSVC 7.0 batch file directly.
Expand Down
99 changes: 99 additions & 0 deletions SCons/Scanner/Java.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# MIT License
#
# Copyright The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import os

import SCons.Node
import SCons.Node.FS
import SCons.Scanner
import SCons.Util


def _subst_libs(env, libs):
"""
Substitute environment variables and split into list.
"""
if SCons.Util.is_String(libs):
libs = env.subst(libs)
if SCons.Util.is_String(libs):
libs = libs.split()
elif SCons.Util.is_Sequence(libs):
_libs = []
for lib in libs:
_libs += _subst_libs(env, lib)
libs = _libs
else:
# libs is an object (Node, for example)
libs = [libs]
return libs


def _collect_classes(list, dirname, files):
for fname in files:
if os.path.splitext(fname)[1] == ".class":
list.append(os.path.join(str(dirname), fname))


def scan(node, env, libpath=()):
"""Scan for files on the JAVACLASSPATH.

The classpath can contain:
- Explicit paths to JAR/Zip files
- Wildcards (*)
- Directories which contain classes in an unnamed package
- Parent directories of the root package for classes in a named package

Class path entries that are neither directories nor archives (.zip or JAR files) nor the asterisk (*) wildcard character are ignored.
"""
classpath = env.get('JAVACLASSPATH', [])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might work for JAVABOOTCLASSPATH now

classpath = _subst_libs(env, classpath)

result = []
for path in classpath:
if SCons.Util.is_String(path) and "*" in path:
libs = env.Glob(path)
else:
libs = [path]

for lib in libs:
if os.path.isdir(str(lib)):
# grab the in-memory nodes
env.Dir(lib).walk(_collect_classes, result)
# now the on-disk ones
for root, dirs, files in os.walk(str(lib)):
_collect_classes(result, root, files)
else:
result.append(lib)

return list(filter(lambda x: os.path.splitext(str(x))[1] in [".class", ".zip", ".jar"], result))


def JavaScanner():
return SCons.Scanner.Base(scan, 'JavaScanner',
skeys=['.java'])

# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4:
160 changes: 160 additions & 0 deletions SCons/Scanner/JavaTests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# MIT License
#
# Copyright The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import unittest
import collections
import os

import TestCmd

import SCons.Scanner.Java
import SCons.Node.FS
import SCons.Warnings


test = TestCmd.TestCmd(workdir = '')
test.subdir('com')

files = [
'bootclasspath.jar',
'classpath.jar',
'Test.class',
'com/Test.class'
]

for fname in files:
test.write(fname, "\n")


class DummyEnvironment(collections.UserDict):
def __init__(self,**kw):
collections.UserDict.__init__(self)
self.data.update(kw)
self.fs = SCons.Node.FS.FS(test.workpath(''))
self['ENV'] = {}

def Dictionary(self, *args):
return self.data

def subst(self, strSubst, target=None, source=None, conv=None):
if strSubst[0] == '$':
return self.data[strSubst[1:]]
return strSubst

def subst_path(self, path, target=None, source=None, conv=None):
if not isinstance(path, list):
path = [path]
return list(map(self.subst, path))

def has_key(self, key):
return key in self.Dictionary()

def get_calculator(self):
return None

def get_factory(self, factory):
return factory or self.fs.File

def Dir(self, filename):
return self.fs.Dir(filename)

def File(self, filename):
return self.fs.File(filename)

def Glob(self, path):
return self.fs.Glob(path)


class DummyNode:
def __init__(self, name):
self.name = name

def rexists(self):
return 1

def __str__(self):
return self.name


global my_normpath
my_normpath = os.path.normpath

if os.path.normcase('foo') == os.path.normcase('FOO'):
my_normpath = os.path.normcase

def deps_match(self, deps, headers):
scanned = sorted(map(my_normpath, list(map(str, deps))))
expect = sorted(map(my_normpath, headers))
self.assertTrue(scanned == expect, "expect %s != scanned %s" % (expect, scanned))


class JavaScannerEmptyClasspath(unittest.TestCase):
def runTest(self):
path = []
env = DummyEnvironment(JAVASUFFIXES=['.java'],
JAVACLASSPATH=path)
s = SCons.Scanner.Java.JavaScanner()
deps = s(DummyNode('dummy'), env)
expected = []
deps_match(self, deps, expected)


class JavaScannerClasspath(unittest.TestCase):
def runTest(self):
env = DummyEnvironment(JAVASUFFIXES=['.java'],
JAVACLASSPATH=[test.workpath('classpath.jar')])
s = SCons.Scanner.Java.JavaScanner()
deps = s(DummyNode('dummy'), env)
expected = ['classpath.jar']
deps_match(self, deps, expected)


class JavaScannerWildcardClasspath(unittest.TestCase):
def runTest(self):
env = DummyEnvironment(JAVASUFFIXES=['.java'],
JAVACLASSPATH=[test.workpath('*')])
s = SCons.Scanner.Java.JavaScanner()
deps = s(DummyNode('dummy'), env)
expected = ['bootclasspath.jar', 'classpath.jar', 'Test.class']
deps_match(self, deps, expected)


class JavaScannerDirClasspath(unittest.TestCase):
def runTest(self):
env = DummyEnvironment(JAVASUFFIXES=['.java'],
JAVACLASSPATH=[test.workpath()])
s = SCons.Scanner.Java.JavaScanner()
deps = s(DummyNode('dummy'), env)
expected = ['Test.class', 'com/Test.class']
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if this should pick up jars too

deps_match(self, deps, expected)



if __name__ == "__main__":
unittest.main()

# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4:
8 changes: 6 additions & 2 deletions SCons/Tool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import SCons.Scanner
import SCons.Scanner.C
import SCons.Scanner.D
import SCons.Scanner.Java
import SCons.Scanner.LaTeX
import SCons.Scanner.Prog
import SCons.Scanner.SWIG
Expand All @@ -57,6 +58,7 @@

CScanner = SCons.Scanner.C.CScanner()
DScanner = SCons.Scanner.D.DScanner()
JavaScanner = SCons.Scanner.Java.JavaScanner()
LaTeXScanner = SCons.Scanner.LaTeX.LaTeXScanner()
PDFLaTeXScanner = SCons.Scanner.LaTeX.PDFLaTeXScanner()
ProgramScanner = SCons.Scanner.Prog.ProgramScanner()
Expand Down Expand Up @@ -521,7 +523,8 @@ def CreateJavaClassFileBuilder(env):
src_suffix='$JAVASUFFIX',
src_builder=['JavaFile'],
target_factory=fs.Entry,
source_factory=fs.File)
source_factory=fs.File,
target_scanner=JavaScanner)
env['BUILDERS']['JavaClassFile'] = java_class_file
return java_class_file

Expand All @@ -535,7 +538,8 @@ def CreateJavaClassDirBuilder(env):
java_class_dir = SCons.Builder.Builder(action=javac_com,
emitter={},
target_factory=fs.Dir,
source_factory=fs.Dir)
source_factory=fs.Dir,
target_scanner=JavaScanner)
env['BUILDERS']['JavaClassDir'] = java_class_dir
return java_class_dir

Expand Down
1 change: 1 addition & 0 deletions SCons/Tool/javac.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def __call__(self, target, source, env, for_signature):
default = [default]
path = path + default
if path:
path = SCons.Util.flatten(path)
return [self.opt, os.pathsep.join(map(str, path))]
else:
return []
Expand Down
9 changes: 0 additions & 9 deletions SCons/Tool/javac.xml
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,6 @@ env = Environment(JAVACCOMSTR="Compiling class files $TARGETS from $SOURCES")
<filename>;</filename>
on Windows).
</para>

<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>

Expand Down
5 changes: 5 additions & 0 deletions SCons/Tool/javacTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ def test_default_unset(self):
['-foopath', '/foo'],
'/foo',
'')

def test_list_within_list(self):
self.assert_pathopt(['-foopath', os.pathsep.join(['/foo','/bar'])],
['/foo', ['/bar']])


if __name__ == "__main__":
unittest.main()