Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions SCons/Tool/MSCommon/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ def read_script_env_cache():
try:
p = Path(CONFIG_CACHE)
with p.open('r') as f:
envcache = json.load(f)
# Convert the list of cache entry dictionaries read from
# json to the cache dictionary. Reconstruct the cache key
# tuple from the key list written to json.
envcache_list = json.load(f)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine, I'm inclined to merge this change. Maybe a comment why we're doing what we're doing with came out of the json file (and/or what goes into it).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better or worse? See below as well.

envcache = {tuple(d['key']): d['data'] for d in envcache_list}
except FileNotFoundError:
# don't fail if no cache file, just proceed without it
pass
Expand All @@ -119,7 +123,11 @@ def write_script_env_cache(cache):
try:
p = Path(CONFIG_CACHE)
with p.open('w') as f:
json.dump(cache, f, indent=2)
# Convert the cache dictionary to a list of cache entry
# dictionaries. The cache key is converted from a tuple to
# a list for compatibility with json.
envcache_list = [{'key': list(key), 'data': data} for key, data in cache.items()]
json.dump(envcache_list, f, indent=2)
except TypeError:
# data can't serialize to json, don't leave partial file
with suppress(FileNotFoundError):
Expand Down
2 changes: 1 addition & 1 deletion SCons/Tool/MSCommon/vc.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ def script_env(script, args=None):

if script_env_cache is None:
script_env_cache = common.read_script_env_cache()
cache_key = f"{script}--{args}" if args else f"{script}"
cache_key = (script, args if args else None)
cache_data = script_env_cache.get(cache_key, None)

# Brief sanity check: if we got a value for the key,
Expand Down