From 24409247142c9aef9b8308b52f8fd23360e05608 Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Fri, 19 Nov 2021 12:05:44 -0700 Subject: Clean up lint complaints in MSCommon Largest change is lazy formatting in logging (debug). W1201: Use lazy % formatting in logging functions (logging-not-lazy) W1202: Use lazy % formatting in logging functions (logging-format-interpolation) This required minor rework to the two alternate definitions of 'debug' which didn't use logging, to keep the signatures consistent. W1510: Using subprocess.run without explicitly set `check` is not recommended. (subprocess-run-check) Signed-off-by: Mats Wichmann --- CHANGES.txt | 4 ++ SCons/Tool/MSCommon/__init__.py | 27 ++++---- SCons/Tool/MSCommon/arch.py | 18 ++--- SCons/Tool/MSCommon/common.py | 35 +++++----- SCons/Tool/MSCommon/netframework.py | 15 ++--- SCons/Tool/MSCommon/sdk.py | 54 +++++++-------- SCons/Tool/MSCommon/vc.py | 128 ++++++++++++++++++------------------ SCons/Tool/MSCommon/vs.py | 65 +++++++++--------- 8 files changed, 180 insertions(+), 166 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 3db1fd5..ebcae22 100755 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -31,6 +31,10 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER we need to do this for internal reasons, those are skipped in that case. Bad association could mean some other tool took it over (Visual Studio Code is known to do this), or no association at all. + - logging code ("debug" call) in Tool/MSCommon now conforms to the + Python logging recommended "lazy interpolation" so instead of + debug("template %s" % text) it looks like debug("template %s", text) + so the logging system does the interpolation when/if needed. RELEASE 4.3.0 - Tue, 16 Nov 2021 18:12:46 -0700 diff --git a/SCons/Tool/MSCommon/__init__.py b/SCons/Tool/MSCommon/__init__.py index ec2bfea..50eed73 100644 --- a/SCons/Tool/MSCommon/__init__.py +++ b/SCons/Tool/MSCommon/__init__.py @@ -30,20 +30,23 @@ import SCons.Errors import SCons.Platform.win32 import SCons.Util -from SCons.Tool.MSCommon.sdk import mssdk_exists, \ - mssdk_setup_env +from SCons.Tool.MSCommon.sdk import mssdk_exists, mssdk_setup_env -from SCons.Tool.MSCommon.vc import msvc_exists, \ - msvc_setup_env, \ - msvc_setup_env_once, \ - msvc_version_to_maj_min, \ - msvc_find_vswhere +from SCons.Tool.MSCommon.vc import ( + msvc_exists, + msvc_setup_env, + msvc_setup_env_once, + msvc_version_to_maj_min, + msvc_find_vswhere, +) -from SCons.Tool.MSCommon.vs import get_default_version, \ - get_vs_by_version, \ - merge_default_version, \ - msvs_exists, \ - query_versions +from SCons.Tool.MSCommon.vs import ( + get_default_version, + get_vs_by_version, + merge_default_version, + msvs_exists, + query_versions, +) # Local Variables: # tab-width:4 diff --git a/SCons/Tool/MSCommon/arch.py b/SCons/Tool/MSCommon/arch.py index 0032422..6648bb6 100644 --- a/SCons/Tool/MSCommon/arch.py +++ b/SCons/Tool/MSCommon/arch.py @@ -1,5 +1,6 @@ +# MIT License # -# __COPYRIGHT__ +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -19,11 +20,9 @@ # 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__" -__doc__ = """Module to define supported Windows chip architectures. +""" +MS compilers: Supported Windows chip architectures. """ @@ -40,22 +39,18 @@ SupportedArchitectureList = [ 'x86', ['i386', 'i486', 'i586', 'i686'], ), - ArchDefinition( 'x86_64', ['AMD64', 'amd64', 'em64t', 'EM64T', 'x86_64'], ), - ArchDefinition( 'ia64', ['IA64'], ), - ArchDefinition( 'arm', ['ARM'], ), - ] SupportedArchitectureMap = {} @@ -64,3 +59,8 @@ for a in SupportedArchitectureList: for s in a.synonyms: SupportedArchitectureMap[s] = a +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/SCons/Tool/MSCommon/common.py b/SCons/Tool/MSCommon/common.py index f5e64ee..839df11 100644 --- a/SCons/Tool/MSCommon/common.py +++ b/SCons/Tool/MSCommon/common.py @@ -1,8 +1,6 @@ -""" -Common helper functions for working with the Microsoft tool chain. -""" +# MIT License # -# __COPYRIGHT__ +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -22,8 +20,10 @@ Common helper functions for working with the Microsoft tool chain. # 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__" + +""" +Common helper functions for working with the Microsoft tool chain. +""" import copy import json @@ -38,8 +38,12 @@ import SCons.Util # set to '-' to print to console, else set to filename to log to LOGFILE = os.environ.get('SCONS_MSCOMMON_DEBUG') if LOGFILE == '-': - def debug(message): - print(message) + def debug(message, *args): + if args: + print(message % args) + else: + print(message) + elif LOGFILE: import logging modulelist = ( @@ -83,7 +87,8 @@ elif LOGFILE: logger.addFilter(_Debug_Filter()) debug = logger.debug else: - def debug(x): return None + def debug(x, *args): + return None # SCONS_CACHE_MSVC_CONFIG is public, and is documented. @@ -214,7 +219,7 @@ def normalize_env(env, keys, force=False): if sys32_ps_dir not in normenv['PATH']: normenv['PATH'] = normenv['PATH'] + os.pathsep + sys32_ps_dir - debug("PATH: %s" % normenv['PATH']) + debug("PATH: %s", normenv['PATH']) return normenv @@ -256,14 +261,14 @@ def get_output(vcbat, args=None, env=None): env['ENV'] = normalize_env(env['ENV'], vs_vc_vars, force=False) if args: - debug("Calling '%s %s'" % (vcbat, args)) + debug("Calling '%s %s'", vcbat, args) popen = SCons.Action._subproc(env, '"%s" %s & set' % (vcbat, args), stdin='devnull', stdout=subprocess.PIPE, stderr=subprocess.PIPE) else: - debug("Calling '%s'" % vcbat) + debug("Calling '%s'", vcbat) popen = SCons.Action._subproc(env, '"%s" & set' % vcbat, stdin='devnull', @@ -279,8 +284,8 @@ def get_output(vcbat, args=None, env=None): stderr = popen.stderr.read() # Extra debug logic, uncomment if necessary - # debug('stdout:%s' % stdout) - # debug('stderr:%s' % stderr) + # debug('stdout:%s', stdout) + # debug('stderr:%s', stderr) # Ongoing problems getting non-corrupted text led to this # changing to "oem" from "mbcs" - the scripts run presumably @@ -321,7 +326,7 @@ def parse_output(output, keep=KEEPLIST): # dkeep is a dict associating key: path_list, where key is one item from # keep, and path_list the associated list of paths - dkeep = dict([(i, []) for i in keep]) + dkeep = {i: [] for i in keep} # rdk will keep the regex to match the .bat file output line starts rdk = {} diff --git a/SCons/Tool/MSCommon/netframework.py b/SCons/Tool/MSCommon/netframework.py index 5e2c33a..98d9231 100644 --- a/SCons/Tool/MSCommon/netframework.py +++ b/SCons/Tool/MSCommon/netframework.py @@ -1,5 +1,6 @@ +# MIT License # -# __COPYRIGHT__ +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,14 +21,12 @@ # 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__" - -__doc__ = """ +""" +MS Compilers: .Net Framework support """ import os import re -import SCons.Util from .common import read_reg, debug @@ -40,13 +39,13 @@ def find_framework_root(): # XXX: find it from environment (FrameworkDir) try: froot = read_reg(_FRAMEWORKDIR_HKEY_ROOT) - debug("Found framework install root in registry: {}".format(froot)) + debug("Found framework install root in registry: %s", froot) except OSError: - debug("Could not read reg key {}".format(_FRAMEWORKDIR_HKEY_ROOT)) + debug("Could not read reg key %s", _FRAMEWORKDIR_HKEY_ROOT) return None if not os.path.exists(froot): - debug("{} not found on fs".format(froot)) + debug("%s not found on fs", froot) return None return froot diff --git a/SCons/Tool/MSCommon/sdk.py b/SCons/Tool/MSCommon/sdk.py index 439a7ad..d95df91 100644 --- a/SCons/Tool/MSCommon/sdk.py +++ b/SCons/Tool/MSCommon/sdk.py @@ -1,5 +1,6 @@ +# MIT License # -# __COPYRIGHT__ +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,10 +21,8 @@ # 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__" - -__doc__ = """Module to detect the Platform/Windows SDK +""" +MS Compilers: detect the Platform/Windows SDK PSDK 2003 R1 is the earliest version detected. """ @@ -74,23 +73,23 @@ class SDKDefinition: return None hkey = self.HKEY_FMT % self.hkey_data - debug('find_sdk_dir(): checking registry:{}'.format(hkey)) + debug('find_sdk_dir(): checking registry: %s', hkey) try: sdk_dir = read_reg(hkey) except OSError: - debug('find_sdk_dir(): no SDK registry key {}'.format(repr(hkey))) + debug('find_sdk_dir(): no SDK registry key %s', hkey) return None - debug('find_sdk_dir(): Trying SDK Dir: {}'.format(sdk_dir)) + debug('find_sdk_dir(): Trying SDK Dir: %s', sdk_dir) if not os.path.exists(sdk_dir): - debug('find_sdk_dir(): {} not on file system'.format(sdk_dir)) + debug('find_sdk_dir(): %s not on file system', sdk_dir) return None ftc = os.path.join(sdk_dir, self.sanity_check_file) if not os.path.exists(ftc): - debug("find_sdk_dir(): sanity check {} not found".format(ftc)) + debug("find_sdk_dir(): sanity check %s not found", ftc) return None return sdk_dir @@ -116,11 +115,14 @@ class SDKDefinition: if host_arch != target_arch: arch_string='%s_%s'%(host_arch,target_arch) - debug("get_sdk_vc_script():arch_string:%s host_arch:%s target_arch:%s"%(arch_string, - host_arch, - target_arch)) - file=self.vc_setup_scripts.get(arch_string,None) - debug("get_sdk_vc_script():file:%s"%file) + debug( + "get_sdk_vc_script():arch_string:%s host_arch:%s target_arch:%s", + arch_string, + host_arch, + target_arch, + ) + file = self.vc_setup_scripts.get(arch_string, None) + debug("get_sdk_vc_script():file:%s", file) return file class WindowsSDK(SDKDefinition): @@ -289,9 +291,9 @@ def get_installed_sdks(): InstalledSDKList = [] InstalledSDKMap = {} for sdk in SupportedSDKList: - debug('trying to find SDK %s' % sdk.version) + debug('trying to find SDK %s', sdk.version) if sdk.get_sdk_dir(): - debug('found SDK %s' % sdk.version) + debug('found SDK %s', sdk.version) InstalledSDKList.append(sdk) InstalledSDKMap[sdk.version] = sdk return InstalledSDKList @@ -306,7 +308,7 @@ SDKEnvironmentUpdates = {} def set_sdk_by_directory(env, sdk_dir): global SDKEnvironmentUpdates - debug('set_sdk_by_directory: Using dir:%s'%sdk_dir) + debug('set_sdk_by_directory: Using dir:%s', sdk_dir) try: env_tuple_list = SDKEnvironmentUpdates[sdk_dir] except KeyError: @@ -350,7 +352,7 @@ def mssdk_setup_env(env): if sdk_dir is None: return sdk_dir = env.subst(sdk_dir) - debug('mssdk_setup_env: Using MSSDK_DIR:{}'.format(sdk_dir)) + debug('mssdk_setup_env: Using MSSDK_DIR:%s', sdk_dir) elif 'MSSDK_VERSION' in env: sdk_version = env['MSSDK_VERSION'] if sdk_version is None: @@ -362,22 +364,22 @@ def mssdk_setup_env(env): msg = "SDK version %s is not installed" % sdk_version raise SCons.Errors.UserError(msg) sdk_dir = mssdk.get_sdk_dir() - debug('mssdk_setup_env: Using MSSDK_VERSION:%s'%sdk_dir) + debug('mssdk_setup_env: Using MSSDK_VERSION:%s', sdk_dir) elif 'MSVS_VERSION' in env: msvs_version = env['MSVS_VERSION'] - debug('mssdk_setup_env:Getting MSVS_VERSION from env:%s'%msvs_version) + debug('mssdk_setup_env:Getting MSVS_VERSION from env:%s', msvs_version) if msvs_version is None: debug('mssdk_setup_env thinks msvs_version is None') return msvs_version = env.subst(msvs_version) from . import vs msvs = vs.get_vs_by_version(msvs_version) - debug('mssdk_setup_env:msvs is :%s'%msvs) + debug('mssdk_setup_env:msvs is :%s', msvs) if not msvs: - debug('mssdk_setup_env: no VS version detected, bailingout:%s'%msvs) + debug('mssdk_setup_env: no VS version detected, bailingout:%s', msvs) return sdk_version = msvs.sdk_version - debug('msvs.sdk_version is %s'%sdk_version) + debug('msvs.sdk_version is %s', sdk_version) if not sdk_version: return mssdk = get_sdk_by_version(sdk_version) @@ -386,13 +388,13 @@ def mssdk_setup_env(env): if not mssdk: return sdk_dir = mssdk.get_sdk_dir() - debug('mssdk_setup_env: Using MSVS_VERSION:%s'%sdk_dir) + debug('mssdk_setup_env: Using MSVS_VERSION:%s', sdk_dir) else: mssdk = get_default_sdk() if not mssdk: return sdk_dir = mssdk.get_sdk_dir() - debug('mssdk_setup_env: not using any env values. sdk_dir:%s'%sdk_dir) + debug('mssdk_setup_env: not using any env values. sdk_dir:%s', sdk_dir) set_sdk_by_directory(env, sdk_dir) diff --git a/SCons/Tool/MSCommon/vc.py b/SCons/Tool/MSCommon/vc.py index dc882c4..4f9f9c6 100644 --- a/SCons/Tool/MSCommon/vc.py +++ b/SCons/Tool/MSCommon/vc.py @@ -1,4 +1,3 @@ -# # MIT License # # Copyright The SCons Foundation @@ -21,8 +20,9 @@ # 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. -# -"""Module for Visual C/C++ detection and configuration. + +""" +MS Compilers: Visual C/C++ detection and configuration. # TODO: # * gather all the information from a single vswhere call instead @@ -39,7 +39,6 @@ """ import SCons.compat -import SCons.Util import subprocess import os @@ -47,6 +46,7 @@ import platform from string import digits as string_digits from subprocess import PIPE +import SCons.Util import SCons.Warnings from SCons.Tool import find_program_path @@ -194,7 +194,7 @@ def get_msvc_version_numeric(msvc_version): def get_host_target(env): host_platform = env.get('HOST_ARCH') - debug("HOST_ARCH:" + str(host_platform)) + debug("HOST_ARCH:%s", str(host_platform)) if not host_platform: host_platform = platform.machine() @@ -207,7 +207,7 @@ def get_host_target(env): # Retain user requested TARGET_ARCH req_target_platform = env.get('TARGET_ARCH') - debug("TARGET_ARCH:" + str(req_target_platform)) + debug("TARGET_ARCH:%s", str(req_target_platform)) if req_target_platform: # If user requested a specific platform then only try that one. target_platform = req_target_platform @@ -218,7 +218,7 @@ def get_host_target(env): host = _ARCH_TO_CANONICAL[host_platform.lower()] except KeyError: msg = "Unrecognized host architecture %s" - raise MSVCUnsupportedHostArch(msg % repr(host_platform)) + raise MSVCUnsupportedHostArch(msg % repr(host_platform)) from None try: target = _ARCH_TO_CANONICAL[target_platform.lower()] @@ -227,7 +227,7 @@ def get_host_target(env): raise MSVCUnsupportedTargetArch( "Unrecognized target architecture %s\n\tValid architectures: %s" % (target_platform, all_archs) - ) + ) from None return (host, target, req_target_platform) @@ -333,7 +333,7 @@ def msvc_version_to_maj_min(msvc_version): min = int(t[1]) return maj, min except ValueError as e: - raise ValueError("Unrecognized version %s (%s)" % (msvc_version,msvc_version_numeric)) + raise ValueError("Unrecognized version %s (%s)" % (msvc_version,msvc_version_numeric)) from None def is_host_target_supported(host_target, msvc_version): @@ -397,8 +397,8 @@ def find_vc_pdir_vswhere(msvc_version, env=None): try: vswhere_version = _VCVER_TO_VSWHERE_VER[msvc_version] except KeyError: - debug("Unknown version of MSVC: %s" % msvc_version) - raise UnsupportedVersion("Unknown version %s" % msvc_version) + debug("Unknown version of MSVC: %s", msvc_version) + raise UnsupportedVersion("Unknown version %s" % msvc_version) from None if env is None or not env.get('VSWHERE'): vswhere_path = msvc_find_vswhere() @@ -408,15 +408,15 @@ def find_vc_pdir_vswhere(msvc_version, env=None): if vswhere_path is None: return None - debug('VSWHERE: %s' % vswhere_path) + debug('VSWHERE: %s', vswhere_path) for vswhere_version_args in vswhere_version: vswhere_cmd = [vswhere_path] + vswhere_version_args + ["-property", "installationPath"] - debug("running: %s" % vswhere_cmd) + debug("running: %s", vswhere_cmd) - #cp = subprocess.run(vswhere_cmd, capture_output=True) # 3.7+ only - cp = subprocess.run(vswhere_cmd, stdout=PIPE, stderr=PIPE) + #cp = subprocess.run(vswhere_cmd, capture_output=True, check=True) # 3.7+ only + cp = subprocess.run(vswhere_cmd, stdout=PIPE, stderr=PIPE, check=True) if cp.stdout: # vswhere could return multiple lines, e.g. if Build Tools @@ -458,8 +458,8 @@ def find_vc_pdir(env, msvc_version): try: hkeys = _VCVER_TO_PRODUCT_DIR[msvc_version] except KeyError: - debug("Unknown version of MSVC: %s" % msvc_version) - raise UnsupportedVersion("Unknown version %s" % msvc_version) + debug("Unknown version of MSVC: %s", msvc_version) + raise UnsupportedVersion("Unknown version %s" % msvc_version) from None for hkroot, key in hkeys: try: @@ -467,9 +467,9 @@ def find_vc_pdir(env, msvc_version): if not key: comps = find_vc_pdir_vswhere(msvc_version, env) if not comps: - debug('no VC found for version {}'.format(repr(msvc_version))) + debug('no VC found for version %s', repr(msvc_version)) raise OSError - debug('VC found: {}'.format(repr(msvc_version))) + debug('VC found: %s', repr(msvc_version)) return comps else: if common.is_win64(): @@ -483,13 +483,13 @@ def find_vc_pdir(env, msvc_version): # not Win64, or Microsoft Visual Studio for Python 2.7 comps = common.read_reg(root + key, hkroot) except OSError: - debug('no VC registry key {}'.format(repr(key))) + debug('no VC registry key %s', repr(key)) else: - debug('found VC in registry: {}'.format(comps)) + debug('found VC in registry: %s', comps) if os.path.exists(comps): return comps else: - debug('reg says dir is {}, but it does not exist. (ignoring)'.format(comps)) + debug('reg says dir is %s, but it does not exist. (ignoring)', comps) raise MissingConfiguration("registry dir {} not found on the filesystem".format(comps)) return None @@ -506,7 +506,7 @@ def find_batch_file(env,msvc_version,host_arch,target_arch): pdir = find_vc_pdir(env, msvc_version) if pdir is None: raise NoVersionFound("No version of Visual Studio found") - debug('looking in {}'.format(pdir)) + debug('looking in %s', pdir) # filter out e.g. "Exp" from the version name msvc_ver_numeric = get_msvc_version_numeric(msvc_version) @@ -527,18 +527,18 @@ def find_batch_file(env,msvc_version,host_arch,target_arch): use_arg = False if not os.path.exists(batfilename): - debug("Not found: %s" % batfilename) + debug("Not found: %s", batfilename) batfilename = None installed_sdks = get_installed_sdks() for _sdk in installed_sdks: sdk_bat_file = _sdk.get_sdk_vc_script(host_arch,target_arch) if not sdk_bat_file: - debug("batch file not found:%s" % _sdk) + debug("batch file not found:%s", _sdk) else: sdk_bat_file_path = os.path.join(pdir,sdk_bat_file) if os.path.exists(sdk_bat_file_path): - debug('sdk_bat_file_path:%s' % sdk_bat_file_path) + debug('sdk_bat_file_path:%s', sdk_bat_file_path) return (batfilename, use_arg, sdk_bat_file_path) return (batfilename, use_arg, None) @@ -582,7 +582,7 @@ def _check_cl_exists_in_vc_dir(env, vc_dir, msvc_version): host_platform = _ARCH_TO_CANONICAL[host_platform] target_platform = _ARCH_TO_CANONICAL[target_platform] - debug('host platform %s, target platform %s for version %s' % (host_platform, target_platform, msvc_version)) + debug('host platform %s, target platform %s for version %s', host_platform, target_platform, msvc_version) ver_num = float(get_msvc_version_numeric(msvc_version)) @@ -597,21 +597,21 @@ def _check_cl_exists_in_vc_dir(env, vc_dir, msvc_version): with open(default_toolset_file) as f: vc_specific_version = f.readlines()[0].strip() except IOError: - debug('failed to read ' + default_toolset_file) + debug('failed to read %s', default_toolset_file) return False except IndexError: - debug('failed to find MSVC version in ' + default_toolset_file) + debug('failed to find MSVC version in %s', default_toolset_file) return False host_trgt_dir = _HOST_TARGET_TO_CL_DIR_GREATER_THAN_14.get((host_platform, target_platform), None) if host_trgt_dir is None: - debug('unsupported host/target platform combo: (%s,%s)'%(host_platform, target_platform)) + debug('unsupported host/target platform combo: (%s,%s)', host_platform, target_platform) return False cl_path = os.path.join(vc_dir, 'Tools','MSVC', vc_specific_version, 'bin', host_trgt_dir[0], host_trgt_dir[1], _CL_EXE_NAME) - debug('checking for ' + _CL_EXE_NAME + ' at ' + cl_path) + debug('checking for %s at %s', _CL_EXE_NAME, cl_path) if os.path.exists(cl_path): - debug('found ' + _CL_EXE_NAME + '!') + debug('found %s!', _CL_EXE_NAME) return True elif host_platform == "amd64" and host_trgt_dir[0] == "Hostx64": @@ -623,9 +623,9 @@ def _check_cl_exists_in_vc_dir(env, vc_dir, msvc_version): # targets, but we don't see those in this function. host_trgt_dir = ("Hostx86", host_trgt_dir[1]) cl_path = os.path.join(vc_dir, 'Tools','MSVC', vc_specific_version, 'bin', host_trgt_dir[0], host_trgt_dir[1], _CL_EXE_NAME) - debug('checking for ' + _CL_EXE_NAME + ' at ' + cl_path) + debug('checking for %s at %s', _CL_EXE_NAME, cl_path) if os.path.exists(cl_path): - debug('found ' + _CL_EXE_NAME + '!') + debug('found %s!', _CL_EXE_NAME) return True elif 14 >= ver_num >= 8: @@ -637,7 +637,7 @@ def _check_cl_exists_in_vc_dir(env, vc_dir, msvc_version): return False cl_path = os.path.join(vc_dir, 'bin', host_trgt_dir, _CL_EXE_NAME) - debug('checking for ' + _CL_EXE_NAME + ' at ' + cl_path) + debug('checking for %s at %s', _CL_EXE_NAME, cl_path) cl_path_exists = os.path.exists(cl_path) if not cl_path_exists and host_platform == 'amd64': @@ -652,11 +652,11 @@ def _check_cl_exists_in_vc_dir(env, vc_dir, msvc_version): return False cl_path = os.path.join(vc_dir, 'bin', host_trgt_dir, _CL_EXE_NAME) - debug('checking for ' + _CL_EXE_NAME + ' at ' + cl_path) + debug('checking for %s at %s', _CL_EXE_NAME, cl_path) cl_path_exists = os.path.exists(cl_path) if cl_path_exists: - debug('found ' + _CL_EXE_NAME + '!') + debug('found %s', _CL_EXE_NAME) return True elif 8 > ver_num >= 6: @@ -665,19 +665,19 @@ def _check_cl_exists_in_vc_dir(env, vc_dir, msvc_version): for cl_dir in ('bin', ''): cl_path = os.path.join(vc_dir, cl_dir, _CL_EXE_NAME) if os.path.exists(cl_path): - debug(_CL_EXE_NAME + ' found %s' % cl_path) + debug('%s found %s', _CL_EXE_NAME, cl_path) return True # not in bin or root: must be in a subdirectory for cl_root, cl_dirs, _ in os.walk(vc_dir): for cl_dir in cl_dirs: cl_path = os.path.join(cl_root, cl_dir, _CL_EXE_NAME) if os.path.exists(cl_path): - debug(_CL_EXE_NAME + ' found %s' % cl_path) + debug('%s found %s', _CL_EXE_NAME, cl_path) return True return False else: # version not support return false - debug('unsupported MSVC version: ' + str(ver_num)) + debug('unsupported MSVC version: %s', str(ver_num)) return False @@ -690,23 +690,23 @@ def get_installed_vcs(env=None): installed_versions = [] for ver in _VCVER: - debug('trying to find VC %s' % ver) + debug('trying to find VC %s', ver) try: VC_DIR = find_vc_pdir(env, ver) if VC_DIR: - debug('found VC %s' % ver) + debug('found VC %s', ver) if _check_cl_exists_in_vc_dir(env, VC_DIR, ver): installed_versions.append(ver) else: - debug('no compiler found %s' % ver) + debug('no compiler found %s', ver) else: - debug('return None for ver %s' % ver) + debug('return None for ver %s', ver) except (MSVCUnsupportedTargetArch, MSVCUnsupportedHostArch): # Allow this exception to propagate further as it should cause # SCons to exit with an error code raise except VisualCException as e: - debug('did not find VC %s: caught exception %s' % (ver, str(e))) + debug('did not find VC %s: caught exception %s', ver, str(e)) __INSTALLED_VCS_RUN = installed_versions return __INSTALLED_VCS_RUN @@ -762,7 +762,7 @@ def script_env(script, args=None): def get_default_version(env): msvc_version = env.get('MSVC_VERSION') msvs_version = env.get('MSVS_VERSION') - debug('msvc_version:%s msvs_version:%s' % (msvc_version, msvs_version)) + debug('msvc_version:%s msvs_version:%s', msvc_version, msvs_version) if msvs_version and not msvc_version: SCons.Warnings.warn( @@ -781,17 +781,15 @@ def get_default_version(env): if not msvc_version: installed_vcs = get_installed_vcs(env) - debug('installed_vcs:%s' % installed_vcs) + debug('installed_vcs:%s', installed_vcs) if not installed_vcs: - #msg = 'No installed VCs' - #debug('msv %s' % repr(msg)) #SCons.Warnings.warn(SCons.Warnings.VisualCMissingWarning, msg) debug('No installed VCs') return None msvc_version = installed_vcs[0] - debug('using default installed MSVC version %s' % repr(msvc_version)) + debug('using default installed MSVC version %s', repr(msvc_version)) else: - debug('using specified MSVC version %s' % repr(msvc_version)) + debug('using specified MSVC version %s', repr(msvc_version)) return msvc_version @@ -820,7 +818,7 @@ def msvc_find_valid_batch_script(env, version): # Find the host, target, and if present the requested target: platforms = get_host_target(env) - debug("host_platform %s, target_platform %s req_target_platform %s" % platforms) + debug("host_platform %s, target_platform %s req_target_platform %s", *platforms) host_platform, target_platform, req_target_platform = platforms # Most combinations of host + target are straightforward. @@ -850,14 +848,14 @@ def msvc_find_valid_batch_script(env, version): # if there are no viable 64 bit tools installed try_target_archs.append('x86') - debug("host_platform: %s, try_target_archs: %s"%(host_platform, try_target_archs)) + debug("host_platform: %s, try_target_archs: %s", host_platform, try_target_archs) d = None for tp in try_target_archs: # Set to current arch. env['TARGET_ARCH'] = tp - debug("trying target_platform:%s" % tp) + debug("trying target_platform:%s", tp) host_target = (host_platform, tp) if not is_host_target_supported(host_target, version): warn_msg = "host, target = %s not supported for MSVC version %s" % \ @@ -868,10 +866,10 @@ def msvc_find_valid_batch_script(env, version): # Try to locate a batch file for this host/target platform combo 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)) + debug('vc_script:%s sdk_script:%s', vc_script, sdk_script) except VisualCException as e: msg = str(e) - debug('Caught exception while looking for batch file (%s)' % msg) + 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" @@ -880,7 +878,7 @@ def msvc_find_valid_batch_script(env, version): continue # Try to use the located batch file for this host/target platform combo - debug('use_script 2 %s, args:%s' % (repr(vc_script), arg)) + debug('use_script 2 %s, args:%s', repr(vc_script), arg) found = None if vc_script: if not use_arg: @@ -897,22 +895,22 @@ def msvc_find_valid_batch_script(env, version): d = script_env(vc_script, args=arg) found = vc_script except BatchFileExecutionError as e: - debug('use_script 3: failed running VC script %s: %s: Error:%s'%(repr(vc_script),arg,e)) + debug('use_script 3: failed running VC script %s: %s: Error:%s', repr(vc_script), arg, e) vc_script=None continue if not vc_script and sdk_script: - debug('use_script 4: trying sdk script: %s' % sdk_script) + debug('use_script 4: trying sdk script: %s', sdk_script) try: d = script_env(sdk_script) found = sdk_script except BatchFileExecutionError as e: - debug('use_script 5: failed running SDK script %s: Error:%s'%(repr(sdk_script), e)) + debug('use_script 5: failed running SDK script %s: Error:%s', repr(sdk_script), e) continue elif not vc_script and not sdk_script: debug('use_script 6: Neither VC script nor SDK script found') continue - debug("Found a working script/target: %s/%s"%(repr(found),arg)) + debug("Found a working script/target: %s/%s", repr(found), arg) break # We've found a working target_platform, so stop looking # If we cannot find a viable installed compiler, reset the TARGET_ARCH @@ -944,11 +942,11 @@ def msvc_setup_env(env): use_script = use_script.strip() if not os.path.exists(use_script): raise MSVCScriptNotFound('Script specified by MSVC_USE_SCRIPT not found: "{}"'.format(use_script)) - debug('use_script 1 %s' % repr(use_script)) + debug('use_script 1 %s', repr(use_script)) d = script_env(use_script) elif use_script: d = msvc_find_valid_batch_script(env,version) - debug('use_script 2 %s' % d) + debug('use_script 2 %s', d) if not d: return d else: @@ -960,11 +958,11 @@ def msvc_setup_env(env): for k, v in d.items(): env.PrependENVPath(k, v, delete_existing=True) - debug("env['ENV']['%s'] = %s" % (k, env['ENV'][k])) + debug("env['ENV']['%s'] = %s", k, env['ENV'][k]) # final check to issue a warning if the compiler is not present if not find_program_path(env, 'cl'): - debug("did not find " + _CL_EXE_NAME) + debug("did not find %s", _CL_EXE_NAME) if CONFIG_CACHE: propose = "SCONS_CACHE_MSVC_CONFIG caching enabled, remove cache file {} if out of date.".format(CONFIG_CACHE) else: diff --git a/SCons/Tool/MSCommon/vs.py b/SCons/Tool/MSCommon/vs.py index b6fe282..35d21e0 100644 --- a/SCons/Tool/MSCommon/vs.py +++ b/SCons/Tool/MSCommon/vs.py @@ -1,5 +1,6 @@ +# MIT License # -# __COPYRIGHT__ +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -19,26 +20,26 @@ # 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__" -__doc__ = """Module to detect Visual Studio and/or Visual C/C++ +""" +MS Compilers: detect Visual Studio and/or Visual C/C++ """ import os import SCons.Errors +import SCons.Tool.MSCommon.vc import SCons.Util -from .common import debug, \ - get_output, \ - is_win64, \ - normalize_env, \ - parse_output, \ - read_reg +from .common import ( + debug, + get_output, + is_win64, + normalize_env, + parse_output, + read_reg, +) -import SCons.Tool.MSCommon.vc class VisualStudio: """ @@ -60,14 +61,14 @@ class VisualStudio: batch_file = os.path.join(vs_dir, self.batch_file_path) batch_file = os.path.normpath(batch_file) if not os.path.isfile(batch_file): - debug('%s not on file system' % batch_file) + debug('%s not on file system', batch_file) return None return batch_file def find_vs_dir_by_vc(self, env): dir = SCons.Tool.MSCommon.vc.find_vc_pdir(env, self.vc_version) if not dir: - debug('no installed VC %s' % self.vc_version) + debug('no installed VC %s', self.vc_version) return None return os.path.abspath(os.path.join(dir, os.pardir)) @@ -83,9 +84,9 @@ class VisualStudio: try: comps = read_reg(key) except OSError: - debug('no VS registry key {}'.format(repr(key))) + debug('no VS registry key %s', repr(key)) else: - debug('found VS in registry: {}'.format(comps)) + debug('found VS in registry: %s', comps) return comps return None @@ -94,21 +95,21 @@ class VisualStudio: First try to find by registry, and if that fails find via VC dir """ - vs_dir=self.find_vs_dir_by_reg(env) + vs_dir = self.find_vs_dir_by_reg(env) if not vs_dir: vs_dir = self.find_vs_dir_by_vc(env) - debug('found VS in ' + str(vs_dir )) + debug('found VS in %s', str(vs_dir)) return vs_dir def find_executable(self, env): vs_dir = self.get_vs_dir(env) if not vs_dir: - debug('no vs_dir ({})'.format(vs_dir)) + debug('no vs_dir (%s)', vs_dir) return None executable = os.path.join(vs_dir, self.executable_path) executable = os.path.normpath(executable) if not os.path.isfile(executable): - debug('{} not on file system'.format(executable)) + debug('%s not on file system', executable) return None return executable @@ -122,15 +123,15 @@ class VisualStudio: def get_executable(self, env=None): try: - debug('using cache:%s'%self._cache['executable']) + debug('using cache:%s', self._cache['executable']) return self._cache['executable'] except KeyError: executable = self.find_executable(env) self._cache['executable'] = executable - debug('not in cache:%s'%executable) + debug('not in cache:%s', executable) return executable - def get_vs_dir(self, env): + def get_vs_dir(self, env=None): try: return self._cache['vs_dir'] except KeyError: @@ -431,9 +432,9 @@ def get_installed_visual_studios(env=None): InstalledVSList = [] InstalledVSMap = {} for vs in SupportedVSList: - debug('trying to find VS %s' % vs.version) + debug('trying to find VS %s', vs.version) if vs.get_executable(env): - debug('found VS %s' % vs.version) + debug('found VS %s', vs.version) InstalledVSList.append(vs) InstalledVSMap[vs.version] = vs return InstalledVSList @@ -483,8 +484,8 @@ def reset_installed_visual_studios(): # for variable, directory in env_tuple_list: # env.PrependENVPath(variable, directory) -def msvs_exists(env=None): - return (len(get_installed_visual_studios(env)) > 0) +def msvs_exists(env=None) -> bool: + return len(get_installed_visual_studios(env)) > 0 def get_vs_by_version(msvs): global InstalledVSMap @@ -496,8 +497,8 @@ def get_vs_by_version(msvs): raise SCons.Errors.UserError(msg) get_installed_visual_studios() vs = InstalledVSMap.get(msvs) - debug('InstalledVSMap:%s' % InstalledVSMap) - debug('found vs:%s' % vs) + debug('InstalledVSMap:%s', InstalledVSMap) + debug('found vs:%s', vs) # Some check like this would let us provide a useful error message # if they try to set a Visual Studio version that's not installed. # However, we also want to be able to run tests (like the unit @@ -533,7 +534,8 @@ def get_default_version(env): env['MSVS_VERSION'] = versions[0] #use highest version by default else: debug('WARNING: no installed versions found, ' - 'using first in SupportedVSList (%s)' % SupportedVSList[0].version) + 'using first in SupportedVSList (%s)', + SupportedVSList[0].version) env['MSVS_VERSION'] = SupportedVSList[0].version env['MSVS']['VERSION'] = env['MSVS_VERSION'] @@ -566,11 +568,12 @@ def merge_default_version(env): version = get_default_version(env) arch = get_default_arch(env) +# TODO: refers to versions and arch which aren't defined; called nowhere. Drop? def msvs_setup_env(env): - batfilename = msvs.get_batch_file() msvs = get_vs_by_version(version) if msvs is None: return + batfilename = msvs.get_batch_file() # XXX: I think this is broken. This will silently set a bogus tool instead # of failing, but there is no other way with the current scons tool -- cgit v0.12 From c91232b77e781a813fd8207d5213b20ccc7c8240 Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Mon, 3 Jan 2022 09:32:18 -0700 Subject: Slight change to MS logging template Signed-off-by: Mats Wichmann --- SCons/Tool/MSCommon/common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SCons/Tool/MSCommon/common.py b/SCons/Tool/MSCommon/common.py index 839df11..ee31b2d 100644 --- a/SCons/Tool/MSCommon/common.py +++ b/SCons/Tool/MSCommon/common.py @@ -73,13 +73,13 @@ elif LOGFILE: return True logging.basicConfig( # This looks like: - # 00109ms:MSCommon/vc.py:find_vc_pdir#447: + # 00109ms:MSCommon/vc.py:find_vc_pdir#447:VC found '14.3' format=( '%(relativeCreated)05dms' ':%(relfilename)s' ':%(funcName)s' '#%(lineno)s' - ':%(message)s: ' + ':%(message)s' ), filename=LOGFILE, level=logging.DEBUG) -- cgit v0.12 From 8f61b20fba1815810ee411b89d603a0208a6cf37 Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Fri, 7 Jan 2022 11:25:49 -0700 Subject: Update CHANGES for msvc debug change [ci skip] Signed-off-by: Mats Wichmann --- CHANGES.txt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index ebcae22..e544d13 100755 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -31,10 +31,11 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER we need to do this for internal reasons, those are skipped in that case. Bad association could mean some other tool took it over (Visual Studio Code is known to do this), or no association at all. - - logging code ("debug" call) in Tool/MSCommon now conforms to the - Python logging recommended "lazy interpolation" so instead of - debug("template %s" % text) it looks like debug("template %s", text) - so the logging system does the interpolation when/if needed. + - Updated debug code in MSVC and MSVS tools to conform to the + suggested "lazy interpolation" use of the Python logging module. + Calls now look like 'debug("template %s", text)' rather than + 'debug("template %s" % text)' so the logging system does the + interpolation only when/if needed (was a pylint warning). RELEASE 4.3.0 - Tue, 16 Nov 2021 18:12:46 -0700 -- cgit v0.12