diff options
Diffstat (limited to 'src/engine/SCons/Tool/MSCommon/common.py')
-rw-r--r-- | src/engine/SCons/Tool/MSCommon/common.py | 60 |
1 files changed, 48 insertions, 12 deletions
diff --git a/src/engine/SCons/Tool/MSCommon/common.py b/src/engine/SCons/Tool/MSCommon/common.py index 8353944..6f979e6 100644 --- a/src/engine/SCons/Tool/MSCommon/common.py +++ b/src/engine/SCons/Tool/MSCommon/common.py @@ -25,31 +25,67 @@ Common helper functions for working with the Microsoft tool chain. # from __future__ import print_function -__revision__ = "src/engine/SCons/Tool/MSCommon/common.py e724ae812eb96f4858a132f5b8c769724744faf6 2019-07-21 00:04:47 bdeegan" +__revision__ = "src/engine/SCons/Tool/MSCommon/common.py bee7caf9defd6e108fc2998a2520ddb36a967691 2019-12-17 02:07:09 bdeegan" import copy +import json import os -import subprocess import re +import subprocess +import sys import SCons.Util +# SCONS_MSCOMMON_DEBUG is internal-use so undocumented: +# 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) elif LOGFILE: - try: - import logging - except ImportError: - debug = lambda message: open(LOGFILE, 'a').write(message + '\n') - else: - logging.basicConfig(filename=LOGFILE, level=logging.DEBUG) - debug = logging.getLogger(name=__name__).debug + import logging + logging.basicConfig( + format='%(relativeCreated)05dms:pid%(process)05d:MSCommon/%(filename)s:%(message)s', + filename=LOGFILE, + level=logging.DEBUG) + debug = logging.getLogger(name=__name__).debug else: debug = lambda x: None +# SCONS_CACHE_MSVC_CONFIG is public, and is documented. +CONFIG_CACHE = os.environ.get('SCONS_CACHE_MSVC_CONFIG') +if CONFIG_CACHE in ('1', 'true', 'True'): + CONFIG_CACHE = os.path.join(os.path.expanduser('~'), '.scons_msvc_cache') + +def read_script_env_cache(): + """ fetch cached msvc env vars if requested, else return empty dict """ + envcache = {} + if CONFIG_CACHE: + try: + with open(CONFIG_CACHE, 'r') as f: + envcache = json.load(f) + #TODO can use more specific FileNotFoundError when py2 dropped + except IOError: + # don't fail if no cache file, just proceed without it + pass + return envcache + + +def write_script_env_cache(cache): + """ write out cache of msvc env vars if requested """ + if CONFIG_CACHE: + try: + with open(CONFIG_CACHE, 'w') as f: + json.dump(cache, f, indent=2) + except TypeError: + # data can't serialize to json, don't leave partial file + os.remove(CONFIG_CACHE) + except IOError: + # can't write the file, just skip + pass + + _is_win64 = None def is_win64(): @@ -199,7 +235,6 @@ def get_output(vcbat, args = None, env = None): if stderr: # TODO: find something better to do with stderr; # this at least prevents errors from getting swallowed. - import sys sys.stderr.write(stderr) if popen.wait() != 0: raise IOError(stderr.decode("mbcs")) @@ -207,14 +242,15 @@ def get_output(vcbat, args = None, env = None): output = stdout.decode("mbcs") return output -def parse_output(output, keep=("INCLUDE", "LIB", "LIBPATH", "PATH", 'VSCMD_ARG_app_plat')): +KEEPLIST = ("INCLUDE", "LIB", "LIBPATH", "PATH", 'VSCMD_ARG_app_plat') +def parse_output(output, keep=KEEPLIST): """ Parse output from running visual c++/studios vcvarsall.bat and running set To capture the values listed in keep """ # dkeep is a dict associating key: path_list, where key is one item from - # keep, and pat_list the associated list of paths + # keep, and path_list the associated list of paths dkeep = dict([(i, []) for i in keep]) # rdk will keep the regex to match the .bat file output line starts |