Skip to content

Commit eb5e07a

Browse files
committed
Refactor test to use do_runf and remove .out file
1 parent d9f7289 commit eb5e07a

3 files changed

Lines changed: 13 additions & 10 deletions

File tree

test/jslib/test_jslib_custom_settings.out

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/test_jslib.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,13 +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')
358-
359-
self.run_process([EMCC, test_file('hello_world.c'), '-jsDCUSTOM_JS_OPTION=1', '-jsDCUSTOM_JS_OPTION=2'])
356+
self.cflags += ['--js-library', test_file('jslib/test_jslib_custom_settings.js')]
360357

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

360+
self.do_runf('jslib/test_jslib_custom_settings.c', '1\n', cflags=['-jsDCUSTOM_JS_OPTION=1'])
361+
362+
# verify that the settings can be specified more than once, and that the last one wins.
363+
self.do_runf('jslib/test_jslib_custom_settings.c', '2\n', cflags=['-jsDCUSTOM_JS_OPTION=1', '-jsDCUSTOM_JS_OPTION=2'])
364+
363365
def test_jslib_native_deps(self):
364366
# Verify that memset (which lives in compiled code), can be specified as a JS library
365367
# dependency.

tools/cmdline.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def parse_args(newargs): # noqa: C901, PLR0912, PLR0915
216216
"""
217217
should_exit = False
218218
skip = False
219-
user_js_defines = set()
219+
user_js_defines: dict[str, str] = {}
220220
LEGACY_ARGS = {'--js-opts', '--llvm-opts', '--llvm-lto', '--memory-init-file'}
221221
LEGACY_FLAGS = {'--separate-asm', '--jcache', '--proxy-to-worker', '--default-obj-ext',
222222
'--embind-emit-tsd', '--remove-duplicates', '--no-heap-copy'}
@@ -576,11 +576,9 @@ def consume_arg_file():
576576
key, value = key.split('=')
577577
else:
578578
value = '1'
579-
if key in settings.keys() and key not in user_js_defines:
579+
if key in settings.keys() and key not in options.user_js_defines:
580580
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)
582-
# Apply user -jsD settings
583-
settings[key] = value
581+
options.user_js_defines[key] = value
584582
newargs[i] = ''
585583
elif check_flag('-shared'):
586584
options.shared = True
@@ -869,5 +867,9 @@ def parse_arguments(args):
869867

870868
# Apply -s args here (after optimization levels, so they can override them)
871869
apply_user_settings()
870+
871+
# Apply -jsD defines last so they win over -s args
872+
for key, value in options.user_js_defines.items():
873+
settings[key] = value
872874

873875
return newargs

0 commit comments

Comments
 (0)