summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoseph Brill <48932340+jcbrill@users.noreply.github.com>2022-04-12 14:20:49 (GMT)
committerJoseph Brill <48932340+jcbrill@users.noreply.github.com>2022-04-12 14:20:49 (GMT)
commitf338fee76045f94e78f25f15fea1d4bf33786d6e (patch)
tree82fcbc25fcc5546db4ac2e540a07fc20117dc97c
parent8fca5898da15fe1b3f4f87fc35bed34c236e74cb (diff)
downloadSCons-f338fee76045f94e78f25f15fea1d4bf33786d6e.zip
SCons-f338fee76045f94e78f25f15fea1d4bf33786d6e.tar.gz
SCons-f338fee76045f94e78f25f15fea1d4bf33786d6e.tar.bz2
Raise MSVCVersionNotFound exception instead of returning an empty/undefined dictionary when attempting to find a valid msvc batch script. Raise an MSVCVersionNotFound exception when the default msvc version is requested and there are no msvc versions installed. Suppress raising an MSVCVersionNotFound exception during default msvc tool initialization. Add additional tests.
-rw-r--r--SCons/Tool/MSCommon/vc.py36
-rw-r--r--test/MSVC/msvc_badversion.py59
-rw-r--r--test/MSVC/no_msvc.py26
-rw-r--r--test/fixture/no_msvc/no_msvcs_sconstruct.py1
-rw-r--r--test/fixture/no_msvc/no_msvcs_sconstruct_tools.py14
-rw-r--r--test/fixture/no_msvc/no_msvcs_sconstruct_version.py14
6 files changed, 138 insertions, 12 deletions
diff --git a/SCons/Tool/MSCommon/vc.py b/SCons/Tool/MSCommon/vc.py
index 3373301..d9a6e50 100644
--- a/SCons/Tool/MSCommon/vc.py
+++ b/SCons/Tool/MSCommon/vc.py
@@ -79,6 +79,9 @@ class BatchFileExecutionError(VisualCException):
class MSVCScriptNotFound(VisualCException):
pass
+class MSVCVersionNotFound(VisualCException):
+ pass
+
# Dict to 'canonalize' the arch
_ARCH_TO_CANONICAL = {
"amd64" : "amd64",
@@ -853,6 +856,7 @@ def msvc_find_valid_batch_script(env, version):
debug("host_platform: %s, try_target_archs: %s", host_platform, try_target_archs)
d = None
+ version_installed = False
for tp in try_target_archs:
# Set to current arch.
env['TARGET_ARCH'] = tp
@@ -869,14 +873,11 @@ def msvc_find_valid_batch_script(env, version):
try:
(vc_script, use_arg, sdk_script) = find_batch_file(env, version, host_platform, tp)
debug('vc_script:%s sdk_script:%s', vc_script, sdk_script)
+ version_installed = True
except VisualCException as e:
msg = str(e)
debug('Caught exception while looking for batch file (%s)', msg)
- warn_msg = "VC version %s not installed. " + \
- "C/C++ compilers are most likely not set correctly.\n" + \
- " Installed versions are: %s"
- warn_msg = warn_msg % (version, get_installed_vcs(env))
- SCons.Warnings.warn(SCons.Warnings.VisualCMissingWarning, warn_msg)
+ version_installed = False
continue
# Try to use the located batch file for this host/target platform combo
@@ -919,6 +920,25 @@ def msvc_find_valid_batch_script(env, version):
# To it's initial value
if not d:
env['TARGET_ARCH']=req_target_platform
+ installed_vcs = get_installed_vcs(env)
+ if version_installed:
+ err_msg = "MSVC version {} working host/target script was not found.\n" \
+ " Host = {}, Target = {}\n" \
+ " Visual Studio C/C++ compilers may not be set correctly".format(
+ version, host_platform, target_platform
+ )
+ elif version and installed_vcs:
+ err_msg = "MSVC version {} was not found.\n" \
+ " Visual Studio C/C++ compilers may not be set correctly.\n" \
+ " Installed versions are: {}".format(version, installed_vcs)
+ elif version:
+ err_msg = "MSVC version {} was not found.\n" \
+ " No versions of the MSVC compiler were found.\n" \
+ " Visual Studio C/C++ compilers may not be set correctly".format(version)
+ else:
+ err_msg = "No versions of the MSVC compiler were found.\n" \
+ " Visual Studio C/C++ compilers may not be set correctly"
+ raise MSVCVersionNotFound(err_msg)
return d
@@ -930,9 +950,9 @@ def msvc_setup_env(env):
version = get_default_version(env)
if version is None:
if __MSVC_SETUP_ENV_DEFAULT:
- warn_msg = "No version of Visual Studio compiler found - C/C++ " \
- "compilers most likely not set correctly"
- SCons.Warnings.warn(SCons.Warnings.VisualCMissingWarning, warn_msg)
+ err_msg = "No versions of the MSVC compiler were found.\n" \
+ " Visual Studio C/C++ compilers may not be set correctly"
+ raise MSVCVersionNotFound(err_msg)
__MSVC_SETUP_ENV_DEFAULT = True
return None
diff --git a/test/MSVC/msvc_badversion.py b/test/MSVC/msvc_badversion.py
new file mode 100644
index 0000000..7af8ca5
--- /dev/null
+++ b/test/MSVC/msvc_badversion.py
@@ -0,0 +1,59 @@
+#!/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 scons with an invalid MSVC version when at least one MSVC is present.
+"""
+
+import sys
+
+import TestSCons
+import SCons.Tool.MSCommon.vc as msvc
+
+test = TestSCons.TestSCons()
+
+if sys.platform != 'win32':
+ test.skip_test("Not win32 platform. Skipping test\n")
+
+test.skip_if_not_msvc()
+
+installed_msvc_versions = msvc.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
+
+test.write('SConstruct', """\
+env = Environment(MSVC_VERSION='12.9')
+""")
+
+test.run(arguments='-Q -s', status=2, stderr=r"^.*MSVCVersionNotFound.+", match=TestSCons.match_re_dotall)
+
+test.pass_test()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/test/MSVC/no_msvc.py b/test/MSVC/no_msvc.py
index d1161c6..b6442e8 100644
--- a/test/MSVC/no_msvc.py
+++ b/test/MSVC/no_msvc.py
@@ -43,9 +43,29 @@ test.run(arguments='-Q -s', stdout='')
# test no msvc's
test.file_fixture('no_msvc/no_msvcs_sconstruct.py', 'SConstruct')
+test.run(arguments='-Q -s', status=2, stderr=r"^.*MSVCVersionNotFound.+", match=TestSCons.match_re_dotall)
+
+# test msvc version number request with no msvc's
+test.file_fixture('no_msvc/no_msvcs_sconstruct_version.py', 'SConstruct')
+test.run(arguments='-Q -s', status=2, stderr=r"^.*MSVCVersionNotFound.+", match=TestSCons.match_re_dotall)
+
+# test that MSVCVersionNotFound is not raised for default msvc tools
+# when a non-msvc tool list is used
+test.subdir('site_scons', ['site_scons', 'site_tools'])
+
+test.write(['site_scons', 'site_tools', 'myignoredefaultmsvctool.py'], """
+import SCons.Tool
+def generate(env):
+ env['MYIGNOREDEFAULTMSVCTOOL']='myignoredefaultmsvctool'
+def exists(env):
+ return 1
+""")
+
+test.file_fixture('no_msvc/no_msvcs_sconstruct_tools.py', 'SConstruct')
+test.run(arguments='-Q -s')
+
+test.file_fixture('no_msvc/no_msvcs_sconstruct_tools.py', 'SConstruct')
test.run(arguments='-Q -s')
-if 'MSVC_VERSION=None' not in test.stdout():
- test.fail_test()
+test.pass_test()
-test.pass_test() \ No newline at end of file
diff --git a/test/fixture/no_msvc/no_msvcs_sconstruct.py b/test/fixture/no_msvc/no_msvcs_sconstruct.py
index 18366d8..590142b 100644
--- a/test/fixture/no_msvc/no_msvcs_sconstruct.py
+++ b/test/fixture/no_msvc/no_msvcs_sconstruct.py
@@ -12,4 +12,3 @@ SCons.Tool.MSCommon.vc.find_vc_pdir_vswhere = DummyVsWhere
env = SCons.Environment.Environment()
-print('MSVC_VERSION='+str(env.get('MSVC_VERSION'))) \ No newline at end of file
diff --git a/test/fixture/no_msvc/no_msvcs_sconstruct_tools.py b/test/fixture/no_msvc/no_msvcs_sconstruct_tools.py
new file mode 100644
index 0000000..ca9b699
--- /dev/null
+++ b/test/fixture/no_msvc/no_msvcs_sconstruct_tools.py
@@ -0,0 +1,14 @@
+import SCons
+import SCons.Tool.MSCommon
+
+def DummyVsWhere(msvc_version, env):
+ # not testing versions with vswhere, so return none
+ return None
+
+for key in SCons.Tool.MSCommon.vc._VCVER_TO_PRODUCT_DIR:
+ SCons.Tool.MSCommon.vc._VCVER_TO_PRODUCT_DIR[key]=[(SCons.Util.HKEY_LOCAL_MACHINE, r'')]
+
+SCons.Tool.MSCommon.vc.find_vc_pdir_vswhere = DummyVsWhere
+
+env = SCons.Environment.Environment(tools=['MYIGNOREDEFAULTMSVCTOOL'])
+
diff --git a/test/fixture/no_msvc/no_msvcs_sconstruct_version.py b/test/fixture/no_msvc/no_msvcs_sconstruct_version.py
new file mode 100644
index 0000000..81d47cf
--- /dev/null
+++ b/test/fixture/no_msvc/no_msvcs_sconstruct_version.py
@@ -0,0 +1,14 @@
+import SCons
+import SCons.Tool.MSCommon
+
+def DummyVsWhere(msvc_version, env):
+ # not testing versions with vswhere, so return none
+ return None
+
+for key in SCons.Tool.MSCommon.vc._VCVER_TO_PRODUCT_DIR:
+ SCons.Tool.MSCommon.vc._VCVER_TO_PRODUCT_DIR[key]=[(SCons.Util.HKEY_LOCAL_MACHINE, r'')]
+
+SCons.Tool.MSCommon.vc.find_vc_pdir_vswhere = DummyVsWhere
+
+env = SCons.Environment.Environment(MSVC_VERSION='14.3')
+