Skip to content

Commit 9c0230b

Browse files
committed
wip web [ci skip]
1 parent dfbc24e commit 9c0230b

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

emcc.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -841,9 +841,18 @@ def setting_sub(s):
841841
wasm_text_target = asm_target.replace('.asm.js', '.wast') # ditto, might not be used
842842
wasm_binary_target = asm_target.replace('.asm.js', '.wasm') # ditto, might not be used
843843

844-
if final_suffix == 'html' and not options.separate_asm and ('PRECISE_F32=2' in settings_changes or 'USE_PTHREADS=2' in settings_changes):
845-
options.separate_asm = True
846-
logging.warning('forcing separate asm output (--separate-asm), because -s PRECISE_F32=2 or -s USE_PTHREADS=2 was passed.')
844+
if final_suffix == 'html':
845+
if shared.Settings.ENVIRONMENT:
846+
if shared.Settings.ENVIRONMENT != 'web':
847+
logging.warning('Output is HTML, but ENVIRONMENT was set to "%s" != "web"' % shared.Settings.ENVIRONMENT)
848+
else:
849+
logging.debug('Output is HTML, so setting ENVIRONMENT to "web" (the .js will not run off the web)')
850+
shared.Settings.ENVIRONMENT = 'web'
851+
852+
if not options.separate_asm and ('PRECISE_F32=2' in settings_changes or 'USE_PTHREADS=2' in settings_changes):
853+
options.separate_asm = True
854+
logging.warning('forcing separate asm output (--separate-asm), because -s PRECISE_F32=2 or -s USE_PTHREADS=2 was passed.')
855+
847856
if options.separate_asm:
848857
shared.Settings.SEPARATE_ASM = shared.JS.get_subresource_location(asm_target)
849858

tests/test_browser.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3895,3 +3895,29 @@ def test_unicode_html_shell(self):
38953895
open(self.in_dir('shell.html'), 'w').write(open(path_from_root('src', 'shell.html')).read().replace('Emscripten-Generated Code', 'Emscripten-Generated Emoji 😅'))
38963896
subprocess.check_output([PYTHON, EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--shell-file', 'shell.html', '-o', 'test.html'])
38973897
self.run_browser('test.html', None, '/report_result?0')
3898+
3899+
def test_ENVIRONMENT(self):
3900+
for work in (1, 0):
3901+
for assertions in (0, 1):
3902+
if work and assertions: continue # we care about assertions when we fail
3903+
# tell the compiler to build with just that engine
3904+
args = []
3905+
if work:
3906+
args += ['-s', 'ENVIRONMENT="web"']
3907+
else:
3908+
args += ['-s', 'ENVIRONMENT="node"']
3909+
if assertions:
3910+
args += ['-s', 'ASSERTIONS=1']
3911+
print(work, assertions, args)
3912+
try:
3913+
self.btest('browser_test_hello_world.c', expected='0', args=args)
3914+
except Exception as e:
3915+
if not work:
3916+
if assertions:
3917+
# with assertions, an error should be shown
3918+
self.assertContained('not compiled with support for that', str(e))
3919+
else:
3920+
raise
3921+
js = open('src.cpp.o.js').read()
3922+
assert ('require(' in js) == ('node' in str(args)), 'we should have require() calls only if node js specified'
3923+

0 commit comments

Comments
 (0)