Skip to content

Commit d0e21ba

Browse files
committed
cmdline: allow overriding -jsD directives (#26576)
1 parent d984d06 commit d0e21ba

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

test/test_jslib.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,13 @@ def test_jslib_legacy(self):
353353
# the -jsDfoo=val syntax:
354354
# See https://github.com/emscripten-core/emscripten/issues/10580.
355355
def test_jslib_custom_settings(self):
356-
self.cflags += ['--js-library', test_file('jslib/test_jslib_custom_settings.js'), '-jsDCUSTOM_JS_OPTION=1']
357-
self.do_run_in_out_file_test('jslib/test_jslib_custom_settings.c')
356+
test_file_path = test_file('jslib/test_jslib_custom_settings.c')
357+
js_lib = test_file('jslib/test_jslib_custom_settings.js')
358+
359+
self.do_runf(test_file_path, '1\n', cflags=['--js-library', js_lib, '-jsDCUSTOM_JS_OPTION=1'])
360+
361+
# verify that the settings can be specified more than once, and that the last one wins.
362+
self.do_runf(test_file_path, '2\n', cflags=['--js-library', js_lib, '-jsDCUSTOM_JS_OPTION=1', '-jsDCUSTOM_JS_OPTION=2'])
358363

359364
self.assert_fail([EMCC, '-jsDWASM=0'], 'cannot change built-in settings values with a -jsD directive')
360365

tools/cmdline.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
shared,
2323
utils,
2424
)
25-
from tools.settings import MEM_SIZE_SETTINGS, settings, user_settings
25+
from tools.settings import MEM_SIZE_SETTINGS, default_settings, settings, user_settings
2626
from tools.toolchain_profiler import ToolchainProfiler
2727
from tools.utils import exit_with_error, read_file
2828

@@ -216,6 +216,8 @@ def parse_args(newargs): # noqa: C901, PLR0912, PLR0915
216216
"""
217217
should_exit = False
218218
skip = False
219+
builtin_settings = set(default_settings.keys())
220+
user_js_defines = set()
219221
LEGACY_ARGS = {'--js-opts', '--llvm-opts', '--llvm-lto', '--memory-init-file'}
220222
LEGACY_FLAGS = {'--separate-asm', '--jcache', '--proxy-to-worker', '--default-obj-ext',
221223
'--embind-emit-tsd', '--remove-duplicates', '--no-heap-copy'}
@@ -572,11 +574,12 @@ def consume_arg_file():
572574
elif arg.startswith('-jsD'):
573575
key = arg.removeprefix('-jsD')
574576
if '=' in key:
575-
key, value = key.split('=')
577+
key, value = key.split('=', 1)
576578
else:
577579
value = '1'
578-
if key in settings.keys():
580+
if key in builtin_settings and key not in user_js_defines:
579581
exit_with_error(f'{arg}: cannot change built-in settings values with a -jsD directive. Pass -s{key}={value} instead!')
582+
user_js_defines.add(key)
580583
# Apply user -jsD settings
581584
settings[key] = value
582585
newargs[i] = ''

0 commit comments

Comments
 (0)