diff options
author | Mats Wichmann <mats@linux.com> | 2019-10-11 01:40:46 (GMT) |
---|---|---|
committer | Mats Wichmann <mats@linux.com> | 2019-10-11 01:40:46 (GMT) |
commit | 98e5afec3e9727d7ab462aca3fa4681ca3b5b016 (patch) | |
tree | 84e4c381168586b2b3344ab662a22fcfc77ce500 /src | |
parent | f39f01c44bfb52fbb09ee57e8d678e03086b9a83 (diff) | |
download | SCons-98e5afec3e9727d7ab462aca3fa4681ca3b5b016.zip SCons-98e5afec3e9727d7ab462aca3fa4681ca3b5b016.tar.gz SCons-98e5afec3e9727d7ab462aca3fa4681ca3b5b016.tar.bz2 |
[PR 3462] python two handle the json
reading the cache from the json file got us unicode when
running python2, and this broke certain tests when calling
subprocess.Popen: TypeError, because all the environment
wasn't strings, some was unicode.
Signed-off-by: Mats Wichmann <mats@linux.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/engine/SCons/Tool/MSCommon/common.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/engine/SCons/Tool/MSCommon/common.py b/src/engine/SCons/Tool/MSCommon/common.py index d4997eb..eaf57f9 100644 --- a/src/engine/SCons/Tool/MSCommon/common.py +++ b/src/engine/SCons/Tool/MSCommon/common.py @@ -32,6 +32,8 @@ import json import os import subprocess import re +import subprocess +import sys import SCons.Util @@ -56,13 +58,23 @@ 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') +# !@$#@$? Python2 +if sys.version_info[0] == 2: + def str_hook(obj): + return {k.encode('utf-8') if isinstance(k, unicode) else k : + v.encode('utf-8') if isinstance(v, unicode) else v + for k,v in obj} + 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) + if sys.version_info[0] == 2: + envcache = json.load(f, object_pairs_hook=str_hook) + else: + envcache = json.load(f) #TODO can use more specific FileNotFoundError when py2 dropped except IOError: pass |