From a17c87b1b644acb37270d2282743d471c2aae549 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 9 Jan 2019 08:40:36 -0600 Subject: updated to use the target arch removed debug print --- src/engine/SCons/Tool/MSCommon/vc.py | 66 ++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 7 deletions(-) diff --git a/src/engine/SCons/Tool/MSCommon/vc.py b/src/engine/SCons/Tool/MSCommon/vc.py index cf776fc..fccab88 100644 --- a/src/engine/SCons/Tool/MSCommon/vc.py +++ b/src/engine/SCons/Tool/MSCommon/vc.py @@ -347,6 +347,64 @@ def find_batch_file(env,msvc_version,host_arch,target_arch): __INSTALLED_VCS_RUN = None +def _check_cl_exists_in_vc_dir(env, vc_dir, msvc_version): + ver_num = float(get_msvc_version_numeric(msvc_version)) + found_cl = False + (host_platform, target_platform,req_target_platform) = get_host_target(env) + + # check to see if the x86 or 64 bit compiler is in the bin dir + if ver_num > 14: + try: + f = open(os.path.join(vc_dir, r'Auxiliary\Build\Microsoft.VCToolsVersion.default.txt')) + vc_specific_version = f.readlines()[0].strip() + except: + return False + + if host_platform in ('amd64','x86_64'): + host_dir = "Hostx64" + elif host_platform in ('i386','i686','x86'): + host_dir = "Hostx86" + else: + return False + + if target_platform in ('amd64','x86_64'): + target_dir = "x64" + elif target_platform in ('i386','i686','x86'): + target_dir = "x86" + else: + return False + + if os.path.exists(os.path.join(vc_dir, r'Tools\MSVC', vc_specific_version, 'bin', host_dir, target_dir, 'cl.exe')): + return True + elif ver_num <= 14: + if host_platform in ('amd64','x86_64'): + host_dir = "amd64" + elif host_platform in ('i386','i686','x86'): + host_dir = "x86" + else: + return False + + + if target_platform in ('amd64','x86_64'): + target_dir = "amd64" + elif target_platform in ('i386','i686','x86'): + target_dir = "x86" + elif target_platform in ('ia64'): + target_dir = "ia64" + else: + return False + + host_target_dir = _HOST_TARGET_ARCH_TO_BAT_ARCH[(host_dir, target_dir)] + if host_target_dir == 'x86': + host_target_dir == '' + else: + host_target_dir += '\\' + cl_dir = 'bin\\' + host_target_dir + 'cl.exe' + if os.path.exists(os.path.join(vc_dir, cl_dir)): + return True + return False + + def cached_get_installed_vcs(env): global __INSTALLED_VCS_RUN @@ -364,13 +422,7 @@ def get_installed_vcs(env): VC_DIR = find_vc_pdir(ver) if VC_DIR: debug('found VC %s' % ver) - ver_num = float(get_msvc_version_numeric(ver)) - # check to see if the x86 or 64 bit compiler is in the bin dir - if (ver_num > 14 and msvc_find_valid_batch_script(env,ver,False)): - installed_versions.append(ver) - elif (ver_num <= 14 - and (os.path.exists(os.path.join(VC_DIR, r'bin\cl.exe')) - or os.path.exists(os.path.join(VC_DIR, r'bin\amd64\cl.exe')))): + if _check_cl_exists_in_vc_dir(env, VC_DIR, ver): installed_versions.append(ver) else: debug('find_vc_pdir no compiler found %s' % ver) -- cgit v0.12 From 39bdae14fbee3f7c724ec64b38f117849cbebeda Mon Sep 17 00:00:00 2001 From: Daniel Moody Date: Wed, 9 Jan 2019 10:07:21 -0600 Subject: added ability to get vc dir without env (assume host == target) and fixed test --- src/engine/SCons/Tool/MSCommon/vc.py | 10 +++++++--- test/CC/CCFLAGS.py | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/engine/SCons/Tool/MSCommon/vc.py b/src/engine/SCons/Tool/MSCommon/vc.py index fccab88..168add5 100644 --- a/src/engine/SCons/Tool/MSCommon/vc.py +++ b/src/engine/SCons/Tool/MSCommon/vc.py @@ -350,8 +350,12 @@ __INSTALLED_VCS_RUN = None def _check_cl_exists_in_vc_dir(env, vc_dir, msvc_version): ver_num = float(get_msvc_version_numeric(msvc_version)) found_cl = False - (host_platform, target_platform,req_target_platform) = get_host_target(env) - + if env: + (host_platform, target_platform,req_target_platform) = get_host_target(env) + else: + host_platform = platform.machine().lower() + target_platform = host_platform + # check to see if the x86 or 64 bit compiler is in the bin dir if ver_num > 14: try: @@ -414,7 +418,7 @@ def cached_get_installed_vcs(env): return __INSTALLED_VCS_RUN -def get_installed_vcs(env): +def get_installed_vcs(env=None): installed_versions = [] for ver in _VCVER: debug('trying to find VC %s' % ver) diff --git a/test/CC/CCFLAGS.py b/test/CC/CCFLAGS.py index 967f865..a9db61f 100644 --- a/test/CC/CCFLAGS.py +++ b/test/CC/CCFLAGS.py @@ -29,6 +29,8 @@ import TestSCons _obj = TestSCons._obj +test = TestSCons.TestSCons() + if sys.platform == 'win32': import SCons.Tool.MSCommon as msc @@ -42,8 +44,6 @@ else: fooflags = '-DFOO' barflags = '-DBAR' -test = TestSCons.TestSCons() - test.write('SConstruct', """ foo = Environment(CCFLAGS = '%s') bar = Environment(CCFLAGS = '%s') -- cgit v0.12 From f8de931ad51d8f81770c47c7ba6259eccaee0503 Mon Sep 17 00:00:00 2001 From: Daniel Moody Date: Wed, 9 Jan 2019 10:20:17 -0600 Subject: reverted tests so they can use a default host == target platform for find msvc fixed some other tests --- src/engine/SCons/Tool/MSCommon/vc.py | 4 ++-- test/AS/ASFLAGS.py | 2 +- test/AS/ASPPFLAGS.py | 2 +- test/CC/CCFLAGS.py | 6 +++--- test/CC/CFLAGS.py | 2 +- test/LINK/SHLINKCOMSTR.py | 2 +- test/Libs/LIBPREFIXES.py | 2 +- test/Libs/LIBS.py | 6 ++---- test/Libs/LIBSUFFIXES.py | 6 +++--- test/Libs/SharedLibraryIxes.py | 2 +- test/long-lines/live.py | 2 +- test/sconsign/script/dblite.py | 2 +- testing/framework/TestSCons.py | 2 +- 13 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/engine/SCons/Tool/MSCommon/vc.py b/src/engine/SCons/Tool/MSCommon/vc.py index 168add5..ad921ef 100644 --- a/src/engine/SCons/Tool/MSCommon/vc.py +++ b/src/engine/SCons/Tool/MSCommon/vc.py @@ -409,7 +409,7 @@ def _check_cl_exists_in_vc_dir(env, vc_dir, msvc_version): return False -def cached_get_installed_vcs(env): +def cached_get_installed_vcs(env=None): global __INSTALLED_VCS_RUN if __INSTALLED_VCS_RUN is None: @@ -643,7 +643,7 @@ def msvc_setup_env(env): SCons.Warnings.warn(SCons.Warnings.VisualCMissingWarning, "Could not find MSVC compiler 'cl.exe', it may need to be installed separately with Visual Studio") -def msvc_exists(env, version=None): +def msvc_exists(env=None, version=None): vcs = cached_get_installed_vcs(env) if version is None: return len(vcs) > 0 diff --git a/test/AS/ASFLAGS.py b/test/AS/ASFLAGS.py index b72d32d..79fde8c 100644 --- a/test/AS/ASFLAGS.py +++ b/test/AS/ASFLAGS.py @@ -42,7 +42,7 @@ o_c = ' -x -c' if sys.platform == 'win32': import SCons.Tool.MSCommon as msc - if msc.msvc_exists(test.Environment()): + if msc.msvc_exists(): o_c = ' -x' test.write('SConstruct', """ diff --git a/test/AS/ASPPFLAGS.py b/test/AS/ASPPFLAGS.py index d548eaa..254a458 100644 --- a/test/AS/ASPPFLAGS.py +++ b/test/AS/ASPPFLAGS.py @@ -42,7 +42,7 @@ o_c = ' -x -c' if sys.platform == 'win32': import SCons.Tool.MSCommon as msc - if msc.msvc_exists(test.Environment()): + if msc.msvc_exists(): o_c = ' -x' test.write('SConstruct', """ diff --git a/test/CC/CCFLAGS.py b/test/CC/CCFLAGS.py index a9db61f..069b429 100644 --- a/test/CC/CCFLAGS.py +++ b/test/CC/CCFLAGS.py @@ -29,12 +29,10 @@ import TestSCons _obj = TestSCons._obj -test = TestSCons.TestSCons() - if sys.platform == 'win32': import SCons.Tool.MSCommon as msc - if not msc.msvc_exists(test.Environment()): + if not msc.msvc_exists(): fooflags = '-DFOO' barflags = '-DBAR' else: @@ -44,6 +42,8 @@ else: fooflags = '-DFOO' barflags = '-DBAR' +test = TestSCons.TestSCons() + test.write('SConstruct', """ foo = Environment(CCFLAGS = '%s') bar = Environment(CCFLAGS = '%s') diff --git a/test/CC/CFLAGS.py b/test/CC/CFLAGS.py index 6d0ee39..590d6b5 100644 --- a/test/CC/CFLAGS.py +++ b/test/CC/CFLAGS.py @@ -47,7 +47,7 @@ _obj = TestSCons._obj if sys.platform == 'win32': import SCons.Tool.MSCommon as msc - if not msc.msvc_exists(test.Environment()): + if not msc.msvc_exists(): fooflags = '-DFOO' barflags = '-DBAR' else: diff --git a/test/LINK/SHLINKCOMSTR.py b/test/LINK/SHLINKCOMSTR.py index bf419e5..4dd5c7c 100644 --- a/test/LINK/SHLINKCOMSTR.py +++ b/test/LINK/SHLINKCOMSTR.py @@ -73,7 +73,7 @@ test.must_match('test3.dll', "test1.c\ntest2.c\n") if sys.platform == "win32": import SCons.Tool.MSCommon as msc - if msc.msvc_exists(test.Environment()): + if msc.msvc_exists(): # Now test an actual compile and link. Since MS Windows # resets the link actions, this could fail even if the above # test passed. diff --git a/test/Libs/LIBPREFIXES.py b/test/Libs/LIBPREFIXES.py index b9621a1..aed451e 100644 --- a/test/Libs/LIBPREFIXES.py +++ b/test/Libs/LIBPREFIXES.py @@ -31,7 +31,7 @@ import TestSCons if sys.platform == 'win32': _lib = '.lib' import SCons.Tool.MSCommon as msc - if not msc.msvc_exists(test.Environment()): + if not msc.msvc_exists(): _lib = '.a' else: _lib = '.a' diff --git a/test/Libs/LIBS.py b/test/Libs/LIBS.py index 0798475..5639228 100644 --- a/test/Libs/LIBS.py +++ b/test/Libs/LIBS.py @@ -27,19 +27,17 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import TestSCons import sys -test = TestSCons.TestSCons() - if sys.platform == 'win32': _exe = '.exe' bar_lib = 'bar.lib' import SCons.Tool.MSCommon as msc - if not msc.msvc_exists(test.Environment()): + if not msc.msvc_exists(): bar_lib = 'libbar.a' else: _exe = '' bar_lib = 'libbar.a' - +test = TestSCons.TestSCons() test.subdir('sub1', 'sub2') diff --git a/test/Libs/LIBSUFFIXES.py b/test/Libs/LIBSUFFIXES.py index 030e601..13baeab 100644 --- a/test/Libs/LIBSUFFIXES.py +++ b/test/Libs/LIBSUFFIXES.py @@ -28,16 +28,16 @@ import os import sys import TestSCons -test = TestSCons.TestSCons() - if sys.platform == 'win32': lib_ = '' import SCons.Tool.MSCommon as msc - if not msc.msvc_exists(test.Environment()): + if not msc.msvc_exists(): lib_ = 'lib' else: lib_ = 'lib' +test = TestSCons.TestSCons() + test.write('SConstruct', """ env = Environment(LIBSUFFIX = '.xxx', LIBSUFFIXES = ['.xxx']) diff --git a/test/Libs/SharedLibraryIxes.py b/test/Libs/SharedLibraryIxes.py index 2a58026..93d67ea 100644 --- a/test/Libs/SharedLibraryIxes.py +++ b/test/Libs/SharedLibraryIxes.py @@ -42,7 +42,7 @@ isWindows = sys.platform == 'win32' isMingw = False if isWindows: import SCons.Tool.MSCommon as msc - if not msc.msvc_exists(test.Environment()): + if not msc.msvc_exists(): # We can't seem to find any MSVC version, so we assume # that MinGW is installed instead. Accordingly, we use the # standard gcc/g++ conventions for lib prefixes and suffixes diff --git a/test/long-lines/live.py b/test/long-lines/live.py index 8540cd7..5618f55 100644 --- a/test/long-lines/live.py +++ b/test/long-lines/live.py @@ -43,7 +43,7 @@ if sys.platform == 'win32': linkflag_init = '/LIBPATH:' + test.workpath() linkflag = ' /LIBPATH:' + test.workpath() import SCons.Tool.MSCommon as msc - if not msc.msvc_exists(test.Environment()): + if not msc.msvc_exists(): lib_shared_dll = 'shared.dll' lib_static_lib = 'libstatic.a' arflag_init = 'r' diff --git a/test/sconsign/script/dblite.py b/test/sconsign/script/dblite.py index 36718f1..0daf8bf 100644 --- a/test/sconsign/script/dblite.py +++ b/test/sconsign/script/dblite.py @@ -114,7 +114,7 @@ date_re = r'\S+ \S+ [ \d]\d \d\d:\d\d:\d\d \d\d\d\d' if sys.platform == 'win32': import SCons.Tool.MSCommon as msc - if msc.msvc_exists(test.Environment()): + if msc.msvc_exists(): manifest = r""" embedManifestExeCheck\(target, source, env\)""" else: diff --git a/testing/framework/TestSCons.py b/testing/framework/TestSCons.py index 01002c5..b543c07 100644 --- a/testing/framework/TestSCons.py +++ b/testing/framework/TestSCons.py @@ -1072,7 +1072,7 @@ SConscript( sconscript ) try: import SCons.Tool.MSCommon as msc - if not msc.msvc_exists(self.Environment()): + if not msc.msvc_exists(): msg = "No MSVC toolchain found...skipping test\n" self.skip_test(msg) except: -- cgit v0.12 From d325e5fa8843e6667fd87ee7910252570f405607 Mon Sep 17 00:00:00 2001 From: Daniel Moody Date: Wed, 9 Jan 2019 11:04:29 -0600 Subject: removed unused varied, added named expections, whitespace and comments fixed except check revert some obsolete changes --- src/engine/SCons/Tool/MSCommon/vc.py | 47 +++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/src/engine/SCons/Tool/MSCommon/vc.py b/src/engine/SCons/Tool/MSCommon/vc.py index ad921ef..e9a473f 100644 --- a/src/engine/SCons/Tool/MSCommon/vc.py +++ b/src/engine/SCons/Tool/MSCommon/vc.py @@ -348,20 +348,29 @@ def find_batch_file(env,msvc_version,host_arch,target_arch): __INSTALLED_VCS_RUN = None def _check_cl_exists_in_vc_dir(env, vc_dir, msvc_version): - ver_num = float(get_msvc_version_numeric(msvc_version)) - found_cl = False + + # determine if there is a specific target platform we want to build for and + # use that to find a list of valid VCs, default is host platform == target platform + # and same for if no env is specified to extract target platform from if env: - (host_platform, target_platform,req_target_platform) = get_host_target(env) + (host_platform, target_platform, req_target_platform) = get_host_target(env) else: host_platform = platform.machine().lower() target_platform = host_platform - # check to see if the x86 or 64 bit compiler is in the bin dir + ver_num = float(get_msvc_version_numeric(msvc_version)) + + # make sure the cl.exe exists meaning the tool is installed if ver_num > 14: + # 2017 and newer allowed multiple versions of the VC toolset to be installed at the same time. + # Just get the default tool version for now + #TODO: support setting a specific minor VC version try: f = open(os.path.join(vc_dir, r'Auxiliary\Build\Microsoft.VCToolsVersion.default.txt')) vc_specific_version = f.readlines()[0].strip() - except: + except OSError: + return False + except IndexError: return False if host_platform in ('amd64','x86_64'): @@ -380,34 +389,35 @@ def _check_cl_exists_in_vc_dir(env, vc_dir, msvc_version): if os.path.exists(os.path.join(vc_dir, r'Tools\MSVC', vc_specific_version, 'bin', host_dir, target_dir, 'cl.exe')): return True + elif ver_num <= 14: + if host_platform in ('amd64','x86_64'): - host_dir = "amd64" + host_platform = "amd64" elif host_platform in ('i386','i686','x86'): - host_dir = "x86" + host_platform = "x86" else: return False - if target_platform in ('amd64','x86_64'): - target_dir = "amd64" + target_platform = "amd64" elif target_platform in ('i386','i686','x86'): - target_dir = "x86" + target_platform = "x86" elif target_platform in ('ia64'): - target_dir = "ia64" + target_platform = "ia64" else: return False - host_target_dir = _HOST_TARGET_ARCH_TO_BAT_ARCH[(host_dir, target_dir)] + host_target_dir = _HOST_TARGET_ARCH_TO_BAT_ARCH[(host_platform, target_platform)] if host_target_dir == 'x86': host_target_dir == '' else: host_target_dir += '\\' - cl_dir = 'bin\\' + host_target_dir + 'cl.exe' - if os.path.exists(os.path.join(vc_dir, cl_dir)): + + if os.path.exists(os.path.join(vc_dir, 'bin\\' + host_target_dir + 'cl.exe')): return True - return False + return False def cached_get_installed_vcs(env=None): global __INSTALLED_VCS_RUN @@ -509,7 +519,7 @@ def msvc_setup_env_once(env): msvc_setup_env(env) env["MSVC_SETUP_RUN"] = True -def msvc_find_valid_batch_script(env,version,modify_env=True): +def msvc_find_valid_batch_script(env,version): debug('vc.py:msvc_find_valid_batch_script()') # Find the host platform, target platform, and if present the requested # target platform @@ -535,8 +545,7 @@ def msvc_find_valid_batch_script(env,version,modify_env=True): d = None for tp in try_target_archs: # Set to current arch. - if modify_env: - env['TARGET_ARCH']=tp + env['TARGET_ARCH']=tp debug("vc.py:msvc_find_valid_batch_script() trying target_platform:%s"%tp) host_target = (host_platform, tp) @@ -593,7 +602,7 @@ def msvc_find_valid_batch_script(env,version,modify_env=True): # If we cannot find a viable installed compiler, reset the TARGET_ARCH # To it's initial value - if not d and modify_env: + if not d: env['TARGET_ARCH']=req_target_platform return d -- cgit v0.12