From 23fd1a45db2d57767dcbb50c151295dc93975181 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Thu, 9 Apr 2020 15:11:52 -0700 Subject: pep8 --- src/engine/SCons/Tool/MSCommon/vc.py | 12 +++++++----- src/engine/SCons/Tool/msvc.py | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/engine/SCons/Tool/MSCommon/vc.py b/src/engine/SCons/Tool/MSCommon/vc.py index 82fb6b9..f5a410f 100644 --- a/src/engine/SCons/Tool/MSCommon/vc.py +++ b/src/engine/SCons/Tool/MSCommon/vc.py @@ -233,16 +233,16 @@ _VCVER = ["14.2", "14.1", "14.1Exp", "14.0", "14.0Exp", "12.0", "12.0Exp", "11.0 # if using vswhere, a further mapping is needed _VCVER_TO_VSWHERE_VER = { - '14.2' : '[16.0, 17.0)', - '14.1' : '[15.0, 16.0)', + '14.2': '[16.0, 17.0)', + '14.1': '[15.0, 16.0)', } _VCVER_TO_PRODUCT_DIR = { - '14.2' : [ + '14.2': [ (SCons.Util.HKEY_LOCAL_MACHINE, r'')], # not set by this version - '14.1' : [ + '14.1': [ (SCons.Util.HKEY_LOCAL_MACHINE, r'')], # not set by this version - '14.1Exp' : [ + '14.1Exp': [ (SCons.Util.HKEY_LOCAL_MACHINE, r'')], # not set by this version '14.0' : [ (SCons.Util.HKEY_LOCAL_MACHINE, r'Microsoft\VisualStudio\14.0\Setup\VC\ProductDir')], @@ -290,6 +290,7 @@ _VCVER_TO_PRODUCT_DIR = { ] } + def msvc_version_to_maj_min(msvc_version): msvc_version_numeric = get_msvc_version_numeric(msvc_version) @@ -303,6 +304,7 @@ def msvc_version_to_maj_min(msvc_version): except ValueError as e: raise ValueError("Unrecognized version %s (%s)" % (msvc_version,msvc_version_numeric)) + def is_host_target_supported(host_target, msvc_version): """Check if (host, target) pair is supported for a VC version. diff --git a/src/engine/SCons/Tool/msvc.py b/src/engine/SCons/Tool/msvc.py index 65c0e91..05a20e0 100644 --- a/src/engine/SCons/Tool/msvc.py +++ b/src/engine/SCons/Tool/msvc.py @@ -214,6 +214,7 @@ ShCXXAction = SCons.Action.Action("$SHCXXCOM", "$SHCXXCOMSTR", batch_key=msvc_batch_key, targets='$CHANGED_TARGETS') + def generate(env): """Add Builders and construction variables for MSVC++ to an Environment.""" static_obj, shared_obj = SCons.Tool.createObjBuilders(env) -- cgit v0.12 From 91b699c9e13a94d37bd6467930874672eff4c5b1 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Fri, 10 Apr 2020 15:21:04 -0700 Subject: Resolve issue #3605. Allow specifying VSWHERE to environment --- src/CHANGES.txt | 2 + src/engine/SCons/Tool/MSCommon/__init__.py | 3 +- src/engine/SCons/Tool/MSCommon/vc.py | 57 +++++++++++++++++------------ src/engine/SCons/Tool/MSCommon/vcTests.py | 35 ++++++++++++++++-- src/engine/SCons/Tool/MSCommon/vs.py | 36 +++++++++--------- src/engine/SCons/Tool/linkloc.py | 2 +- src/engine/SCons/Tool/msvc.py | 5 ++- src/engine/SCons/Tool/msvc.xml | 34 +++++++++++++++++ src/engine/SCons/Tool/msvsTests.py | 2 +- src/script/scons.bat | 6 +-- test/Win32/scons-bat-error.py | 2 +- test/fixture/no_msvc/no_msvcs_sconstruct.py | 2 +- 12 files changed, 133 insertions(+), 53 deletions(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 6ec16f3..862380b 100755 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -30,6 +30,8 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER - Add msys2 installed mingw default path to PATH for mingw tool. - C:\msys64\mingw64\bin - Purge obsolete internal build and tooling scripts + - Allow user specified location for vswhere.exe specified by VSWHERE. + NOTE: This must be set at the time the 'msvc' tool is initialized to have any effect. From Jeremy Elson: - Updated design doc to use the correct syntax for Depends() diff --git a/src/engine/SCons/Tool/MSCommon/__init__.py b/src/engine/SCons/Tool/MSCommon/__init__.py index c87bf71..be7720a 100644 --- a/src/engine/SCons/Tool/MSCommon/__init__.py +++ b/src/engine/SCons/Tool/MSCommon/__init__.py @@ -42,7 +42,8 @@ from SCons.Tool.MSCommon.sdk import mssdk_exists, \ from SCons.Tool.MSCommon.vc import msvc_exists, \ msvc_setup_env, \ msvc_setup_env_once, \ - msvc_version_to_maj_min + msvc_version_to_maj_min, \ + msvc_find_vswhere from SCons.Tool.MSCommon.vs import get_default_version, \ get_vs_by_version, \ diff --git a/src/engine/SCons/Tool/MSCommon/vc.py b/src/engine/SCons/Tool/MSCommon/vc.py index f5a410f..ce1341d 100644 --- a/src/engine/SCons/Tool/MSCommon/vc.py +++ b/src/engine/SCons/Tool/MSCommon/vc.py @@ -323,7 +323,32 @@ def is_host_target_supported(host_target, msvc_version): return True -def find_vc_pdir_vswhere(msvc_version): +VSWHERE_PATHS = [os.path.join(p,'vswhere.exe') for p in [ + os.path.expandvars(r"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer"), + os.path.expandvars(r"%ProgramFiles%\Microsoft Visual Studio\Installer"), + os.path.expandvars(r"%ChocolateyInstall%\bin"), +]] + +def msvc_find_vswhere(): + """ + Find the location of vswhere + """ + # For bug 3333: support default location of vswhere for both + # 64 and 32 bit windows installs. + # For bug 3542: also accommodate not being on C: drive. + # NB: this gets called from testsuite on non-Windows platforms. + # Whether that makes sense or not, don't break it for those. + # TODO: requested to add a user-specified path to vswhere + # and have this routine set the same var if it finds it. + vswhere_path = None + for pf in VSWHERE_PATHS: + if os.path.exists(pf): + vswhere_path = pf + break + + return vswhere_path + +def find_vc_pdir_vswhere(msvc_version, env=None): """ Find the MSVC product directory using the vswhere program. @@ -338,26 +363,12 @@ def find_vc_pdir_vswhere(msvc_version): debug("Unknown version of MSVC: %s" % msvc_version) raise UnsupportedVersion("Unknown version %s" % msvc_version) - # For bug 3333: support default location of vswhere for both - # 64 and 32 bit windows installs. - # For bug 3542: also accommodate not being on C: drive. - # NB: this gets called from testsuite on non-Windows platforms. - # Whether that makes sense or not, don't break it for those. - # TODO: requested to add a user-specified path to vswhere - # and have this routine set the same var if it finds it. - pfpaths = [ - os.path.expandvars(r"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer"), - os.path.expandvars(r"%ProgramFiles%\Microsoft Visual Studio\Installer"), - os.path.expandvars(r"%ChocolateyInstall%\bin"), - ] - for pf in pfpaths: - vswhere_path = os.path.join(pf, "vswhere.exe") - if os.path.exists(vswhere_path): - break + if env is None or not env.get('VSWHERE'): + vswhere_path = msvc_find_vswhere() else: - # No vswhere on system, no install info available this way - return None + vswhere_path = env.subst('$VSWHERE') + debug('find_vc_pdir_vswhere(): VSWHERE = %s'%vswhere_path) vswhere_cmd = [ vswhere_path, "-products", "*", @@ -381,7 +392,7 @@ def find_vc_pdir_vswhere(msvc_version): return None -def find_vc_pdir(msvc_version): +def find_vc_pdir(env, msvc_version): """Find the MSVC product directory for the given version. Tries to look up the path using a registry key from the table @@ -412,7 +423,7 @@ def find_vc_pdir(msvc_version): try: comps = None if not key: - comps = find_vc_pdir_vswhere(msvc_version) + comps = find_vc_pdir_vswhere(msvc_version, env) if not comps: debug('find_vc_pdir_vswhere(): no VC found for version {}'.format(repr(msvc_version))) raise SCons.Util.WinError @@ -450,7 +461,7 @@ def find_batch_file(env,msvc_version,host_arch,target_arch): so use that and return an indication we don't need the argument we would have computed to run vcvarsall.bat. """ - pdir = find_vc_pdir(msvc_version) + pdir = find_vc_pdir(env, msvc_version) if pdir is None: raise NoVersionFound("No version of Visual Studio found") debug('find_batch_file() in {}'.format(pdir)) @@ -635,7 +646,7 @@ def get_installed_vcs(env=None): for ver in _VCVER: debug('trying to find VC %s' % ver) try: - VC_DIR = find_vc_pdir(ver) + VC_DIR = find_vc_pdir(env, ver) if VC_DIR: debug('found VC %s' % ver) if _check_cl_exists_in_vc_dir(env, VC_DIR, ver): diff --git a/src/engine/SCons/Tool/MSCommon/vcTests.py b/src/engine/SCons/Tool/MSCommon/vcTests.py index 09991f5..f5f7a44 100644 --- a/src/engine/SCons/Tool/MSCommon/vcTests.py +++ b/src/engine/SCons/Tool/MSCommon/vcTests.py @@ -24,6 +24,7 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" +import sys import os import os.path import unittest @@ -45,12 +46,42 @@ MSVCUnsupportedTargetArch = SCons.Tool.MSCommon.vc.MSVCUnsupportedTargetArch MS_TOOLS_VERSION='1.1.1' +class VswhereTestCase(unittest.TestCase): + @staticmethod + def _createVSWhere(path): + os.makedirs(os.path.dirname(path)) + with open(path, 'w') as f: + f.write("Created:%s"%f) + + def testDefaults(self): + """ + Verify that msvc_find_vswhere() find's files in the specified paths + """ + # import pdb; pdb.set_trace() + vswhere_dirs = [os.path.splitdrive(p)[1] for p in SCons.Tool.MSCommon.vc.VSWHERE_PATHS] + base_dir = test.workpath('fake_vswhere') + test_vswhere_dirs = [os.path.join(base_dir,d[1:]) for d in vswhere_dirs] + + SCons.Tool.MSCommon.vc.VSWHERE_PATHS = test_vswhere_dirs + for vsw in test_vswhere_dirs: + VswhereTestCase._createVSWhere(vsw) + find_path = SCons.Tool.MSCommon.vc.msvc_find_vswhere() + self.assertTrue(vsw == find_path, "Didn't find vswhere in %s found in %s"%(vsw, find_path)) + os.remove(vsw) + + # def specifiedVswherePathTest(self): + # "Verify that msvc.generate() respects VSWHERE Specified" + + + + + class MSVcTestCase(unittest.TestCase): @staticmethod def _createDummyCl(path, add_bin=True): """ - Creates a dummy cl.ex in the correct directory. + Creates a dummy cl.exe in the correct directory. It will create all missing parent directories as well Args: @@ -74,8 +105,6 @@ class MSVcTestCase(unittest.TestCase): ct.write('created') - - def runTest(self): """ Check that all proper HOST_PLATFORM and TARGET_PLATFORM are handled. diff --git a/src/engine/SCons/Tool/MSCommon/vs.py b/src/engine/SCons/Tool/MSCommon/vs.py index e13f52f..e71eb27 100644 --- a/src/engine/SCons/Tool/MSCommon/vs.py +++ b/src/engine/SCons/Tool/MSCommon/vs.py @@ -64,22 +64,22 @@ class VisualStudio(object): return None return batch_file - def find_vs_dir_by_vc(self): - SCons.Tool.MSCommon.vc.get_installed_vcs() - dir = SCons.Tool.MSCommon.vc.find_vc_pdir(self.vc_version) + def find_vs_dir_by_vc(self, env): + SCons.Tool.MSCommon.vc.get_installed_vcs(env) + dir = SCons.Tool.MSCommon.vc.find_vc_pdir(env, self.vc_version) if not dir: debug('find_vs_dir_by_vc(): no installed VC %s' % self.vc_version) return None return os.path.abspath(os.path.join(dir, os.pardir)) - def find_vs_dir_by_reg(self): + def find_vs_dir_by_reg(self, env): root = 'Software\\' if is_win64(): root = root + 'Wow6432Node\\' for key in self.hkeys: if key=='use_dir': - return self.find_vs_dir_by_vc() + return self.find_vs_dir_by_vc(env) key = root + key try: comps = read_reg(key) @@ -90,19 +90,19 @@ class VisualStudio(object): return comps return None - def find_vs_dir(self): + def find_vs_dir(self, env): """ Can use registry or location of VC to find vs dir First try to find by registry, and if that fails find via VC dir """ - vs_dir=self.find_vs_dir_by_reg() + vs_dir=self.find_vs_dir_by_reg(env) if not vs_dir: - vs_dir = self.find_vs_dir_by_vc() + vs_dir = self.find_vs_dir_by_vc(env) debug('find_vs_dir(): found VS in ' + str(vs_dir )) return vs_dir - def find_executable(self): - vs_dir = self.get_vs_dir() + def find_executable(self, env): + vs_dir = self.get_vs_dir(env) if not vs_dir: debug('find_executable(): no vs_dir ({})'.format(vs_dir)) return None @@ -121,21 +121,21 @@ class VisualStudio(object): self._cache['batch_file'] = batch_file return batch_file - def get_executable(self): + def get_executable(self, env=None): try: debug('get_executable using cache:%s'%self._cache['executable']) return self._cache['executable'] except KeyError: - executable = self.find_executable() + executable = self.find_executable(env) self._cache['executable'] = executable debug('get_executable not in cache:%s'%executable) return executable - def get_vs_dir(self): + def get_vs_dir(self, env): try: return self._cache['vs_dir'] except KeyError: - vs_dir = self.find_vs_dir() + vs_dir = self.find_vs_dir(env) self._cache['vs_dir'] = vs_dir return vs_dir @@ -413,7 +413,7 @@ for vs in SupportedVSList: InstalledVSList = None InstalledVSMap = None -def get_installed_visual_studios(): +def get_installed_visual_studios(env=None): global InstalledVSList global InstalledVSMap if InstalledVSList is None: @@ -421,7 +421,7 @@ def get_installed_visual_studios(): InstalledVSMap = {} for vs in SupportedVSList: debug('trying to find VS %s' % vs.version) - if vs.get_executable(): + if vs.get_executable(env): debug('found VS %s' % vs.version) InstalledVSList.append(vs) InstalledVSMap[vs.version] = vs @@ -472,8 +472,8 @@ def reset_installed_visual_studios(): # for variable, directory in env_tuple_list: # env.PrependENVPath(variable, directory) -def msvs_exists(): - return (len(get_installed_visual_studios()) > 0) +def msvs_exists(env=None): + return (len(get_installed_visual_studios(env)) > 0) def get_vs_by_version(msvs): global InstalledVSMap diff --git a/src/engine/SCons/Tool/linkloc.py b/src/engine/SCons/Tool/linkloc.py index c73852b..ad189b2 100644 --- a/src/engine/SCons/Tool/linkloc.py +++ b/src/engine/SCons/Tool/linkloc.py @@ -101,7 +101,7 @@ def generate(env): addPharLapPaths(env) def exists(env): - if msvs_exists(): + if msvs_exists(env): return env.Detect('linkloc') else: return 0 diff --git a/src/engine/SCons/Tool/msvc.py b/src/engine/SCons/Tool/msvc.py index 05a20e0..463e372 100644 --- a/src/engine/SCons/Tool/msvc.py +++ b/src/engine/SCons/Tool/msvc.py @@ -48,7 +48,7 @@ import SCons.Util import SCons.Warnings import SCons.Scanner.RC -from .MSCommon import msvc_exists, msvc_setup_env_once, msvc_version_to_maj_min +from .MSCommon import msvc_exists, msvc_setup_env_once, msvc_version_to_maj_min, msvc_find_vswhere CSuffixes = ['.c', '.C'] CXXSuffixes = ['.cc', '.cpp', '.cxx', '.c++', '.C++'] @@ -277,6 +277,9 @@ def generate(env): # without it for lex generation env["LEXUNISTD"] = SCons.Util.CLVar("--nounistd") + # Get user specified vswhere location or locate. + env['VSWHERE'] = env.get('VSWHERE', msvc_find_vswhere()) + # Set-up ms tools paths msvc_setup_env_once(env) diff --git a/src/engine/SCons/Tool/msvc.xml b/src/engine/SCons/Tool/msvc.xml index 100c84c..bdbf253 100644 --- a/src/engine/SCons/Tool/msvc.xml +++ b/src/engine/SCons/Tool/msvc.xml @@ -475,4 +475,38 @@ Valid values are '1' or '0' + + + +Specify the location of vswhere.exe. + + + +vswhere.exe is used to locate MSVC/MSVS installations. +It was initially distributed with MSVS 2017. But can detect MSVC 2010 and newer with -legacy argument. +If &cv-VSWHERE; is set, SCons will use that location. + + +Otherwise SCons will look in the following locations and set VSWHERE to the PATH vswhere.exe +is located. + + +Note that &cv-VSWHERE; must be set in when tool msvc is initialized. This is either in the call to +Environment(VSWHERE='c:/my/path/to/vswhere') or +if Environment created specifying not to automatically initialize any tools or tools which doesn't include msvc or MSVS +such as Environment(Tools=[]) + + + + + +%ProgramFiles(x86)%\Microsoft Visual Studio\Installer +"%ProgramFiles%\Microsoft Visual Studio\Installer +%ChocolateyInstall%\bin + + + + + + diff --git a/src/engine/SCons/Tool/msvsTests.py b/src/engine/SCons/Tool/msvsTests.py index b3373ea..1bacc2c 100644 --- a/src/engine/SCons/Tool/msvsTests.py +++ b/src/engine/SCons/Tool/msvsTests.py @@ -580,7 +580,7 @@ def DummyQueryValue(key, value): def DummyExists(path): return 1 -def DummyVsWhere(msvc_version): +def DummyVsWhere(msvc_version, env): # not testing versions with vswhere, so return none return None diff --git a/src/script/scons.bat b/src/script/scons.bat index 10b8637..1031929 100644 --- a/src/script/scons.bat +++ b/src/script/scons.bat @@ -1,11 +1,11 @@ @REM __COPYRIGHT__ @REM __FILE__ __REVISION__ __DATE__ __DEVELOPER__ -@echo off +@REM echo off set SCONS_ERRORLEVEL= if "%OS%" == "Windows_NT" goto WinNT @REM for 9x/Me you better not have more than 9 args -python -c "from os.path import join; import sys; sys.path = [ join(sys.prefix, 'Lib', 'site-packages', 'scons-__VERSION__'), join(sys.prefix, 'Lib', 'site-packages', 'scons'), join(sys.prefix, 'scons-__VERSION__'), join(sys.prefix, 'scons')] + sys.path; import SCons.Script; SCons.Script.main()" %1 %2 %3 %4 %5 %6 %7 %8 %9 +py -c "from os.path import join; import sys; sys.path = [ join(sys.prefix, 'Lib', 'site-packages', 'scons-__VERSION__'), join(sys.prefix, 'Lib', 'site-packages', 'scons'), join(sys.prefix, 'scons-__VERSION__'), join(sys.prefix, 'scons')] + sys.path; import SCons.Script; SCons.Script.main()" %1 %2 %3 %4 %5 %6 %7 %8 %9 @REM no way to set exit status of this script for 9x/Me goto endscons @@ -24,7 +24,7 @@ set scriptname=%~dp0%~n0.py if not exist "%scriptname%" set scriptname=%~dp0Scripts\%~n0.py @REM Handle when running from wheel where the script has no .py extension if not exist "%scriptname%" set scriptname=%~dp0%~n0 -python "%scriptname%" %* +py "%scriptname%" %* endlocal & set SCONS_ERRORLEVEL=%ERRORLEVEL% if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto returncode diff --git a/test/Win32/scons-bat-error.py b/test/Win32/scons-bat-error.py index d772132..4d5d00c 100644 --- a/test/Win32/scons-bat-error.py +++ b/test/Win32/scons-bat-error.py @@ -39,7 +39,7 @@ if sys.platform != 'win32': msg = "Skipping scons.bat test on non-Windows platform '%s'\n" % sys.platform test.skip_test(msg) -python = test.where_is('python') +python = sys.executable #test.where_is('python') if not python: msg = "Skipping scons.bat test; python is not on %PATH%.\n" diff --git a/test/fixture/no_msvc/no_msvcs_sconstruct.py b/test/fixture/no_msvc/no_msvcs_sconstruct.py index e0b59e6..11a06ac 100644 --- a/test/fixture/no_msvc/no_msvcs_sconstruct.py +++ b/test/fixture/no_msvc/no_msvcs_sconstruct.py @@ -1,7 +1,7 @@ import SCons import SCons.Tool.MSCommon -def DummyVsWhere(msvc_version): +def DummyVsWhere(env, msvc_version): # not testing versions with vswhere, so return none return None -- cgit v0.12 From 4d582eed59c08a9cb42dbcebf4bb89261cc01b48 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Fri, 10 Apr 2020 15:23:33 -0700 Subject: restore scons.bat to original --- src/script/scons.bat | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/script/scons.bat b/src/script/scons.bat index 1031929..10b8637 100644 --- a/src/script/scons.bat +++ b/src/script/scons.bat @@ -1,11 +1,11 @@ @REM __COPYRIGHT__ @REM __FILE__ __REVISION__ __DATE__ __DEVELOPER__ -@REM echo off +@echo off set SCONS_ERRORLEVEL= if "%OS%" == "Windows_NT" goto WinNT @REM for 9x/Me you better not have more than 9 args -py -c "from os.path import join; import sys; sys.path = [ join(sys.prefix, 'Lib', 'site-packages', 'scons-__VERSION__'), join(sys.prefix, 'Lib', 'site-packages', 'scons'), join(sys.prefix, 'scons-__VERSION__'), join(sys.prefix, 'scons')] + sys.path; import SCons.Script; SCons.Script.main()" %1 %2 %3 %4 %5 %6 %7 %8 %9 +python -c "from os.path import join; import sys; sys.path = [ join(sys.prefix, 'Lib', 'site-packages', 'scons-__VERSION__'), join(sys.prefix, 'Lib', 'site-packages', 'scons'), join(sys.prefix, 'scons-__VERSION__'), join(sys.prefix, 'scons')] + sys.path; import SCons.Script; SCons.Script.main()" %1 %2 %3 %4 %5 %6 %7 %8 %9 @REM no way to set exit status of this script for 9x/Me goto endscons @@ -24,7 +24,7 @@ set scriptname=%~dp0%~n0.py if not exist "%scriptname%" set scriptname=%~dp0Scripts\%~n0.py @REM Handle when running from wheel where the script has no .py extension if not exist "%scriptname%" set scriptname=%~dp0%~n0 -py "%scriptname%" %* +python "%scriptname%" %* endlocal & set SCONS_ERRORLEVEL=%ERRORLEVEL% if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto returncode -- cgit v0.12 From 067ac2b4b793bd45cb3595ef311553ede59aa236 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Fri, 10 Apr 2020 20:36:24 -0700 Subject: Fix tar bz2 test so it won't crash when no bzip2 is present --- test/packaging/tar/bz2_packaging.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/packaging/tar/bz2_packaging.py b/test/packaging/tar/bz2_packaging.py index 3c1afe3..0c8dcea 100644 --- a/test/packaging/tar/bz2_packaging.py +++ b/test/packaging/tar/bz2_packaging.py @@ -44,7 +44,6 @@ if not tar: test.skip_test('tar not found, skipping test\n') bz2 = test.where_is('bzip2') -bz2_path = os.path.dirname(bz2) if sys.platform == 'win32': # windows 10 causes fresh problems by supplying a tar, not bzip2 @@ -56,6 +55,9 @@ if sys.platform == 'win32': if tar[:8] != bz2[:8]: # catch one in \WINDOWS, one not test.skip_test('tar found, but usable bzip2 not, skipping test\n') +bz2_path = os.path.dirname(bz2) + + test.subdir('src') test.write([ 'src', 'main.c'], r""" -- cgit v0.12 From b2596f777bbcc6cea3d792dd4cbfa580981cb93b Mon Sep 17 00:00:00 2001 From: William Deegan Date: Fri, 10 Apr 2020 20:58:04 -0700 Subject: don't change eol on .in files --- .gitattributes | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitattributes b/.gitattributes index 089d31b..54fb67f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4,3 +4,4 @@ src/engine/SCons/Tool/docbook/docbook-xsl-1.76.1 linguist-vendored *.xsl linguist-documentation *.gen linguist-documentation +*.in eol=lf -- cgit v0.12 From b94470116ca5cb31cb9f9737adf24ea9b69b0f55 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Sat, 11 Apr 2020 17:08:05 -0700 Subject: Address PR comments --- src/engine/SCons/Tool/MSCommon/vc.py | 2 -- src/engine/SCons/Tool/msvc.xml | 10 +++++----- test/Win32/scons-bat-error.py | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/engine/SCons/Tool/MSCommon/vc.py b/src/engine/SCons/Tool/MSCommon/vc.py index ce1341d..456ccae 100644 --- a/src/engine/SCons/Tool/MSCommon/vc.py +++ b/src/engine/SCons/Tool/MSCommon/vc.py @@ -338,8 +338,6 @@ def msvc_find_vswhere(): # For bug 3542: also accommodate not being on C: drive. # NB: this gets called from testsuite on non-Windows platforms. # Whether that makes sense or not, don't break it for those. - # TODO: requested to add a user-specified path to vswhere - # and have this routine set the same var if it finds it. vswhere_path = None for pf in VSWHERE_PATHS: if os.path.exists(pf): diff --git a/src/engine/SCons/Tool/msvc.xml b/src/engine/SCons/Tool/msvc.xml index bdbf253..3e8ec95 100644 --- a/src/engine/SCons/Tool/msvc.xml +++ b/src/engine/SCons/Tool/msvc.xml @@ -487,14 +487,14 @@ It was initially distributed with MSVS 2017. But can detect MSVC 2010 and newer If &cv-VSWHERE; is set, SCons will use that location. -Otherwise SCons will look in the following locations and set VSWHERE to the PATH vswhere.exe -is located. +Otherwise SCons will look in the following locations and set VSWHERE to the first directory vswhere.exe +is found. -Note that &cv-VSWHERE; must be set in when tool msvc is initialized. This is either in the call to +Note that &cv-VSWHERE; must be set at the same time or prior to the msvc tool being initialized. So either set it as follows Environment(VSWHERE='c:/my/path/to/vswhere') or -if Environment created specifying not to automatically initialize any tools or tools which doesn't include msvc or MSVS -such as Environment(Tools=[]) +if your Environment() is created specifying no tools tools=[] or with a list of tools not including msvs or msvc or mslink + such as Environment(Tools=[]) diff --git a/test/Win32/scons-bat-error.py b/test/Win32/scons-bat-error.py index 4d5d00c..d772132 100644 --- a/test/Win32/scons-bat-error.py +++ b/test/Win32/scons-bat-error.py @@ -39,7 +39,7 @@ if sys.platform != 'win32': msg = "Skipping scons.bat test on non-Windows platform '%s'\n" % sys.platform test.skip_test(msg) -python = sys.executable #test.where_is('python') +python = test.where_is('python') if not python: msg = "Skipping scons.bat test; python is not on %PATH%.\n" -- cgit v0.12 From afc8807fcc940e9b31043b1cdca68fd29c23719c Mon Sep 17 00:00:00 2001 From: William Deegan Date: Sun, 12 Apr 2020 15:53:59 -0700 Subject: Address comments on PR for docs --- src/engine/SCons/Tool/msvc.xml | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/engine/SCons/Tool/msvc.xml b/src/engine/SCons/Tool/msvc.xml index 3e8ec95..48ce13f 100644 --- a/src/engine/SCons/Tool/msvc.xml +++ b/src/engine/SCons/Tool/msvc.xml @@ -482,14 +482,23 @@ Specify the location of vswhere.exe. -vswhere.exe is used to locate MSVC/MSVS installations. -It was initially distributed with MSVS 2017. But can detect MSVC 2010 and newer with -legacy argument. +Propose: The vswhere command is distributed with Microsoft Visual Studio and Build + Tools since the 2017 edition, but is also available standalone. It fully detects 2017 and later editions, + but with the argument, can detect installations of the 2010 through 2015 + editions with limited data returned. If &cv-VSWHERE; is set, SCons will use that location. -Otherwise SCons will look in the following locations and set VSWHERE to the first directory vswhere.exe -is found. + Otherwise SCons will look in the following locations and set &cv-VSWHERE; to the path of the first vswhere.exe +located. + + +%ProgramFiles(x86)%\Microsoft Visual Studio\Installer +"%ProgramFiles%\Microsoft Visual Studio\Installer +%ChocolateyInstall%\bin + + Note that &cv-VSWHERE; must be set at the same time or prior to the msvc tool being initialized. So either set it as follows Environment(VSWHERE='c:/my/path/to/vswhere') or @@ -499,11 +508,7 @@ if your Environment() is created specifying no tools tools=[] - -%ProgramFiles(x86)%\Microsoft Visual Studio\Installer -"%ProgramFiles%\Microsoft Visual Studio\Installer -%ChocolateyInstall%\bin - + -- cgit v0.12 From 5c8ff63775a475510dc9fd555b99bdf0bf319d79 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Sun, 12 Apr 2020 15:54:28 -0700 Subject: If no vswhere.exe is found, do not try to run it. Was breaking tests on non-win32 --- src/engine/SCons/Tool/MSCommon/vc.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/engine/SCons/Tool/MSCommon/vc.py b/src/engine/SCons/Tool/MSCommon/vc.py index 456ccae..58be07c 100644 --- a/src/engine/SCons/Tool/MSCommon/vc.py +++ b/src/engine/SCons/Tool/MSCommon/vc.py @@ -366,6 +366,9 @@ def find_vc_pdir_vswhere(msvc_version, env=None): else: vswhere_path = env.subst('$VSWHERE') + if vswhere_path is None: + return None + debug('find_vc_pdir_vswhere(): VSWHERE = %s'%vswhere_path) vswhere_cmd = [ vswhere_path, @@ -374,6 +377,8 @@ def find_vc_pdir_vswhere(msvc_version, env=None): "-property", "installationPath", ] + debug("find_vc_pdir_vswhere(): running: %s" % vswhere_cmd) + #cp = subprocess.run(vswhere_cmd, capture_output=True) # 3.7+ only cp = subprocess.run(vswhere_cmd, stdout=PIPE, stderr=PIPE) -- cgit v0.12 From c82e9618c97b084f8c385ae55637d3ac6cf2ed2a Mon Sep 17 00:00:00 2001 From: William Deegan Date: Sun, 12 Apr 2020 15:57:56 -0700 Subject: resolve sider issue. import sys not needed --- src/engine/SCons/Tool/MSCommon/vcTests.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/engine/SCons/Tool/MSCommon/vcTests.py b/src/engine/SCons/Tool/MSCommon/vcTests.py index f5f7a44..3474887 100644 --- a/src/engine/SCons/Tool/MSCommon/vcTests.py +++ b/src/engine/SCons/Tool/MSCommon/vcTests.py @@ -24,7 +24,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" -import sys import os import os.path import unittest -- cgit v0.12 From 9c295184d3efbaff6d24d656f503f3ee1fb380b8 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Sun, 12 Apr 2020 17:57:00 -0700 Subject: fix vcTests.py creating already existing dir on win32 --- src/engine/SCons/Tool/MSCommon/vcTests.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/engine/SCons/Tool/MSCommon/vcTests.py b/src/engine/SCons/Tool/MSCommon/vcTests.py index 3474887..884e90e 100644 --- a/src/engine/SCons/Tool/MSCommon/vcTests.py +++ b/src/engine/SCons/Tool/MSCommon/vcTests.py @@ -48,7 +48,8 @@ MS_TOOLS_VERSION='1.1.1' class VswhereTestCase(unittest.TestCase): @staticmethod def _createVSWhere(path): - os.makedirs(os.path.dirname(path)) + if not os.path.isdir(os.path.dirname(path)): + os.makedirs(os.path.dirname(path)) with open(path, 'w') as f: f.write("Created:%s"%f) -- cgit v0.12 From c69043c502044994840e246d8c4926a15b7d2bdb Mon Sep 17 00:00:00 2001 From: William Deegan Date: Sun, 12 Apr 2020 19:37:01 -0700 Subject: We're all py3 now can use exist_ok=True on os.mkdirs(). Thanks mwichmann --- src/engine/SCons/Tool/MSCommon/vcTests.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/engine/SCons/Tool/MSCommon/vcTests.py b/src/engine/SCons/Tool/MSCommon/vcTests.py index 884e90e..eb09def 100644 --- a/src/engine/SCons/Tool/MSCommon/vcTests.py +++ b/src/engine/SCons/Tool/MSCommon/vcTests.py @@ -48,8 +48,7 @@ MS_TOOLS_VERSION='1.1.1' class VswhereTestCase(unittest.TestCase): @staticmethod def _createVSWhere(path): - if not os.path.isdir(os.path.dirname(path)): - os.makedirs(os.path.dirname(path)) + os.makedirs(os.path.dirname(path), exist_ok=True) with open(path, 'w') as f: f.write("Created:%s"%f) -- cgit v0.12 From c0e9c494d9dd441627047d462a2c22e8c2beeb9f Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 21 Apr 2020 11:17:06 -0700 Subject: [ci skip] Update docs --- src/engine/SCons/Tool/msvc.xml | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/engine/SCons/Tool/msvc.xml b/src/engine/SCons/Tool/msvc.xml index 48ce13f..bdde91b 100644 --- a/src/engine/SCons/Tool/msvc.xml +++ b/src/engine/SCons/Tool/msvc.xml @@ -482,7 +482,7 @@ Specify the location of vswhere.exe. -Propose: The vswhere command is distributed with Microsoft Visual Studio and Build + The vswhere command is distributed with Microsoft Visual Studio and Build Tools since the 2017 edition, but is also available standalone. It fully detects 2017 and later editions, but with the argument, can detect installations of the 2010 through 2015 editions with limited data returned. @@ -501,9 +501,19 @@ located. Note that &cv-VSWHERE; must be set at the same time or prior to the msvc tool being initialized. So either set it as follows -Environment(VSWHERE='c:/my/path/to/vswhere') or -if your Environment() is created specifying no tools tools=[] or with a list of tools not including msvs or msvc or mslink - such as Environment(Tools=[]) + + +env = Environment(VSWHERE='c:/my/path/to/vswhere') + + +or if your Environment() is created specifying no tools +tools=[] +or with a list of tools not including msvs or msvc or mslink such as + + env = Environment(Tools=[]) + env['VSWHERE'] = r'c:/my/vswhere/install/location/vswhere.exe' + env.Tool() + -- cgit v0.12 From 735bd26ddff03d49544287b16996d8cd456c072f Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 21 Apr 2020 14:07:39 -0700 Subject: [ci skip] Doc updates --- src/engine/SCons/Tool/msvc.xml | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/engine/SCons/Tool/msvc.xml b/src/engine/SCons/Tool/msvc.xml index bdde91b..97de279 100644 --- a/src/engine/SCons/Tool/msvc.xml +++ b/src/engine/SCons/Tool/msvc.xml @@ -478,48 +478,48 @@ Valid values are '1' or '0' -Specify the location of vswhere.exe. +Specify the location of vswhere.exe. - The vswhere command is distributed with Microsoft Visual Studio and Build - Tools since the 2017 edition, but is also available standalone. It fully detects 2017 and later editions, - but with the argument, can detect installations of the 2010 through 2015 + The vswhere.exe executable is distributed with Microsoft Visual Studio and Build + Tools since the 2017 edition, but is also available standalone. + It provides full information about installations of 2017 and later editions. + With the argument, vswhere.exe can detect installations of the 2010 through 2015 editions with limited data returned. -If &cv-VSWHERE; is set, SCons will use that location. +If VSWHERE is set, SCons will use that location. - Otherwise SCons will look in the following locations and set &cv-VSWHERE; to the path of the first vswhere.exe + Otherwise SCons will look in the following locations and set VSWHERE to the path of the first vswhere.exe located. -%ProgramFiles(x86)%\Microsoft Visual Studio\Installer -"%ProgramFiles%\Microsoft Visual Studio\Installer -%ChocolateyInstall%\bin +%ProgramFiles(x86)%\Microsoft Visual Studio\Installer +%ProgramFiles%\Microsoft Visual Studio\Installer +%ChocolateyInstall%\bin -Note that &cv-VSWHERE; must be set at the same time or prior to the msvc tool being initialized. So either set it as follows + Note that VSWHERE must be set at the same time or prior to any of &t-link-msvc;, &t-link-msvs; , and/or &t-link-mslink; &f-link-Tool; being initialized. + Either set it as follows env = Environment(VSWHERE='c:/my/path/to/vswhere') -or if your Environment() is created specifying no tools +or if your &f-link-Environment; is created specifying no tools tools=[] -or with a list of tools not including msvs or msvc or mslink such as +or with an empty list of tools or with a list of tools which doesn't include &t-link-default;, &t-link-msvs;, &t-link-msvc; or &t-link-mslink;. - env = Environment(Tools=[]) + env = Environment(tools=[]) env['VSWHERE'] = r'c:/my/vswhere/install/location/vswhere.exe' - env.Tool() + env.Tool('msvc') + env.Tool('mslink') + env.Tool('msvs') - - - - -- cgit v0.12 From 3fed7a63425265d3151f52515fdbd4f62867e57d Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 21 Apr 2020 17:23:58 -0700 Subject: [ci skip] updated wording for VSWHERE --- src/engine/SCons/Tool/msvc.xml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/engine/SCons/Tool/msvc.xml b/src/engine/SCons/Tool/msvc.xml index 97de279..e92fa9b 100644 --- a/src/engine/SCons/Tool/msvc.xml +++ b/src/engine/SCons/Tool/msvc.xml @@ -508,10 +508,11 @@ located. env = Environment(VSWHERE='c:/my/path/to/vswhere') -or if your &f-link-Environment; is created specifying no tools -tools=[] -or with an empty list of tools or with a list of tools which doesn't include &t-link-default;, &t-link-msvs;, &t-link-msvc; or &t-link-mslink;. - +or if your &consenv; is created specifying an empty tools list +(or a list of tools which omits all of default, msvs, msvc, and mslink), +and also before &f-link-env-Tool; is called to ininitialize any of those tools: + + env = Environment(tools=[]) env['VSWHERE'] = r'c:/my/vswhere/install/location/vswhere.exe' env.Tool('msvc') -- cgit v0.12 From 7ec2c76c12d1254c2c31a20d15ae5c39540adb3e Mon Sep 17 00:00:00 2001 From: William Deegan Date: Wed, 22 Apr 2020 17:17:24 -0700 Subject: Add system test for setting and retrieving VSWHERE --- test/MSVC/VSWHERE-fixture/SConstruct | 22 ++++++++ test/MSVC/VSWHERE.py | 101 +++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 test/MSVC/VSWHERE-fixture/SConstruct create mode 100644 test/MSVC/VSWHERE.py diff --git a/test/MSVC/VSWHERE-fixture/SConstruct b/test/MSVC/VSWHERE-fixture/SConstruct new file mode 100644 index 0000000..38dfb0b --- /dev/null +++ b/test/MSVC/VSWHERE-fixture/SConstruct @@ -0,0 +1,22 @@ +import os +import os.path + +from SCons.Tool.MSCommon.vc import VSWHERE_PATHS + +# Dump out expected paths +for vw_path in VSWHERE_PATHS: + print("VSWHERE_PATH=%s"%vw_path) + + +# Allow normal detection logic to find vswhere.exe +env1=Environment() +print("VSWHERE-detect=%s" % env1['VSWHERE']) + +# Copy found vswhere.exe to current dir +v_local = os.path.join(os.getcwd(), 'vswhere.exe') +Execute(Copy(os.path.join(os.getcwd(), 'vswhere.exe'), env1['VSWHERE'])) + +# With VSWHERE set to copied vswhere.exe (see above), find vswhere.exe +env=Environment(VSWHERE=v_local) +print("VSWHERE-env=%s" % env['VSWHERE']) + diff --git a/test/MSVC/VSWHERE.py b/test/MSVC/VSWHERE.py new file mode 100644 index 0000000..0d6b991 --- /dev/null +++ b/test/MSVC/VSWHERE.py @@ -0,0 +1,101 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# 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. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Test the ability to configure the $VSWHERE construction variable. +Also test that vswhere.exe is found and sets VSWHERE to the correct values +""" +import os.path +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() +test.verbose_set(1) + +test.skip_if_not_msvc() +test.dir_fixture('VSWHERE-fixture') + +test.run(arguments=".") + +# Now grab info out of stdout +lines = test.stdout().splitlines() + +# Debug code +# print("LINES:\n%s" % lines) + +default_locations = [] +detected_path = None +env_path = None +for l in lines: + if 'VSWHERE_PATH' in l: + path = l.strip().split('=')[-1] + default_locations.append(path) + elif 'VSWHERE-detect' in l: + detected_path = l.strip().split('=')[-1] + elif 'VSWHERE-env' in l: + env_path = l.strip().split('=')[-1] + +# Debug code +# print("VPP:%s" % default_locations) +# print("V-D:%s" % detected_path) +# print("V-E:%s" % env_path) + + +test.fail_test(len(default_locations) == 0, + message='No default vswhere.exe locations found') +test.fail_test( + detected_path is None, message='No vswhere.exe detected in default paths :%s' % default_locations) +test.fail_test(detected_path not in default_locations, + message='detected path [%s] not in default locations[%s]' % (detected_path, default_locations)) + +expected_env_path = os.path.join(test.workdir, 'vswhere.exe') +test.fail_test(env_path != expected_env_path, + message='VSWHERE not\n\t%s\n\t but\n\t%s' % (expected_env_path, env_path)) + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: + +expected = r""" +PS C:\Users\Bill\AppData\Local\Temp\testcmd.11256.1ae1_as5> py -3.8 C:\Users\Bill\devel\scons\git\scons-2\scripts\scons.py +scons: Reading SConscript files ... +VSWHERE_PATH=C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe +VSWHERE_PATH=C:\Program Files\Microsoft Visual Studio\Installer\vswhere.exe +VSWHERE_PATH=C:\ProgramData\chocolatey\bin\vswhere.exe +VSWHERE-detect=C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe +Copy("C:\Users\Bill\AppData\Local\Temp\testcmd.11256.1ae1_as5\vswhere.exe", "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe") +VSWHERE-env=C:\Users\Bill\AppData\Local\Temp\testcmd.11256.1ae1_as5\vswhere.exe +scons: done reading SConscript files. +scons: Building targets ... +scons: `.' is up to date. +scons: done building targets. +""" -- cgit v0.12