Skip to content

Commit 02426d8

Browse files
committed
cmdline: allow overriding -jsD directives (#26576)
1 parent 2b98693 commit 02426d8

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

test/test_jslib.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ def test_jslib_custom_settings(self):
356356
self.cflags += ['--js-library', test_file('jslib/test_jslib_custom_settings.js'), '-jsDCUSTOM_JS_OPTION=1']
357357
self.do_run_in_out_file_test('jslib/test_jslib_custom_settings.c')
358358

359+
self.run_process([EMCC, test_file('hello_world.c'), '-jsDCUSTOM_JS_OPTION=1', '-jsDCUSTOM_JS_OPTION=2'])
360+
359361
self.assert_fail([EMCC, '-jsDWASM=0'], 'cannot change built-in settings values with a -jsD directive')
360362

361363
def test_jslib_native_deps(self):

tools/cmdline.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ def parse_args(newargs): # noqa: C901, PLR0912, PLR0915
216216
"""
217217
should_exit = False
218218
skip = False
219+
user_js_defines = set()
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'}
@@ -575,8 +576,9 @@ def consume_arg_file():
575576
key, value = key.split('=')
576577
else:
577578
value = '1'
578-
if key in settings.keys():
579+
if key in settings.keys() and key not in user_js_defines:
579580
exit_with_error(f'{arg}: cannot change built-in settings values with a -jsD directive. Pass -s{key}={value} instead!')
581+
user_js_defines.add(key)
580582
# Apply user -jsD settings
581583
settings[key] = value
582584
newargs[i] = ''

0 commit comments

Comments
 (0)