diff --git a/ChangeLog.md b/ChangeLog.md index 71cf9ad26d30..79670738689d 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -17,6 +17,9 @@ See docs/process.md for how version tagging works. Current Trunk ------------- +- Settings on the command line no longer require a space between the `-s` and + the name of the setting. For example, `-sEXPORT_ALL` is now equivalent to + `-s EXPORT_ALL`. - Rename `EXCEPTION_CATCHING_WHITELIST` to `EXCEPTION_CATCHING_ALLOWED`. The functionality is unchanged, and the old name will be allowed as an alias for a few releases to give users time to migrate. diff --git a/docs/emcc.txt b/docs/emcc.txt index 27ccd0f41d28..e5c5161e280e 100644 --- a/docs/emcc.txt +++ b/docs/emcc.txt @@ -83,8 +83,8 @@ Options that are modified or new in *emcc* are listed below: Note: For more tips on optimizing your code, see Optimizing Code. "-s OPTION[=VALUE]" - JavaScript code generation option passed into the Emscripten - compiler. For the available options, see src/settings.js. + Emscripten build options. For the available options, see + src/settings.js. Note: You can prefix boolean options with "NO_" to reverse them. For example, "-s EXIT_RUNTIME=1" is the same as "-s @@ -113,6 +113,9 @@ Options that are modified or new in *emcc* are listed below: * The specified file path must be absolute, not relative. + Note: Options can be specified as a single argument without a + space between the "-s" and option name. e.g. "-sFOO=1". + "-g" Preserve debug information. diff --git a/emcc.py b/emcc.py index 2f980b3a54ed..4a445a965e39 100755 --- a/emcc.py +++ b/emcc.py @@ -838,17 +838,16 @@ def get_language_mode(args): language_mode = get_language_mode(args) - def is_minus_s_for_emcc(args, i): - # -s OPT=VALUE or -s OPT are interpreted as emscripten flags. + def is_dash_s_for_emcc(args, i): + # -s OPT=VALUE or -s OPT or -sOPT are all interpreted as emscripten flags. # -s by itself is a linker option (alias for --strip-all) - assert args[i] == '-s' - if len(args) > i + 1: + if args[i] == '-s': + if len(args) <= i + 1: + return False arg = args[i + 1] - if arg.split('=')[0].isupper(): - return True - - logger.debug('treating -s as linker option and not as -s OPT=VALUE for js compilation') - return False + else: + arg = args[i][2:] + return arg.split('=')[0].isupper() CONFIGURE_CONFIG = os.environ.get('EMMAKEN_JUST_CONFIGURE') or 'conftest.c' in args if CONFIGURE_CONFIG and not os.environ.get('EMMAKEN_JUST_CONFIGURE_RECURSE'): @@ -1034,9 +1033,15 @@ def need_llvm_debug_info(options): start_time = time.time() # done after parsing arguments, which might affect debug state for i in range(len(newargs)): - if newargs[i] == '-s': - if is_minus_s_for_emcc(newargs, i): - key = newargs[i + 1] + if newargs[i].startswith('-s'): + if is_dash_s_for_emcc(newargs, i): + if newargs[i] == '-s': + key = newargs[i + 1] + newargs[i + 1] = '' + else: + key = newargs[i][2:] + newargs[i] = '' + # If not = is specified default to 1 if '=' not in key: key += '=1' @@ -1051,7 +1056,7 @@ def need_llvm_debug_info(options): pass settings_changes.append(key) - newargs[i] = newargs[i + 1] = '' + newargs = [arg for arg in newargs if arg] settings_key_changes = set() diff --git a/site/source/docs/tools_reference/emcc.rst b/site/source/docs/tools_reference/emcc.rst index 06f85c6256f5..3b4c8f69566f 100644 --- a/site/source/docs/tools_reference/emcc.rst +++ b/site/source/docs/tools_reference/emcc.rst @@ -82,7 +82,7 @@ Options that are modified or new in *emcc* are listed below: .. _emcc-s-option-value: ``-s OPTION[=VALUE]`` - JavaScript code generation option passed into the Emscripten compiler. For the available options, see `src/settings.js `_. + Emscripten build options. For the available options, see `src/settings.js `_. .. note:: You can prefix boolean options with ``NO_`` to reverse them. For example, ``-s EXIT_RUNTIME=1`` is the same as ``-s NO_EXIT_RUNTIME=0``. @@ -106,6 +106,9 @@ Options that are modified or new in *emcc* are listed below: - In this case the file might contain a JSON-formatted list of functions: ``["_func1", "func2"]``. - The specified file path must be absolute, not relative. + .. note:: Options can be specified as a single argument without a space + between the ``-s`` and option name. e.g. ``-sFOO=1``. + .. _emcc-g: ``-g`` diff --git a/tests/test_other.py b/tests/test_other.py index 679e51c31694..402f79e8ebeb 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -6843,6 +6843,11 @@ def test_dash_s_typo(self): self.assertContained("Attempt to set a non-existent setting: 'ZBINARYEN_ASYNC_COMPILATION'", stderr) self.assertNotContained(' BINARYEN_ASYNC_COMPILATION', stderr) + def test_dash_s_no_space(self): + run_process([EMCC, path_from_root('tests', 'hello_world.c'), '-sEXPORT_ALL=1']) + err = self.expect_fail([EMCC, path_from_root('tests', 'hello_world.cpp'), '-sEXPORTED_FUNCTIONS=["foo"]']) + self.assertContained('error: undefined exported function: "foo"', err) + def test_python_2_3(self): # check emcc/em++ can be called by any python def trim_py_suffix(filename):