Skip to content

Commit bb615a9

Browse files
authored
Use modern -s command line lists in more places. NFC (#15516)
We want to avoid pointing folks to the older, more error prone and complex format.
1 parent 72fd2b4 commit bb615a9

File tree

6 files changed

+34
-38
lines changed

6 files changed

+34
-38
lines changed

docs/emcc.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,17 @@ Options that are modified or new in *emcc* are listed below:
104104

105105
Note:
106106

107-
Lists can be specified without or without quotes around each
108-
element and with or without brackets around the list. For
109-
example all the following are equivelent:
107+
Lists can be specified as comma separated strings:
110108

111109
-s EXPORTED_FUNCTIONS=foo,bar
110+
111+
Note:
112+
113+
We also support older list formats that involve more quoting.
114+
Lists can be specified with or without quotes around each element
115+
and with or without brackets around the list. For example, all
116+
the following are equivalent:
117+
112118
-s EXPORTED_FUNCTIONS="foo","bar"
113119
-s EXPORTED_FUNCTIONS=["foo","bar"]
114120
-s EXPORTED_FUNCTIONS=[foo,bar]

site/source/docs/api_reference/advanced-apis.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ While it is possible to edit **settings.js** manually, this is *highly discourag
3030

3131
The small number of options that developers may have cause to change should be modified when the *emcc* tool is invoked. For example, ``EXPORTED_FUNCTIONS``: ::
3232

33-
./emcc tests/hello_function.cpp -o function.html -s EXPORTED_FUNCTIONS="['_int_sqrt']"
33+
./emcc tests/hello_function.cpp -o function.html -s EXPORTED_FUNCTIONS=_int_sqrt
3434

3535

3636
preamble.js

site/source/docs/api_reference/preamble.js.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ We call this "``preamble.js``" because Emscripten's output JS, at a high level,
1010

1111
The preamble code is included in the output JS, which is then optimized all together by the compiler, together with any ``--pre-js`` and ``--post-js`` files you added and code from any JavaScript libraries (``--js-library``). That means that you can call methods from the preamble directly, and the compiler will see that you need them, and not remove them as being unused.
1212

13-
If you want to call preamble methods from somewhere the compiler can't see, like another script tag on the HTML, you need to **export** them. To do so, add them to ``EXPORTED_RUNTIME_METHODS`` (for example, ``-s 'EXPORTED_RUNTIME_METHODS=["ccall", "cwrap"]'`` will export ``ccall`` and ``cwrap``). Once exported, you can access them on the ``Module`` object (as ``Module.ccall``, for example).
13+
If you want to call preamble methods from somewhere the compiler can't see, like another script tag on the HTML, you need to **export** them. To do so, add them to ``EXPORTED_RUNTIME_METHODS`` (for example, ``-s EXPORTED_RUNTIME_METHODS=ccall,cwrap`` will export ``ccall`` and ``cwrap``). Once exported, you can access them on the ``Module`` object (as ``Module.ccall``, for example).
1414

1515
.. note:: If you try to use ``Module.ccall`` or another runtime method without exporting it, you will get an error. In a build with ``-s ASSERTIONS=1``, the compiler emits code to show you a useful error message, which will explain that you need to export it. In general, if you see something odd, it's useful to build with assertions.
1616

@@ -51,7 +51,7 @@ Calling compiled C functions from JavaScript
5151

5252
.. code-block:: none
5353
54-
-s EXPORTED_FUNCTIONS="['_main', '_myfunc']"
54+
-s EXPORTED_FUNCTIONS=_main,_myfunc"
5555
5656
(Note that we also export ``main`` - if we didn't, the compiler would assume we don't need it.) Exported functions can then be called as normal:
5757

@@ -104,7 +104,7 @@ Calling compiled C functions from JavaScript
104104

105105
.. code-block:: none
106106
107-
-s EXPORTED_FUNCTIONS="['_main', '_myfunc']"
107+
-s EXPORTED_FUNCTIONS=_main,_myfunc
108108
109109
Exported functions can be called as normal:
110110

site/source/docs/getting_started/FAQ.rst

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -415,46 +415,31 @@ with
415415
Why do I get a ``NameError`` or ``a problem occurred in evaluating content after a "-s"`` when I use a ``-s`` option?
416416
=====================================================================================================================
417417

418-
That may occur when running something like
418+
That may occur when using the old list syntax for ``-s`` settings:
419419

420420
::
421421

422422
# this fails on most Linuxes
423-
emcc a.c -s EXPORTED_RUNTIME_METHODS=['addOnPostRun']
423+
emcc a.c -s EXPORTED_RUNTIME_METHODS=['foo']
424424

425425
# this fails on macOS
426-
emcc a.c -s EXPORTED_RUNTIME_METHODS="['addOnPostRun']"
426+
emcc a.c -s EXPORTED_RUNTIME_METHODS="['foo']"
427427

428-
You may need to quote things like this:
428+
A new, simpler way to specify these lists is to simply use
429+
comma separated lists:
429430

430431
::
431432

432-
# this works in the shell on most Linuxes and on macOS
433-
emcc a.c -s "EXPORTED_RUNTIME_METHODS=['addOnPostRun']"
433+
emcc a.c -s EXPORTED_RUNTIME_METHODS=foo,bar
434434

435-
# or you may need something like this in a Makefile
436-
emcc a.c -s EXPORTED_RUNTIME_METHODS=\"['addOnPostRun']\"
437-
438-
The proper syntax depends on the OS and shell you are in, and if you are writing
439-
in a Makefile, etc. Things like spaces may also matter in some shells, for
440-
example you may need to avoid empty spaces between list items:
441-
442-
::
443-
444-
# this works in the shell on most Linuxes and on macOS
445-
emcc a.c -s "EXPORTED_RUNTIME_METHODS=['foo','bar']"
446-
447-
(note there is no space after the ``,``).
448-
449-
For simplicity, you may want to use a **response file**, that is,
435+
It is also possible to use a **response file**, that is,
450436

451437
::
452438

453-
# this works in the shell on most Linuxes and on macOS
454-
emcc a.c -s "EXPORTED_RUNTIME_METHODS=@extra.txt"
439+
emcc a.c -s EXPORTED_RUNTIME_METHODS=@extra.txt
455440

456-
and then ``extra.txt`` can be a plain file that contains ``['foo','bar']``. This
457-
avoids any issues with the shell environment parsing the string.
441+
with ``extra.txt`` being a plain text file that contains ``foo`` and ``bar`` on
442+
seperate lines.
458443

459444
How do I specify ``-s`` options in a CMake project?
460445
===================================================
@@ -475,7 +460,7 @@ notation, that is, without a space:
475460
# same as before but no space after -s
476461
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -sUSE_SDL=2")
477462
# example of target_link_options with a list of names
478-
target_link_options(example PRIVATE "-sEXPORTED_FUNCTIONS=[_main]")
463+
target_link_options(example PRIVATE "-sEXPORTED_FUNCTIONS=_main")
479464

480465
Note also that ``_main`` does not need to be quoted, even though it's a string
481466
name (``emcc`` knows that the argument to ``EXPORTED_FUNCTIONS`` is a list of

site/source/docs/tools_reference/emcc.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,16 @@ Options that are modified or new in *emcc* are listed below:
9696

9797
.. note:: If no value is specifed it will default to ``1``.
9898

99-
.. note:: Lists can be specified without or without quotes around each element and with or without brackets around the list. For example all the following are equivelent:
99+
.. note:: Lists can be specified as comma separated strings:
100100

101101
::
102102

103103
-s EXPORTED_FUNCTIONS=foo,bar
104+
105+
.. note:: We also support older list formats that involve more quoting. Lists can be specified with or without quotes around each element and with or without brackets around the list. For example, all the following are equivalent:
106+
107+
::
108+
104109
-s EXPORTED_FUNCTIONS="foo","bar"
105110
-s EXPORTED_FUNCTIONS=["foo","bar"]
106111
-s EXPORTED_FUNCTIONS=[foo,bar]

tests/test_interactive.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def setUpClass(cls):
2626
print()
2727

2828
def test_html5_fullscreen(self):
29-
self.btest(test_file('test_html5_fullscreen.c'), expected='0', args=['-s', 'DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR', '-s', 'EXPORTED_FUNCTIONS=["_requestFullscreen","_enterSoftFullscreen","_main"]', '--shell-file', test_file('test_html5_fullscreen.html')])
29+
self.btest(test_file('test_html5_fullscreen.c'), expected='0', args=['-s', 'DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR', '-s', 'EXPORTED_FUNCTIONS=_requestFullscreen,_enterSoftFullscreen,_main', '--shell-file', test_file('test_html5_fullscreen.html')])
3030

3131
def test_html5_emscripten_exit_with_escape(self):
3232
self.btest('test_html5_emscripten_exit_fullscreen.c', expected='1', args=['-DEXIT_WITH_F'])
@@ -63,7 +63,7 @@ def test_sdl_audio(self):
6363
open(os.path.join(self.get_dir(), 'bad.ogg'), 'w').write('I claim to be audio, but am lying')
6464

6565
# use closure to check for a possible bug with closure minifying away newer Audio() attributes
66-
self.compile_btest(['-O2', '--closure=1', '--minify=0', test_file('sdl_audio.c'), '--preload-file', 'sound.ogg', '--preload-file', 'sound2.wav', '--embed-file', 'the_entertainer.ogg', '--preload-file', 'noise.ogg', '--preload-file', 'bad.ogg', '-o', 'page.html', '-s', 'EXPORTED_FUNCTIONS=["_main", "_play", "_play2"]'])
66+
self.compile_btest(['-O2', '--closure=1', '--minify=0', test_file('sdl_audio.c'), '--preload-file', 'sound.ogg', '--preload-file', 'sound2.wav', '--embed-file', 'the_entertainer.ogg', '--preload-file', 'noise.ogg', '--preload-file', 'bad.ogg', '-o', 'page.html', '-s', 'EXPORTED_FUNCTIONS=_main,_play,_play2'])
6767
self.run_browser('page.html', '', '/report_result?1')
6868

6969
# print('SDL2')
@@ -72,7 +72,7 @@ def test_sdl_audio(self):
7272
# depended on fragile SDL1/SDL2 mixing, which stopped working with
7373
# 7a5744d754e00bec4422405a1a94f60b8e53c8fc (which just uncovered
7474
# the existing problem)
75-
# self.run_process([EMCC, '-O1', '--closure', '0', '--minify=0', os.path.join(self.get_dir(), 'sdl_audio.c'), '--preload-file', 'sound.ogg', '--preload-file', 'sound2.wav', '--embed-file', 'the_entertainer.ogg', '--preload-file', 'noise.ogg', '--preload-file', 'bad.ogg', '-o', 'page.html', '-s', 'EXPORTED_FUNCTIONS=["_main", "_play", "_play2"]', '-s', 'USE_SDL=2', '-DUSE_SDL2']).communicate()
75+
# self.run_process([EMCC, '-O1', '--closure', '0', '--minify=0', os.path.join(self.get_dir(), 'sdl_audio.c'), '--preload-file', 'sound.ogg', '--preload-file', 'sound2.wav', '--embed-file', 'the_entertainer.ogg', '--preload-file', 'noise.ogg', '--preload-file', 'bad.ogg', '-o', 'page.html', '-s', 'EXPORTED_FUNCTIONS=[_main,_play,_play2', '-s', 'USE_SDL=2', '-DUSE_SDL2']).communicate()
7676
# self.run_browser('page.html', '', '/report_result?1')
7777

7878
@parameterized({
@@ -101,7 +101,7 @@ def test_sdl_audio_panning(self):
101101
shutil.copyfile(test_file('sounds', 'the_entertainer.wav'), os.path.join(self.get_dir(), 'the_entertainer.wav'))
102102

103103
# use closure to check for a possible bug with closure minifying away newer Audio() attributes
104-
self.compile_btest(['-O2', '--closure=1', '--minify=0', test_file('sdl_audio_panning.c'), '--preload-file', 'the_entertainer.wav', '-o', 'page.html', '-s', 'EXPORTED_FUNCTIONS=["_main", "_play"]'])
104+
self.compile_btest(['-O2', '--closure=1', '--minify=0', test_file('sdl_audio_panning.c'), '--preload-file', 'the_entertainer.wav', '-o', 'page.html', '-s', 'EXPORTED_FUNCTIONS=_main,_play'])
105105
self.run_browser('page.html', '', '/report_result?1')
106106

107107
def test_sdl_audio_beeps(self):

0 commit comments

Comments
 (0)