Skip to content

Commit 28591cd

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

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

test/test_jslib.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,15 @@ 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')
358358

359-
self.assert_fail([EMCC, '-jsDWASM=0'], 'cannot change built-in settings values with a -jsD directive')
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'])
363+
364+
self.assert_fail([EMCC, '-jsDWASM=1'], 'cannot change built-in settings values with a -jsD directive')
360365

361366
def test_jslib_native_deps(self):
362367
# Verify that memset (which lives in compiled code), can be specified as a JS library

tools/cmdline.py

Lines changed: 5 additions & 4 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,7 @@ def parse_args(newargs): # noqa: C901, PLR0912, PLR0915
216216
"""
217217
should_exit = False
218218
skip = False
219+
builtin_settings = set(default_settings.keys())
219220
LEGACY_ARGS = {'--js-opts', '--llvm-opts', '--llvm-lto', '--memory-init-file'}
220221
LEGACY_FLAGS = {'--separate-asm', '--jcache', '--proxy-to-worker', '--default-obj-ext',
221222
'--embind-emit-tsd', '--remove-duplicates', '--no-heap-copy'}
@@ -572,12 +573,12 @@ def consume_arg_file():
572573
elif arg.startswith('-jsD'):
573574
key = arg.removeprefix('-jsD')
574575
if '=' in key:
575-
key, value = key.split('=')
576+
key, value = key.split('=', 1)
576577
else:
577578
value = '1'
578-
if key in settings.keys():
579+
if key in builtin_settings:
579580
exit_with_error(f'{arg}: cannot change built-in settings values with a -jsD directive. Pass -s{key}={value} instead!')
580-
# Apply user -jsD settings
581+
# Allow overrides/duplicates for user-defined -jsD flags
581582
settings[key] = value
582583
newargs[i] = ''
583584
elif check_flag('-shared'):

0 commit comments

Comments
 (0)