Skip to content

Commit

Permalink
Allow -sFOO=1 as well as -s FOO=1 on the command line (#11550)
Browse files Browse the repository at this point in the history
Fixes: #11463
  • Loading branch information
sbc100 committed Jul 6, 2020
1 parent 8c94b85 commit f45bea2
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 16 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Expand Up @@ -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.
Expand Down
7 changes: 5 additions & 2 deletions docs/emcc.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down
31 changes: 18 additions & 13 deletions emcc.py
Expand Up @@ -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'):
Expand Down Expand Up @@ -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'
Expand All @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion site/source/docs/tools_reference/emcc.rst
Expand Up @@ -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 <https://github.com/emscripten-core/emscripten/blob/master/src/settings.js>`_.
Emscripten build options. For the available options, see `src/settings.js <https://github.com/emscripten-core/emscripten/blob/master/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``.

Expand All @@ -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``
Expand Down
5 changes: 5 additions & 0 deletions tests/test_other.py
Expand Up @@ -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):
Expand Down

0 comments on commit f45bea2

Please sign in to comment.