From 2180ff6d0388162586fff59e066bc1e3e4bb9600 Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Sun, 26 Aug 2018 22:54:00 -0600 Subject: Stop using custom OrderedDict OrdredDict is in the standard library for all supported Python versions (2.7 and 3.5+) and has improvements over the ActiveState recipe version of OrderedDict we have been using. Switch to importing from collections instead of getting it from SCons.Util (tests already did this). At the same time, reorganize the Util.py imports - import Iterable from collections.abc if possible (it is deprecated to import it from collections, will stop working in 3.8); try getting the User{Dict,List,String} from collections if possible - that is, try the 3.x way first. Signed-off-by: Mats Wichmann --- src/engine/SCons/Action.py | 3 +- src/engine/SCons/Tool/javac.py | 3 +- src/engine/SCons/Util.py | 74 +++++------------------------------------- 3 files changed, 13 insertions(+), 67 deletions(-) diff --git a/src/engine/SCons/Action.py b/src/engine/SCons/Action.py index 44ddacd..9a3888b 100644 --- a/src/engine/SCons/Action.py +++ b/src/engine/SCons/Action.py @@ -107,6 +107,7 @@ import sys import subprocess import itertools import inspect +from collections import OrderedDict import SCons.Debug from SCons.Debug import logInstanceCreation @@ -1294,7 +1295,7 @@ class ListAction(ActionBase): return result def get_varlist(self, target, source, env, executor=None): - result = SCons.Util.OrderedDict() + result = OrderedDict() for act in self.list: for var in act.get_varlist(target, source, env, executor): result[var] = True diff --git a/src/engine/SCons/Tool/javac.py b/src/engine/SCons/Tool/javac.py index b26c0b3..72c48f7 100644 --- a/src/engine/SCons/Tool/javac.py +++ b/src/engine/SCons/Tool/javac.py @@ -34,6 +34,7 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os import os.path +from collections import OrderedDict import SCons.Action import SCons.Builder @@ -70,7 +71,7 @@ def emit_java_classes(target, source, env): if isinstance(entry, SCons.Node.FS.File): slist.append(entry) elif isinstance(entry, SCons.Node.FS.Dir): - result = SCons.Util.OrderedDict() + result = OrderedDict() dirnode = entry.rdir() def find_java_files(arg, dirpath, filenames): java_files = sorted([n for n in filenames diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index 52f42d2..f691cd9 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -37,21 +37,18 @@ import pprint PY3 = sys.version_info[0] == 3 try: + from collections import UserDict, UserList, UserString +except ImportError: from UserDict import UserDict -except ImportError as e: - from collections import UserDict - -try: from UserList import UserList -except ImportError as e: - from collections import UserList - -from collections import Iterable + from UserString import UserString try: - from UserString import UserString -except ImportError as e: - from collections import UserString + from collections.abc import Iterable +except ImportError: + from collections import Iterable + +from collections import OrderedDict # Don't "from types import ..." these because we need to get at the # types module later to look for UnicodeType. @@ -63,7 +60,7 @@ MethodType = types.MethodType FunctionType = types.FunctionType try: - unicode + _ = type(unicode) except NameError: UnicodeType = str else: @@ -1032,59 +1029,6 @@ class CLVar(UserList): def __str__(self): return ' '.join(self.data) -# A dictionary that preserves the order in which items are added. -# Submitted by David Benjamin to ActiveState's Python Cookbook web site: -# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/107747 -# Including fixes/enhancements from the follow-on discussions. -class OrderedDict(UserDict): - def __init__(self, dict = None): - self._keys = [] - UserDict.__init__(self, dict) - - def __delitem__(self, key): - UserDict.__delitem__(self, key) - self._keys.remove(key) - - def __setitem__(self, key, item): - UserDict.__setitem__(self, key, item) - if key not in self._keys: self._keys.append(key) - - def clear(self): - UserDict.clear(self) - self._keys = [] - - def copy(self): - dict = OrderedDict() - dict.update(self) - return dict - - def items(self): - return list(zip(self._keys, list(self.values()))) - - def keys(self): - return self._keys[:] - - def popitem(self): - try: - key = self._keys[-1] - except IndexError: - raise KeyError('dictionary is empty') - - val = self[key] - del self[key] - - return (key, val) - - def setdefault(self, key, failobj = None): - UserDict.setdefault(self, key, failobj) - if key not in self._keys: self._keys.append(key) - - def update(self, dict): - for (key, val) in dict.items(): - self.__setitem__(key, val) - - def values(self): - return list(map(self.get, self._keys)) class Selector(OrderedDict): """A callable ordered dictionary that maps file suffixes to -- cgit v0.12 From 4edd05726a8fad7f192e486a9539c44ea012cd94 Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Thu, 6 Sep 2018 12:17:56 -0600 Subject: Update CHANGES.txt for OrderedDict change Signed-off-by: Mats Wichmann --- src/CHANGES.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 95680dd..6f873b0 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -128,6 +128,7 @@ RELEASE 3.1.0.alpha.yyyymmdd - NEW DATE WILL BE INSERTED HERE time.clock deprecated since py3.3, due to remove in 3.8. deprecation warnings from py3.7 were failing a bunch of tests on Windows since they mess up expected stderr. + - Remove obsoleted internal implementaiton of OrderedDict. From Hao Wu - typo in customized decider example in user guide -- cgit v0.12 From bbde3d2bbf2a7e34d369c5be069fde2d5e235670 Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Fri, 7 Sep 2018 07:37:58 -0600 Subject: Improvements to tarball packager Both gz and bzip2 now skip the test if tar is not found (previously they would not test, but mark the test OK). Since tar is now found on recent Windows 10, but the helper program bzip2 is not, check for bzip2 as well. This is actually a correct test for other systems as well, they have just been very unlikely to not have had bzip2 provisioned so it has not bitten us. Note: on Windows, with cygwin installed, the test may well find bzip2 but c:\Windows\System32\tar.exe does not find it and the test fails anyway. Work needed on this "finds too much" issue (not unique to this test). Signed-off-by: Mats Wichmann --- src/CHANGES.txt | 5 ++++- test/packaging/tar/bz2_packaging.py | 17 +++++++++++------ test/packaging/tar/gz.py | 13 +++++++------ 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 6f7e851..6fa9649 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -129,13 +129,16 @@ RELEASE 3.1.0.alpha.yyyymmdd - NEW DATE WILL BE INSERTED HERE - Document and comment cleanup. - Added new Environment Value X_RPM_EXTRADEFS to supply custom settings to the specfile without adding specific logic for each one to scons. - - One swig test now checks for Python.h instead of failing + - The test for Python.h needed by swig tests is moved to get_python_platform + so it does not have to be repeated in every test; picks up one failure + which did not make the (previously needed) check. - If test opens os.devnull, register with atexit so file opens do not leak. - Fix bugs in Win32 process spawn logic to handle OSError exception correctly. - Use time.perf_counter instead of time.clock if it exists. time.clock deprecated since py3.3, due to remove in 3.8. deprecation warnings from py3.7 were failing a bunch of tests on Windows since they mess up expected stderr. + - tar packaging test fixups From Hao Wu - typo in customized decider example in user guide diff --git a/test/packaging/tar/bz2_packaging.py b/test/packaging/tar/bz2_packaging.py index 1552fd1..2a8b506 100644 --- a/test/packaging/tar/bz2_packaging.py +++ b/test/packaging/tar/bz2_packaging.py @@ -36,18 +36,23 @@ python = TestSCons.python test = TestSCons.TestSCons() tar = test.detect('TAR', 'tar') +if not tar: + test.skip_test('tar not found, skipping test\n') -if tar: - test.subdir('src') +bz2 = test.where_is('bzip2') +if not bz2: + test.skip_test('tar found, but helper bzip2 not found, skipping test\n') - test.write( [ 'src', 'main.c' ], r""" +test.subdir('src') + +test.write([ 'src', 'main.c'], r""" int main( int argc, char* argv[] ) { return 0; } """) - test.write('SConstruct', """ +test.write('SConstruct', """ Program( 'src/main.c' ) env=Environment(tools=['default', 'packaging']) env.Package( PACKAGETYPE = 'src_tarbz2', @@ -56,9 +61,9 @@ env.Package( PACKAGETYPE = 'src_tarbz2', source = [ 'src/main.c', 'SConstruct' ] ) """) - test.run(arguments='', stderr = None) +test.run(arguments='', stderr=None) - test.must_exist( 'src.tar.bz2' ) +test.must_exist('src.tar.bz2') test.pass_test() diff --git a/test/packaging/tar/gz.py b/test/packaging/tar/gz.py index f841c59..05661b7 100644 --- a/test/packaging/tar/gz.py +++ b/test/packaging/tar/gz.py @@ -36,18 +36,19 @@ python = TestSCons.python test = TestSCons.TestSCons() tar = test.detect('TAR', 'tar') +if not tar: + test.skip_test('tar not found, skipping test\n') -if tar: - test.subdir('src') +test.subdir('src') - test.write( [ 'src', 'main.c' ], r""" +test.write(['src', 'main.c'], r""" int main( int argc, char* argv[] ) { return 0; } """) - test.write('SConstruct', """ +test.write('SConstruct', """ Program( 'src/main.c' ) env=Environment(tools=['default', 'packaging']) env.Package( PACKAGETYPE = 'src_targz', @@ -56,9 +57,9 @@ env.Package( PACKAGETYPE = 'src_targz', source = [ 'src/main.c', 'SConstruct' ] ) """) - test.run(arguments='', stderr = None) +test.run(arguments='', stderr=None) - test.must_exist( 'src.tar.gz' ) +test.must_exist('src.tar.gz') test.pass_test() -- cgit v0.12 From fe27baf677366633c9ec64f2f7b22cb4063adc28 Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Tue, 11 Sep 2018 07:24:41 -0600 Subject: Add java 11 jdk 11.0 is almost at GA, and it will be the first edition designated as Long Term Support (LTS), with commercial support until Sept 2023, so we might as well add support to scons. Going forward, is it worth continuing to check for individual versions as being "supported"? Signed-off-by: Mats Wichmann --- src/CHANGES.txt | 2 +- src/engine/SCons/Tool/JavaCommon.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 6f7e851..353d5ab 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -101,7 +101,7 @@ RELEASE 3.1.0.alpha.yyyymmdd - NEW DATE WILL BE INSERTED HERE This changes SCons to better comply with normal Python installation practices. From Mats Wichmann: - - Recognize new java 9, 10 (as 9.0 and 10.0) + - Recognize new java 9, 10, 11 (as 9.0 and 10.0, 11.0) - Updated manpage scons.xml to fix a nested list problem - Updated doc terminiology: use prepend instead of append as appropriate - XML validity fixes from SConstruct.py change diff --git a/src/engine/SCons/Tool/JavaCommon.py b/src/engine/SCons/Tool/JavaCommon.py index 8349164..e90e768 100644 --- a/src/engine/SCons/Tool/JavaCommon.py +++ b/src/engine/SCons/Tool/JavaCommon.py @@ -69,7 +69,7 @@ if java_parsing: def __init__(self, version=default_java_version): if not version in ('1.1', '1.2', '1.3', '1.4', '1.5', '1.6', '1.7', - '1.8', '5', '6', '9.0', '10.0'): + '1.8', '5', '6', '9.0', '10.0', '11.0'): msg = "Java version %s not supported" % version raise NotImplementedError(msg) @@ -177,7 +177,7 @@ if java_parsing: if self.version in ('1.1', '1.2', '1.3', '1.4'): clazz = self.listClasses[0] self.listOutputs.append('%s$%d' % (clazz, self.nextAnon)) - elif self.version in ('1.5', '1.6', '1.7', '1.8', '5', '6', '9.0', '10.0'): + elif self.version in ('1.5', '1.6', '1.7', '1.8', '5', '6', '9.0', '10.0', '11.0'): self.stackAnonClassBrackets.append(self.brackets) className = [] className.extend(self.listClasses) -- cgit v0.12 From b71404ff2d256460f23c4494932af2ea61d1a271 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Thu, 20 Sep 2018 22:35:51 -0400 Subject: Fix test/Execute.py failing on windows with python 2.7.15. It worked fine with python 2.7.14 and below. The output message changed from / to \ and broke the test. --- test/Execute.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/Execute.py b/test/Execute.py index edd746e..c40d0d0 100644 --- a/test/Execute.py +++ b/test/Execute.py @@ -27,7 +27,7 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ Test the Execute() function for executing actions directly. """ - +import sys import TestSCons _python_ = TestSCons._python_ @@ -82,11 +82,12 @@ test.write('k.in', "k.in\n") test.write('l.in', "l.in\n") test.write('m.in', "m.in\n") -import sys if sys.platform == 'win32' and sys.version_info[0] == 2: + # note that nonexistent.in will have a \ on windows with python < 2.7.15 + # and a / on >= 2.7.15 (The third line below) expect = r"""scons: \*\*\* Error 1 scons: \*\*\* Error 2 -scons: \*\*\* nonexistent.in/\*\.\*: (The system cannot find the path specified|Das System kann den angegebenen Pfad nicht finden)""" +scons: \*\*\* nonexistent.in(/|\\)\*\.\*: (The system cannot find the path specified|Das System kann den angegebenen Pfad nicht finden)""" elif sys.platform == 'win32' and sys.version_info[0] == 3: expect = r"""scons: \*\*\* Error 1 scons: \*\*\* Error 2 -- cgit v0.12