Skip to content

Commit 3d2272e

Browse files
authored
Followups for recent export changes (#5992)
* add a helpful error message when failing to evaluate content after -s * add a faq entry for -s errors with quotations * when running the file packager standalone, mention -s FORCE_FILESYSTEM=1 is necessary, so people don't need to look in the docs
1 parent 50cfb64 commit 3d2272e

File tree

4 files changed

+49
-4
lines changed

4 files changed

+49
-4
lines changed

emcc.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,11 @@ def check(input_file):
909909
value = '"' + value + '"'
910910
else:
911911
value = value.replace('\\', '\\\\')
912-
setattr(shared.Settings, key, eval(value))
912+
try:
913+
setattr(shared.Settings, key, eval(value))
914+
except Exception as e:
915+
logging.error('a problem occurred in evaluating content after a "-s", specifically %s . one possible cause of this is missing quotation marks (this depends on the shell you are running in; you may need quotation marks around the entire %s , or on an individual element)' % (change, change))
916+
raise e
913917
if key == 'EXPORTED_FUNCTIONS':
914918
# used for warnings in emscripten.py
915919
shared.Settings.ORIGINAL_EXPORTED_FUNCTIONS = original_exported_response or shared.Settings.EXPORTED_FUNCTIONS[:]

site/source/docs/getting_started/FAQ.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,28 @@ will export ``ccall``. In both cases you can then access the exported function o
368368

369369
.. note:: Emscripten used to export many runtime methods by default. This increased code size, and for that reason we've changed that default. If you depend on something that used to be exported, you should see a warning pointing you to the solution, in an unoptimized build, or a build with ``ASSERTIONS`` enabled, which we hope will minimize any annoyance. See ``Changelog.markdown`` for details.
370370

371+
Why do I get a ``NameError`` or ``a problem occurred in evaluating content after a "-s"`` when I use a ``-s`` option?
372+
========================================================
373+
374+
That may occur when running something like
375+
376+
::
377+
378+
# this fails on most Linuxes
379+
./emcc a.c -s EXTRA_EXPORTED_RUNTIME_METHODS=['addOnPostRun']
380+
381+
You may need quotation marks, such as
382+
383+
::
384+
385+
# this works on most Linuxes
386+
./emcc a.c -s "EXTRA_EXPORTED_RUNTIME_METHODS=['addOnPostRun']"
387+
388+
# also this should work
389+
./emcc a.c -s EXTRA_EXPORTED_RUNTIME_METHODS="['addOnPostRun']"
390+
391+
The proper syntax depends on the OS and shell you are in.
392+
371393
Why do I get an odd python error complaining about libcxx.bc or libcxxabi.bc?
372394
=============================================================================
373395

tests/test_other.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2317,7 +2317,6 @@ def test_file_packager_unicode(self):
23172317
open(full, 'w').write('data')
23182318
proc = run_process([PYTHON, FILE_PACKAGER, 'test.data', '--preload', full], stdout=PIPE, stderr=PIPE)
23192319
assert len(proc.stdout) > 0, proc.stderr
2320-
assert len(proc.stderr) == 0, proc.stderr
23212320
assert unicode_name in proc.stdout, proc.stdout
23222321
print(len(proc.stderr))
23232322

@@ -2345,6 +2344,16 @@ def test_crunch(self):
23452344
Popen([PYTHON, FILE_PACKAGER, 'test.data', '--crunch=32', '--preload', 'ship.dds'], stdout=open('pre.js', 'w')).communicate()
23462345
assert crunch_time < os.stat('ship.crn').st_mtime, 'Crunch was changed'
23472346

2347+
def test_file_packager_mention_FORCE_FILESYSTEM(self):
2348+
MESSAGE = 'Remember to build the main file with -s FORCE_FILESYSTEM=1 so that it includes support for loading this file package'
2349+
open('data.txt', 'w').write('data1')
2350+
# mention when running standalone
2351+
err = run_process([PYTHON, FILE_PACKAGER, 'test.data', '--preload', 'data.txt'], stdout=PIPE, stderr=PIPE).stderr
2352+
self.assertContained(MESSAGE, err)
2353+
# do not mention from emcc
2354+
err = run_process([PYTHON, EMCC, path_from_root('tests', 'hello_world.c'), '--preload-file', 'data.txt'], stdout=PIPE, stderr=PIPE).stderr
2355+
assert len(err) == 0, err
2356+
23482357
def test_headless(self):
23492358
shutil.copyfile(path_from_root('tests', 'screenshot.png'), os.path.join(self.get_dir(), 'example.png'))
23502359
Popen([PYTHON, EMCC, path_from_root('tests', 'sdl_headless.c'), '-s', 'HEADLESS=1']).communicate()
@@ -5660,12 +5669,13 @@ def test_underscore_exit(self):
56605669
self.assertContained('', run_js('a.out.js', assert_returncode=0))
56615670

56625671
def test_file_packager_huge(self):
5672+
MESSAGE = 'warning: file packager is creating an asset bundle of 257 MB. this is very large, and browsers might have trouble loading it'
56635673
open('huge.dat', 'w').write('a'*(1024*1024*257))
56645674
open('tiny.dat', 'w').write('a')
56655675
err = run_process([PYTHON, FILE_PACKAGER, 'test.data', '--preload', 'tiny.dat'], stdout=PIPE, stderr=PIPE).stderr
5666-
assert err == '', err
5676+
self.assertNotContained(MESSAGE, err)
56675677
err = run_process([PYTHON, FILE_PACKAGER, 'test.data', '--preload', 'huge.dat'], stdout=PIPE, stderr=PIPE).stderr
5668-
assert 'warning: file packager is creating an asset bundle of 257 MB. this is very large, and browsers might have trouble loading it' in err, err
5678+
self.assertContained(MESSAGE, err)
56695679
self.clear()
56705680

56715681
def test_nosplit(self): # relooper shouldn't split nodes if -Os or -Oz
@@ -6828,6 +6838,12 @@ def test_dash_s(self):
68286838
print(check_execute([PYTHON, EMCC, path_from_root('tests', 'hello_world.cpp'), '-s', '-std=c++03']))
68296839
self.assertContained('hello, world!', run_js('a.out.js'))
68306840

6841+
def test_dash_s_error(self):
6842+
# missing quotes
6843+
err = run_process([PYTHON, EMCC, path_from_root('tests', 'hello_world.cpp'), "-s", "EXTRA_EXPORTED_RUNTIME_METHODS=[addOnPostRun]"], stderr=PIPE, check=False).stderr
6844+
self.assertContained('NameError', err) # it failed
6845+
self.assertContained('one possible cause of this is missing quotation marks', err) # but we suggested the fix
6846+
68316847
def test_python_2_3(self): # check emcc/em++ can be called by any python
68326848
print()
68336849
for python in ['python', 'python2', 'python3']:

tools/file_packager.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@
201201
if not has_preloaded or jsoutput == None:
202202
assert not separate_metadata, 'cannot separate-metadata without both --preloaded files and a specified --js-output'
203203

204+
if not from_emcc:
205+
print('Remember to build the main file with -s FORCE_FILESYSTEM=1 so that it includes support for loading this file package', file=sys.stderr)
206+
204207
ret = ''
205208
# emcc.py will add this to the output itself, so it is only needed for standalone calls
206209
if not from_emcc:

0 commit comments

Comments
 (0)