From 6d36db01745c45b107ccaaf57b2768ae3a6b83bd Mon Sep 17 00:00:00 2001 From: Evan Driscoll Date: Wed, 5 Jul 2017 21:39:41 -0500 Subject: Make sure more file objects are explicitly closed --- src/engine/SCons/Debug.py | 4 +++- src/engine/SCons/Tool/linkloc.py | 4 ++-- src/engine/SCons/Util.py | 5 ++--- src/engine/SCons/Variables/__init__.py | 4 +++- src/engine/SCons/cpp.py | 3 ++- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/engine/SCons/Debug.py b/src/engine/SCons/Debug.py index 9e520ff..706b4c4 100644 --- a/src/engine/SCons/Debug.py +++ b/src/engine/SCons/Debug.py @@ -97,7 +97,8 @@ def dumpLoggedInstances(classes, file=sys.stdout): if sys.platform[:5] == "linux": # Linux doesn't actually support memory usage stats from getrusage(). def memory(): - mstr = open('/proc/self/stat').read() + with open('/proc/self/stat') as f: + mstr = f.read() mstr = mstr.split()[22] return int(mstr) elif sys.platform[:6] == 'darwin': @@ -233,6 +234,7 @@ def Trace(msg, file=None, mode='w', tstamp=None): PreviousTime = now fp.write(msg) fp.flush() + fp.close() # Local Variables: # tab-width:4 diff --git a/src/engine/SCons/Tool/linkloc.py b/src/engine/SCons/Tool/linkloc.py index bd643f7..c73852b 100644 --- a/src/engine/SCons/Tool/linkloc.py +++ b/src/engine/SCons/Tool/linkloc.py @@ -52,8 +52,8 @@ def repl_linker_command(m): # Replaces any linker command file directives (e.g. "@foo.lnk") with # the actual contents of the file. try: - f=open(m.group(2), "r") - return m.group(1) + f.read() + with open(m.group(2), "r") as f: + return m.group(1) + f.read() except IOError: # the linker should return an error if it can't # find the linker command file so we will remain quiet. diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index 4d0df22..846d06c 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -1506,9 +1506,8 @@ def MD5signature(s): def MD5filesignature(fname, chunksize=65536): - f = open(fname, "rb") - result = f.read() - f.close() + with open(fname, "rb") as f: + result = f.read() return result try: diff --git a/src/engine/SCons/Variables/__init__.py b/src/engine/SCons/Variables/__init__.py index cd66604..1fe4435 100644 --- a/src/engine/SCons/Variables/__init__.py +++ b/src/engine/SCons/Variables/__init__.py @@ -175,7 +175,9 @@ class Variables(object): sys.path.insert(0, dir) try: values['__name__'] = filename - exec(open(filename, 'r').read(), {}, values) + with open(filename, 'r') as f: + contents = f.read() + exec(contents, {}, values) finally: if dir: del sys.path[0] diff --git a/src/engine/SCons/cpp.py b/src/engine/SCons/cpp.py index f282ba7..2e20017 100644 --- a/src/engine/SCons/cpp.py +++ b/src/engine/SCons/cpp.py @@ -379,7 +379,8 @@ class PreProcessor(object): return None def read_file(self, file): - return open(file).read() + with open(file) as f: + return f.read() # Start and stop processing include lines. -- cgit v0.12 From d9c5836692f8066b7c4fdf42c5a79c32957bff08 Mon Sep 17 00:00:00 2001 From: Ibrahim Esmat Date: Wed, 26 Jul 2017 21:24:10 -0700 Subject: Fix MSVC_UWP_APP test to take into account the MSVC_VERSION. The test should take into account if the MSVC_VERSION is less than 14.0 (VS2015) and check that the LIBPATH doesn't include the store paths. --- test/MSVC/MSVC_UWP_APP.py | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/test/MSVC/MSVC_UWP_APP.py b/test/MSVC/MSVC_UWP_APP.py index 2521ad6..6d33567 100644 --- a/test/MSVC/MSVC_UWP_APP.py +++ b/test/MSVC/MSVC_UWP_APP.py @@ -30,17 +30,23 @@ the desired effect. """ import TestSCons +import SCons.Tool.MSCommon.vc as msvc def AreVCStoreLibPathsInLIBPATH(output): + libpath = None + msvc_version = None lines = output.splitlines() for line in lines: if 'env[ENV][LIBPATH]=' in line: idx_eq = line.find('=') libpath = line[idx_eq + 1:] + elif 'env[MSVC_VERSION]=' in line: + idx_eq = line.find('=') + msvc_version = line[idx_eq + 1:] - if not libpath: - # Couldn't find the libpath in the output - return (False, False) + if not libpath or not msvc_version: + # Couldn't find the libpath or msvc version in the output + return (False, False, None) libpaths = libpath.lower().split(';') (vclibstore_path_present, vclibstorerefs_path_present) = (False, False) @@ -56,7 +62,7 @@ def AreVCStoreLibPathsInLIBPATH(output): elif r'vc\lib\store' in path: vclibstore_path_present = True - return (vclibstore_path_present, vclibstorerefs_path_present) + return (vclibstore_path_present, vclibstorerefs_path_present, msvc_version) _python_ = TestSCons._python_ @@ -77,21 +83,37 @@ else: env = Environment(tools=['default', 'msvc'], variables=help_vars) # Print the ENV LIBPATH to stdout print('env[ENV][LIBPATH]=%s' % env.get('ENV').get('LIBPATH')) +print('env[MSVC_VERSION]=%s' % env.get('MSVC_VERSION')) """) +installed_msvc_versions = msvc.cached_get_installed_vcs() +# MSVC guaranteed to be at least one version on the system or else skip_if_not_msvc() function +# would have skipped the test +greatest_msvc_version_on_system = installed_msvc_versions[0] +maj, min = msvc.msvc_version_to_maj_min(greatest_msvc_version_on_system) + +# We always use the greatest MSVC version installed on the system + # Test setting MSVC_UWP_APP is '1' (True) test.run(arguments = "MSVC_UWP_APP=1") -(vclibstore_path_present, vclibstorerefs_path_present) = AreVCStoreLibPathsInLIBPATH(test.stdout()) -test.fail_test((vclibstore_path_present is False) or (vclibstorerefs_path_present is False)) +(vclibstore_path_present, vclibstorerefs_path_present, msvc_version) = AreVCStoreLibPathsInLIBPATH(test.stdout()) +test.fail_test(msvc_version != greatest_msvc_version_on_system) +# VS2015+ +if maj >= 14: + test.fail_test((vclibstore_path_present is False) or (vclibstorerefs_path_present is False)) +else: + test.fail_test((vclibstore_path_present is True) or (vclibstorerefs_path_present is True)) # Test setting MSVC_UWP_APP is '0' (False) test.run(arguments = "MSVC_UWP_APP=0") -(vclibstore_path_present, vclibstorerefs_path_present) = AreVCStoreLibPathsInLIBPATH(test.stdout()) +(vclibstore_path_present, vclibstorerefs_path_present, msvc_version) = AreVCStoreLibPathsInLIBPATH(test.stdout()) +test.fail_test(msvc_version != greatest_msvc_version_on_system) test.fail_test((vclibstore_path_present is True) or (vclibstorerefs_path_present is True)) # Test not setting MSVC_UWP_APP test.run(arguments = "") -(vclibstore_path_present, vclibstorerefs_path_present) = AreVCStoreLibPathsInLIBPATH(test.stdout()) +(vclibstore_path_present, vclibstorerefs_path_present, msvc_version) = AreVCStoreLibPathsInLIBPATH(test.stdout()) +test.fail_test(msvc_version != greatest_msvc_version_on_system) test.fail_test((vclibstore_path_present is True) or (vclibstorerefs_path_present is True)) test.pass_test() -- cgit v0.12 From b9df77702c7c7c669b29e8a23af8932a2f30492e Mon Sep 17 00:00:00 2001 From: Ibrahim Esmat Date: Thu, 27 Jul 2017 06:00:46 -0700 Subject: Fix MSVC_UWP_APP test to take into account the MSVC_VERSION. Code Review Fixes. --- test/MSVC/MSVC_UWP_APP.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/test/MSVC/MSVC_UWP_APP.py b/test/MSVC/MSVC_UWP_APP.py index 6d33567..1ffc917 100644 --- a/test/MSVC/MSVC_UWP_APP.py +++ b/test/MSVC/MSVC_UWP_APP.py @@ -38,11 +38,9 @@ def AreVCStoreLibPathsInLIBPATH(output): lines = output.splitlines() for line in lines: if 'env[ENV][LIBPATH]=' in line: - idx_eq = line.find('=') - libpath = line[idx_eq + 1:] + libpath = line.split('=')[1] elif 'env[MSVC_VERSION]=' in line: - idx_eq = line.find('=') - msvc_version = line[idx_eq + 1:] + msvc_version = line.split('=')[1] if not libpath or not msvc_version: # Couldn't find the libpath or msvc version in the output @@ -100,21 +98,25 @@ test.run(arguments = "MSVC_UWP_APP=1") test.fail_test(msvc_version != greatest_msvc_version_on_system) # VS2015+ if maj >= 14: - test.fail_test((vclibstore_path_present is False) or (vclibstorerefs_path_present is False)) + test.fail_test((vclibstore_path_present is False) or (vclibstorerefs_path_present is False), + message='VC Store LIBPATHs NOT present when MSVC_UWP_APP=1 (msvc_version=%s)' % msvc_version) else: - test.fail_test((vclibstore_path_present is True) or (vclibstorerefs_path_present is True)) + test.fail_test((vclibstore_path_present is True) or (vclibstorerefs_path_present is True), + message='VC Store LIBPATHs present for unsupported version when MSVC_UWP_APP=1 (msvc_version=%s)' % msvc_version) # Test setting MSVC_UWP_APP is '0' (False) test.run(arguments = "MSVC_UWP_APP=0") (vclibstore_path_present, vclibstorerefs_path_present, msvc_version) = AreVCStoreLibPathsInLIBPATH(test.stdout()) test.fail_test(msvc_version != greatest_msvc_version_on_system) -test.fail_test((vclibstore_path_present is True) or (vclibstorerefs_path_present is True)) +test.fail_test((vclibstore_path_present is True) or (vclibstorerefs_path_present is True), + message='VC Store LIBPATHs present when MSVC_UWP_APP=0 (msvc_version=%s)' % msvc_version) # Test not setting MSVC_UWP_APP test.run(arguments = "") (vclibstore_path_present, vclibstorerefs_path_present, msvc_version) = AreVCStoreLibPathsInLIBPATH(test.stdout()) test.fail_test(msvc_version != greatest_msvc_version_on_system) -test.fail_test((vclibstore_path_present is True) or (vclibstorerefs_path_present is True)) +test.fail_test((vclibstore_path_present is True) or (vclibstorerefs_path_present is True), + message='VC Store LIBPATHs present when MSVC_UWP_APP not set (msvc_version=%s)' % msvc_version) test.pass_test() -- cgit v0.12 From b1a30ba5733531036223946538731a4057bb84e8 Mon Sep 17 00:00:00 2001 From: Ibrahim Esmat Date: Thu, 27 Jul 2017 06:08:05 -0700 Subject: Fix MSVC_UWP_APP test to take into account the MSVC_VERSION. Missed a couple of messages on fail_test --- test/MSVC/MSVC_UWP_APP.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/MSVC/MSVC_UWP_APP.py b/test/MSVC/MSVC_UWP_APP.py index 1ffc917..19cd3f7 100644 --- a/test/MSVC/MSVC_UWP_APP.py +++ b/test/MSVC/MSVC_UWP_APP.py @@ -95,7 +95,9 @@ maj, min = msvc.msvc_version_to_maj_min(greatest_msvc_version_on_system) # Test setting MSVC_UWP_APP is '1' (True) test.run(arguments = "MSVC_UWP_APP=1") (vclibstore_path_present, vclibstorerefs_path_present, msvc_version) = AreVCStoreLibPathsInLIBPATH(test.stdout()) -test.fail_test(msvc_version != greatest_msvc_version_on_system) +test.fail_test(msvc_version != greatest_msvc_version_on_system, + message='MSVC_VERSION (%s) does not match expected greatest version on system (%s)' \ + % (msvc_version, greatest_msvc_version_on_system)) # VS2015+ if maj >= 14: test.fail_test((vclibstore_path_present is False) or (vclibstorerefs_path_present is False), @@ -107,14 +109,18 @@ else: # Test setting MSVC_UWP_APP is '0' (False) test.run(arguments = "MSVC_UWP_APP=0") (vclibstore_path_present, vclibstorerefs_path_present, msvc_version) = AreVCStoreLibPathsInLIBPATH(test.stdout()) -test.fail_test(msvc_version != greatest_msvc_version_on_system) +test.fail_test(msvc_version != greatest_msvc_version_on_system, + message='MSVC_VERSION (%s) does not match expected greatest version on system (%s)' \ + % (msvc_version, greatest_msvc_version_on_system)) test.fail_test((vclibstore_path_present is True) or (vclibstorerefs_path_present is True), message='VC Store LIBPATHs present when MSVC_UWP_APP=0 (msvc_version=%s)' % msvc_version) # Test not setting MSVC_UWP_APP test.run(arguments = "") (vclibstore_path_present, vclibstorerefs_path_present, msvc_version) = AreVCStoreLibPathsInLIBPATH(test.stdout()) -test.fail_test(msvc_version != greatest_msvc_version_on_system) +test.fail_test(msvc_version != greatest_msvc_version_on_system, + message='MSVC_VERSION (%s) does not match expected greatest version on system (%s)' \ + % (msvc_version, greatest_msvc_version_on_system)) test.fail_test((vclibstore_path_present is True) or (vclibstorerefs_path_present is True), message='VC Store LIBPATHs present when MSVC_UWP_APP not set (msvc_version=%s)' % msvc_version) -- cgit v0.12 From 560e375169d9a3b12728b2e31fda8bc725819b74 Mon Sep 17 00:00:00 2001 From: Ibrahim Esmat Date: Mon, 31 Jul 2017 18:18:16 -0700 Subject: Fix MSVC_UWP_APP test to take into account the MSVC_VERSION. Skip test if MSVC_VERSION is less than VS2015 --- test/MSVC/MSVC_UWP_APP.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/test/MSVC/MSVC_UWP_APP.py b/test/MSVC/MSVC_UWP_APP.py index 19cd3f7..c72c739 100644 --- a/test/MSVC/MSVC_UWP_APP.py +++ b/test/MSVC/MSVC_UWP_APP.py @@ -92,19 +92,18 @@ maj, min = msvc.msvc_version_to_maj_min(greatest_msvc_version_on_system) # We always use the greatest MSVC version installed on the system +if maj < 14: + # Skip the test if MSVC version is less than VS2015 + test.skip_test("Available MSVC doesn't support App store ") + # Test setting MSVC_UWP_APP is '1' (True) test.run(arguments = "MSVC_UWP_APP=1") (vclibstore_path_present, vclibstorerefs_path_present, msvc_version) = AreVCStoreLibPathsInLIBPATH(test.stdout()) test.fail_test(msvc_version != greatest_msvc_version_on_system, message='MSVC_VERSION (%s) does not match expected greatest version on system (%s)' \ % (msvc_version, greatest_msvc_version_on_system)) -# VS2015+ -if maj >= 14: - test.fail_test((vclibstore_path_present is False) or (vclibstorerefs_path_present is False), - message='VC Store LIBPATHs NOT present when MSVC_UWP_APP=1 (msvc_version=%s)' % msvc_version) -else: - test.fail_test((vclibstore_path_present is True) or (vclibstorerefs_path_present is True), - message='VC Store LIBPATHs present for unsupported version when MSVC_UWP_APP=1 (msvc_version=%s)' % msvc_version) +test.fail_test((vclibstore_path_present is False) or (vclibstorerefs_path_present is False), + message='VC Store LIBPATHs NOT present when MSVC_UWP_APP=1 (msvc_version=%s)' % msvc_version) # Test setting MSVC_UWP_APP is '0' (False) test.run(arguments = "MSVC_UWP_APP=0") @@ -113,7 +112,7 @@ test.fail_test(msvc_version != greatest_msvc_version_on_system, message='MSVC_VERSION (%s) does not match expected greatest version on system (%s)' \ % (msvc_version, greatest_msvc_version_on_system)) test.fail_test((vclibstore_path_present is True) or (vclibstorerefs_path_present is True), - message='VC Store LIBPATHs present when MSVC_UWP_APP=0 (msvc_version=%s)' % msvc_version) + message='VC Store LIBPATHs present when MSVC_UWP_APP=0 (msvc_version=%s)' % msvc_version) # Test not setting MSVC_UWP_APP test.run(arguments = "") @@ -122,7 +121,7 @@ test.fail_test(msvc_version != greatest_msvc_version_on_system, message='MSVC_VERSION (%s) does not match expected greatest version on system (%s)' \ % (msvc_version, greatest_msvc_version_on_system)) test.fail_test((vclibstore_path_present is True) or (vclibstorerefs_path_present is True), - message='VC Store LIBPATHs present when MSVC_UWP_APP not set (msvc_version=%s)' % msvc_version) + message='VC Store LIBPATHs present when MSVC_UWP_APP not set (msvc_version=%s)' % msvc_version) test.pass_test() -- cgit v0.12