Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup serialization of settings JSON file. NFC #15912

Merged
merged 1 commit into from
Jan 7, 2022
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
9 changes: 7 additions & 2 deletions emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,15 @@ def compile_settings():
logger.info('logging stderr in js compiler phase into %s' % stderr_file)
stderr_file = open(stderr_file, 'w')

# Only the names of the legacy settings are used by the JS compiler
# so we can reduce the size of serialized json by simplifying this
# otherwise complex value.
settings['LEGACY_SETTINGS'] = [l[0] for l in settings['LEGACY_SETTINGS']]

# Save settings to a file to work around v8 issue 1579
with shared.configuration.get_temp_files().get_file('.txt') as settings_file:
with shared.configuration.get_temp_files().get_file('.json') as settings_file:
with open(settings_file, 'w') as s:
json.dump(settings.dict(), s, sort_keys=True)
json.dump(settings.dict(), s, sort_keys=True, indent=2)

# Call js compiler
env = os.environ.copy()
Expand Down
3 changes: 1 addition & 2 deletions src/parseTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -890,8 +890,7 @@ function makeRetainedCompilerSettings() {
const ignore = new Set(['STRUCT_INFO']);
if (STRICT) {
for (const setting of LEGACY_SETTINGS) {
const name = setting[0];
ignore.add(name);
ignore.add(setting);
}
}

Expand Down
19 changes: 8 additions & 11 deletions tools/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,15 @@ def __init__(self):
self.allowed_settings.clear()

# Load the JS defaults into python.
with open(path_from_root('src/settings.js')) as fh:
settings = fh.read().replace('//', '#')
settings = re.sub(r'var ([\w\d]+)', r'attrs["\1"]', settings)
# Variable TARGET_NOT_SUPPORTED is referenced by value settings.js (also beyond declaring it),
# so must pass it there explicitly.
exec(settings, {'attrs': self.attrs})

with open(path_from_root('src/settings_internal.js')) as fh:
settings = fh.read().replace('//', '#')
settings = re.sub(r'var ([\w\d]+)', r'attrs["\1"]', settings)
def read_js_settings(filename, attrs):
with open(filename) as fh:
settings = fh.read().replace('//', '#')
settings = re.sub(r'var ([\w\d]+)', r'attrs["\1"]', settings)
exec(settings, {'attrs': attrs})

internal_attrs = {}
exec(settings, {'attrs': internal_attrs})
read_js_settings(path_from_root('src/settings.js'), self.attrs)
read_js_settings(path_from_root('src/settings_internal.js'), internal_attrs)
self.attrs.update(internal_attrs)

if 'EMCC_STRICT' in os.environ:
Expand Down