From bd9f616033a6b82936c44046094930af58f3885b Mon Sep 17 00:00:00 2001 From: cournape Date: Thu, 19 Nov 2009 05:05:37 +0000 Subject: [PATCH] ENH: use Gary error checking, but using exception instead of returning error message (thanks Gary). git-svn-id: http://scons.tigris.org/svn/scons/trunk@4454 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/engine/SCons/Script/Main.py | 1 + src/engine/SCons/Tool/MSCommon/vc.py | 44 +++++++++++++++++----------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/engine/SCons/Script/Main.py b/src/engine/SCons/Script/Main.py index 6aba90f2..dd4f5197 100644 --- a/src/engine/SCons/Script/Main.py +++ b/src/engine/SCons/Script/Main.py @@ -777,6 +777,7 @@ def _main(parser): SCons.Warnings.ReservedVariableWarning, SCons.Warnings.StackSizeWarning, SCons.Warnings.VisualVersionMismatch, + SCons.Warnings.VisualCMissingWarning, ] for warning in default_warnings: diff --git a/src/engine/SCons/Tool/MSCommon/vc.py b/src/engine/SCons/Tool/MSCommon/vc.py index a6c5aaf6..227d1ff8 100644 --- a/src/engine/SCons/Tool/MSCommon/vc.py +++ b/src/engine/SCons/Tool/MSCommon/vc.py @@ -44,7 +44,19 @@ import common debug = common.debug -class BatchFileExecutionError(Exception): +class VisualCException(Exception): + pass + +class UnsupportedVersion(VisualCException): + pass + +class MissingConfiguration(VisualCException): + pass + +class NoVersionFound(VisualCException): + pass + +class BatchFileExecutionError(VisualCException): pass # Dict to 'canonalize' the arch @@ -114,7 +126,7 @@ def find_vc_pdir(msvc_version): hkeys = _VCVER_TO_PRODUCT_DIR[msvc_version] except KeyError: debug("Unknown version of MSVC: %s" % msvc_version) - return None + raise UnsupportedVersion("Unknown version %s" % msvc_version) for key in hkeys: key = root + key @@ -129,13 +141,13 @@ def find_vc_pdir(msvc_version): else: debug('find_vc_dir(): reg says dir is %s, but it does not exist. (ignoring)'\ % comps) - return None + raise MissingConfiguration("registry dir %s not found on the filesystem" % comps) return None def find_batch_file(msvc_version): pdir = find_vc_pdir(msvc_version) if pdir is None: - return None + raise NoVersionFound("No version of Visual Studio found") vernum = float(msvc_version) if 7 <= vernum < 8: @@ -229,14 +241,16 @@ def msvc_setup_env(env): env['MSVS_VERSION'] = version env['MSVS'] = {} - script = find_batch_file(version) - if not script: - msg = 'VC version %s not installed' % version - debug('msv %s\n' % repr(msg)) - SCons.Warnings.warn(SCons.Warnings.VisualCMissingWarning, msg) + try: + script = find_batch_file(version) + except VisualCException, e: + msg = str(e) + debug('Caught exception while looking for batch file (%s)' % msg) + warn_msg = "VC version %s not installed - C/C++ compilers most " \ + "likely not set correctly" % version + warn_msg += " \n Install versions are: %s" % get_installed_vcs() + SCons.Warnings.warn(SCons.Warnings.VisualCMissingWarning, warn_msg) return None - print script - use_script = env.get('MSVC_USE_SCRIPT', True) if SCons.Util.is_String(use_script): @@ -249,13 +263,9 @@ def msvc_setup_env(env): try: d = script_env(script, args=arg) except BatchFileExecutionError, e: - # XXX: find out why warnings do not work here - print "+++++++++++++++++++++++++++++" - msg = "Error while executing %s with args %s (error was %s)" % \ + msg = "MSVC error while executing %s with args %s (error was %s)" % \ (script, arg, str(e)) - print msg - print "+++++++++++++++++++++++++++++" - return None + raise SCons.Errors.UserError(msg) else: debug('msvc.get_default_env()\n') d = msvc.get_default_env() -- 2.26.2