summaryrefslogtreecommitdiff
path: root/src/engine/SCons/Tool/MSCommon/common.py
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2019-12-28 17:12:57 +0100
committerJörg Frings-Fürst <debian@jff-webhosting.net>2019-12-28 17:12:57 +0100
commit5fc601f5484c9463e3399c0e690db80b9c22386e (patch)
tree3574b43f98f25e7bbf9dfdcb3e90d54f23e8ae0c /src/engine/SCons/Tool/MSCommon/common.py
parent10b9d3fe4386c06efbb4d971e4e307b89e254faa (diff)
parent56597a6a68e741355b301f91d5913d59cfb34eaa (diff)
Update upstream source from tag 'upstream/3.1.2'
Update to upstream version '3.1.2' with Debian dir 7ef381d8ee1bc3570b5feec63204df7f87ac1cb2
Diffstat (limited to 'src/engine/SCons/Tool/MSCommon/common.py')
-rw-r--r--src/engine/SCons/Tool/MSCommon/common.py60
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 428eaba..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 72ae09dc35ac2626f8ff711d8c4b30b6138e08e3 2019-08-08 14:50:06 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