diff options
-rw-r--r-- | src/engine/SCons/Debug.py | 4 | ||||
-rw-r--r-- | src/engine/SCons/Tool/linkloc.py | 4 | ||||
-rw-r--r-- | src/engine/SCons/Util.py | 5 | ||||
-rw-r--r-- | src/engine/SCons/Variables/__init__.py | 4 | ||||
-rw-r--r-- | src/engine/SCons/cpp.py | 3 | ||||
-rw-r--r-- | test/MSVC/MSVC_UWP_APP.py | 53 |
6 files changed, 53 insertions, 20 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. diff --git a/test/MSVC/MSVC_UWP_APP.py b/test/MSVC/MSVC_UWP_APP.py index 2521ad6..c72c739 100644 --- a/test/MSVC/MSVC_UWP_APP.py +++ b/test/MSVC/MSVC_UWP_APP.py @@ -30,17 +30,21 @@ 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:] + libpath = line.split('=')[1] + elif 'env[MSVC_VERSION]=' in line: + msvc_version = line.split('=')[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 +60,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,22 +81,47 @@ 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 + +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) = 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, + 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 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") -(vclibstore_path_present, vclibstorerefs_path_present) = AreVCStoreLibPathsInLIBPATH(test.stdout()) -test.fail_test((vclibstore_path_present is True) or (vclibstorerefs_path_present is True)) +(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)) +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) = AreVCStoreLibPathsInLIBPATH(test.stdout()) -test.fail_test((vclibstore_path_present is True) or (vclibstorerefs_path_present is True)) +(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)) +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() |