Skip to content

Commit 92e2f3e

Browse files
authored
Final part of settings refactor. NFC (emscripten-core#13914)
Remove `serialize` method that is no longer needed. We used to need to serialize to a command line with `-s` flag but that was a long time ago. Now we can just go direct to json instead.
1 parent a543758 commit 92e2f3e

File tree

3 files changed

+11
-20
lines changed

3 files changed

+11
-20
lines changed

emscripten.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def compile_settings():
162162
# Save settings to a file to work around v8 issue 1579
163163
with shared.configuration.get_temp_files().get_file('.txt') as settings_file:
164164
with open(settings_file, 'w') as s:
165-
json.dump(shared.Settings.to_dict(), s, sort_keys=True)
165+
json.dump(shared.Settings.dict(), s, sort_keys=True)
166166

167167
# Call js compiler
168168
env = os.environ.copy()

tools/settings.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# found in the LICENSE file.
55

66
import difflib
7-
import json
87
import os
98
import re
109

@@ -96,18 +95,8 @@ class SettingsManager:
9695
def __init__(self):
9796
load_settings()
9897

99-
# Transforms the Settings information into emcc-compatible args (-s X=Y, etc.). Basically
100-
# the reverse of load_settings, except for -Ox which is relevant there but not here
101-
def serialize(self):
102-
ret = []
103-
for key, value in attrs.items():
104-
if key == key.upper(): # this is a hack. all of our settings are ALL_CAPS, python internals are not
105-
jsoned = json.dumps(value, sort_keys=True)
106-
ret += ['-s', key + '=' + jsoned]
107-
return ret
108-
109-
def to_dict(self):
110-
return attrs.copy()
98+
def dict(self):
99+
return attrs
111100

112101
def keys(self):
113102
return attrs.keys()
@@ -121,9 +110,6 @@ def __getattr__(self, attr):
121110
def __setattr__(self, attr, value):
122111
set_setting(attr, value)
123112

124-
def get(self, key):
125-
return attrs.get(key)
126-
127113
def __getitem__(self, key):
128114
return attrs[key]
129115

tools/shared.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import atexit
88
import binascii
99
import base64
10+
import json
1011
import logging
1112
import os
1213
import re
@@ -749,9 +750,13 @@ def safe_copy(src, dst):
749750
def read_and_preprocess(filename, expand_macros=False):
750751
temp_dir = get_emscripten_temp_dir()
751752
# Create a settings file with the current settings to pass to the JS preprocessor
752-
# Note: Settings.serialize returns an array of -s options i.e. ['-s', '<setting1>', '-s', '<setting2>', ...]
753-
# we only want the actual settings, hence the [1::2] slice operation.
754-
settings_str = "var " + ";\nvar ".join(Settings.serialize()[1::2])
753+
754+
settings_str = ''
755+
for key, value in Settings.dict().items():
756+
assert key == key.upper() # should only ever be uppercase keys in settings
757+
jsoned = json.dumps(value, sort_keys=True)
758+
settings_str += f'var {key} = {jsoned};\n'
759+
755760
settings_file = os.path.join(temp_dir, 'settings.js')
756761
with open(settings_file, 'w') as f:
757762
f.write(settings_str)

0 commit comments

Comments
 (0)