diff --git a/test/jslib/test_jslib_custom_settings.js b/test/jslib/test_jslib_custom_settings.js index 2423a0574fc2d..3fa209787be3c 100644 --- a/test/jslib/test_jslib_custom_settings.js +++ b/test/jslib/test_jslib_custom_settings.js @@ -1,9 +1,5 @@ addToLibrary({ - js_function: function() { -#if CUSTOM_JS_OPTION - return 1; -#else - return 0; -#endif - } -}); + js_function: function() { + return {{{ CUSTOM_JS_OPTION }}}; + } +}); \ No newline at end of file diff --git a/test/test_jslib.py b/test/test_jslib.py index 0c46710abc217..211a679386bd4 100644 --- a/test/test_jslib.py +++ b/test/test_jslib.py @@ -353,10 +353,15 @@ def test_jslib_legacy(self): # the -jsDfoo=val syntax: # See https://github.com/emscripten-core/emscripten/issues/10580. def test_jslib_custom_settings(self): - self.cflags += ['--js-library', test_file('jslib/test_jslib_custom_settings.js'), '-jsDCUSTOM_JS_OPTION=1'] - self.do_run_in_out_file_test('jslib/test_jslib_custom_settings.c') + test_file_path = test_file('jslib/test_jslib_custom_settings.c') + js_lib = test_file('jslib/test_jslib_custom_settings.js') - self.assert_fail([EMCC, '-jsDWASM=0'], 'cannot change built-in settings values with a -jsD directive') + self.do_runf(test_file_path, '1\n', cflags=['--js-library', js_lib, '-jsDCUSTOM_JS_OPTION=1']) + + # verify that the settings can be specified more than once, and that the last one wins. + self.do_runf(test_file_path, '2\n', cflags=['--js-library', js_lib, '-jsDCUSTOM_JS_OPTION=1', '-jsDCUSTOM_JS_OPTION=2']) + + self.assert_fail([EMCC, '-jsDWASM=1'], 'cannot change built-in settings values with a -jsD directive') def test_jslib_native_deps(self): # Verify that memset (which lives in compiled code), can be specified as a JS library diff --git a/tools/cmdline.py b/tools/cmdline.py index d708a09f5c5a7..6584ea02e25a2 100644 --- a/tools/cmdline.py +++ b/tools/cmdline.py @@ -216,6 +216,7 @@ def parse_args(newargs): # noqa: C901, PLR0912, PLR0915 """ should_exit = False skip = False + builtin_settings = set(settings.keys()) LEGACY_ARGS = {'--js-opts', '--llvm-opts', '--llvm-lto', '--memory-init-file'} LEGACY_FLAGS = {'--separate-asm', '--jcache', '--proxy-to-worker', '--default-obj-ext', '--embind-emit-tsd', '--remove-duplicates', '--no-heap-copy'} @@ -572,12 +573,12 @@ def consume_arg_file(): elif arg.startswith('-jsD'): key = arg.removeprefix('-jsD') if '=' in key: - key, value = key.split('=') + key, value = key.split('=', 1) else: value = '1' - if key in settings.keys(): + if key in builtin_settings: exit_with_error(f'{arg}: cannot change built-in settings values with a -jsD directive. Pass -s{key}={value} instead!') - # Apply user -jsD settings + # Allow overrides/duplicates for user-defined -jsD flags settings[key] = value newargs[i] = '' elif check_flag('-shared'):