Skip to content

Commit 8096632

Browse files
authored
Simplify emcc test helper method. NFC (emscripten-core#25699)
It shorter and simpler to just use `-o` rather than specific `output_filename` argument here.
1 parent 7e47a69 commit 8096632

File tree

3 files changed

+29
-33
lines changed

3 files changed

+29
-33
lines changed

test/common.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,12 +1325,10 @@ def run_process(self, cmd, check=True, **kwargs):
13251325
sys.stderr.write(rtn.stderr)
13261326
return rtn
13271327

1328-
def emcc(self, filename, args=[], output_filename=None, **kwargs): # noqa
1328+
def emcc(self, filename, args=[], **kwargs): # noqa
13291329
filename = maybe_test_file(filename)
13301330
compile_only = '-c' in args or '-sSIDE_MODULE' in args
13311331
cmd = [compiler_for(filename), filename] + self.get_cflags(compile_only=compile_only) + args
1332-
if output_filename:
1333-
cmd += ['-o', output_filename]
13341332
self.run_process(cmd, **kwargs)
13351333

13361334
# Shared test code between main suite and others

test/test_core.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7965,17 +7965,15 @@ def test_source_map(self):
79657965
no_maps_filename = 'no-maps.out.js'
79667966

79677967
assert '-gsource-map' not in self.cflags
7968-
self.emcc('src.cpp', output_filename=out_filename)
7968+
self.emcc('src.cpp', ['-o', out_filename])
79697969
# the file name may find its way into the generated code, so make sure we
79707970
# can do an apples-to-apples comparison by compiling with the same file name
79717971
shutil.move(out_filename, no_maps_filename)
79727972
no_maps_file = read_file(no_maps_filename)
79737973
no_maps_file = re.sub(' *//[@#].*$', '', no_maps_file, flags=re.MULTILINE)
79747974
self.cflags.append('-gsource-map')
79757975

7976-
self.emcc(os.path.abspath('src.cpp'),
7977-
self.get_cflags(),
7978-
out_filename)
7976+
self.emcc(os.path.abspath('src.cpp'), ['-o', out_filename])
79797977
map_referent = out_filename if self.is_wasm2js() else wasm_filename
79807978
# after removing the @line and @sourceMappingURL comments, the build
79817979
# result should be identical to the non-source-mapped debug version.

test/test_other.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ def test_multiply_defined_libsymbols(self):
14091409
''')
14101410

14111411
self.cflags.remove('-Werror')
1412-
self.emcc('libA.c', ['-shared'], output_filename='libA.so')
1412+
self.emcc('libA.c', ['-shared', '-o', 'libA.so'])
14131413

14141414
self.emcc('a2.c', ['-r', '-L.', '-lA', '-o', 'a2.o'])
14151415
self.emcc('b2.c', ['-r', '-L.', '-lA', '-o', 'b2.o'])
@@ -1558,8 +1558,8 @@ def test_redundant_link(self):
15581558
''')
15591559

15601560
self.cflags.remove('-Werror')
1561-
self.emcc('libA.c', ['-shared'], output_filename='libA.so')
1562-
self.emcc('main.c', ['libA.so', 'libA.so'], output_filename='a.out.js')
1561+
self.emcc('libA.c', ['-shared', '-o', 'libA.so'])
1562+
self.emcc('main.c', ['libA.so', 'libA.so', '-o', 'a.out.js'])
15631563
self.assertContained('result: 1', self.run_js('a.out.js'))
15641564

15651565
@no_mac('https://github.com/emscripten-core/emscripten/issues/16649')
@@ -1653,7 +1653,7 @@ def test_minimal_runtime_export_all_modularize(self):
16531653
EMSCRIPTEN_KEEPALIVE void libf2() { printf("libf2\n"); }
16541654
''')
16551655

1656-
self.emcc('main.c', ['-sMODULARIZE=1', '-sMINIMAL_RUNTIME=2', '-sEXPORT_ALL', '-sEXPORT_ES6'], output_filename='test.mjs')
1656+
self.emcc('main.c', ['-sMODULARIZE=1', '-sMINIMAL_RUNTIME=2', '-sEXPORT_ALL', '-sEXPORT_ES6', '-o', 'test.mjs'])
16571657

16581658
# We must expose __dirname and require globally because emscripten
16591659
# uses those under the hood.
@@ -1714,11 +1714,11 @@ def test_export_all_and_exported_functions(self):
17141714
''')
17151715

17161716
# libfunc2 should not be linked by default, even with EXPORT_ALL
1717-
self.emcc('lib.c', ['-sEXPORT_ALL', '--pre-js', 'pre.js'], output_filename='a.out.js')
1717+
self.emcc('lib.c', ['-sEXPORT_ALL', '--pre-js', 'pre.js', '-o', 'a.out.js'])
17181718
err = self.run_js('a.out.js', assert_returncode=NON_ZERO)
17191719
self.assertContained('_libfunc2 is not defined', err)
17201720

1721-
self.emcc('lib.c', ['-sEXPORTED_FUNCTIONS=_libfunc2', '-sEXPORT_ALL', '--pre-js', 'pre.js'], output_filename='a.out.js')
1721+
self.emcc('lib.c', ['-sEXPORTED_FUNCTIONS=_libfunc2', '-sEXPORT_ALL', '--pre-js', 'pre.js', '-o', 'a.out.js'])
17221722
self.assertContained('libfunc\n', self.run_js('a.out.js'))
17231723

17241724
@all_engines
@@ -2524,28 +2524,28 @@ def test_sdl_get_key_name(self):
25242524

25252525
@requires_network
25262526
def test_sdl2_mixer_wav(self):
2527-
self.emcc('browser/test_sdl2_mixer_wav.c', ['-sUSE_SDL_MIXER=2'], output_filename='a.out.js')
2528-
self.emcc('browser/test_sdl2_mixer_wav.c', ['--use-port=sdl2_mixer'], output_filename='a.out.js')
2529-
self.emcc('browser/test_sdl2_mixer_wav.c', ['--use-port=sdl2_mixer:formats=ogg'], output_filename='a.out.js')
2527+
self.emcc('browser/test_sdl2_mixer_wav.c', ['-sUSE_SDL_MIXER=2', '-o', 'a.out.js'])
2528+
self.emcc('browser/test_sdl2_mixer_wav.c', ['--use-port=sdl2_mixer', '-o', 'a.out.js'])
2529+
self.emcc('browser/test_sdl2_mixer_wav.c', ['--use-port=sdl2_mixer:formats=ogg', '-o', 'a.out.js'])
25302530

25312531
def test_sdl2_linkable(self):
25322532
# Ensure that SDL2 can be built with MAIN_MODULE. This implies there are no undefined
25332533
# symbols in the library (because MAIN_MODULE=1 includes the entire library).
2534-
self.emcc('browser/test_sdl2_misc.c', ['-sMAIN_MODULE', '-sUSE_SDL=2'], output_filename='a.out.js')
2535-
self.emcc('browser/test_sdl2_misc.c', ['-sMAIN_MODULE', '--use-port=sdl2'], output_filename='a.out.js')
2534+
self.emcc('browser/test_sdl2_misc.c', ['-sMAIN_MODULE', '-sUSE_SDL=2', '-o', 'a.out.js'])
2535+
self.emcc('browser/test_sdl2_misc.c', ['-sMAIN_MODULE', '--use-port=sdl2', '-o', 'a.out.js'])
25362536

25372537
def test_sdl3_linkable(self):
25382538
# Ensure that SDL3 can be built with MAIN_MODULE. This implies there are no undefined
25392539
# symbols in the library (because MAIN_MODULE=1 includes the entire library).
25402540
self.cflags.append('-Wno-experimental')
2541-
self.emcc('browser/test_sdl3_misc.c', ['-sMAIN_MODULE', '-sUSE_SDL=3'], output_filename='a.out.js')
2542-
self.emcc('browser/test_sdl3_misc.c', ['-sMAIN_MODULE', '--use-port=sdl3'], output_filename='a.out.js')
2541+
self.emcc('browser/test_sdl3_misc.c', ['-sMAIN_MODULE', '-sUSE_SDL=3', '-o', 'a.out.js'])
2542+
self.emcc('browser/test_sdl3_misc.c', ['-sMAIN_MODULE', '--use-port=sdl3', '-o', 'a.out.js'])
25432543

25442544
@requires_network
25452545
def test_sdl2_gfx_linkable(self):
25462546
# Same as above but for sdl2_gfx library
2547-
self.emcc('browser/test_sdl2_misc.c', ['-Wl,-fatal-warnings', '-sMAIN_MODULE', '-sUSE_SDL_GFX=2'], output_filename='a.out.js')
2548-
self.emcc('browser/test_sdl2_misc.c', ['-Wl,-fatal-warnings', '-sMAIN_MODULE', '--use-port=sdl2_gfx'], output_filename='a.out.js')
2547+
self.emcc('browser/test_sdl2_misc.c', ['-Wl,-fatal-warnings', '-sMAIN_MODULE', '-sUSE_SDL_GFX=2', '-o', 'a.out.js'])
2548+
self.emcc('browser/test_sdl2_misc.c', ['-Wl,-fatal-warnings', '-sMAIN_MODULE', '--use-port=sdl2_gfx', '-o', 'a.out.js'])
25492549

25502550
@requires_network
25512551
def test_libpng(self):
@@ -2628,7 +2628,7 @@ def test_freetype(self):
26282628
@requires_network
26292629
def test_freetype_with_pthreads(self):
26302630
# Verify that freetype supports compilation requiring pthreads
2631-
self.emcc('test_freetype.c', ['-pthread', '-sUSE_FREETYPE'], output_filename='a.out.js')
2631+
self.emcc('test_freetype.c', ['-pthread', '-sUSE_FREETYPE', '-o', 'a.out.js'])
26322632

26332633
@requires_network
26342634
def test_icu(self):
@@ -2638,8 +2638,8 @@ def test_icu(self):
26382638
@requires_network
26392639
def test_sdl2_ttf(self):
26402640
# This is a compile-only to test to verify that sdl2-ttf (and freetype and harfbuzz) are buildable.
2641-
self.emcc('browser/test_sdl2_ttf.c', args=['-sUSE_SDL=2', '-sUSE_SDL_TTF=2'], output_filename='a.out.js')
2642-
self.emcc('browser/test_sdl2_ttf.c', args=['--use-port=sdl2', '--use-port=sdl2_ttf'], output_filename='a.out.js')
2641+
self.emcc('browser/test_sdl2_ttf.c', args=['-sUSE_SDL=2', '-sUSE_SDL_TTF=2', '-o', 'a.out.js'])
2642+
self.emcc('browser/test_sdl2_ttf.c', args=['--use-port=sdl2', '--use-port=sdl2_ttf', '-o', 'a.out.js'])
26432643

26442644
@requires_network
26452645
def test_contrib_ports(self):
@@ -3184,7 +3184,7 @@ def test_dwarf_sourcemap_names(self):
31843184
(['-gsource-map', '-Og', '-sERROR_ON_WASM_CHANGES_AFTER_LINK'], False, True, False),
31853185
]:
31863186
print(flags, expect_dwarf, expect_sourcemap, expect_names)
3187-
self.emcc(test_file(source_file), flags, js_file)
3187+
self.emcc(test_file(source_file), flags + ['-o', js_file])
31883188
self.assertExists(js_file)
31893189
assertion = self.assertIn if expect_dwarf else self.assertNotIn
31903190
self.verify_dwarf(wasm_file, assertion)
@@ -6063,7 +6063,7 @@ def test_link_with_bad_o_in_a(self):
60636063
@requires_node
60646064
def test_require(self):
60656065
inname = test_file('hello_world.c')
6066-
self.emcc(inname, args=['-sASSERTIONS=0'], output_filename='a.out.js')
6066+
self.emcc(inname, args=['-sASSERTIONS=0', '-o', 'a.out.js'])
60676067
create_file('run.js', 'require("./a.out.js")')
60686068
output = self.run_js('run.js')
60696069
self.assertEqual('hello, world!\n', output)
@@ -6128,7 +6128,7 @@ def test_modularize_run_dependency(self):
61286128
''')
61296129
self.set_setting('DEFAULT_LIBRARY_FUNCS_TO_INCLUDE', '$addRunDependency,$removeRunDependency')
61306130
self.cflags += ['-sEXPORT_ES6', '-sMODULARIZE', '-sWASM_ASYNC_COMPILATION=0', '--pre-js=pre.js']
6131-
self.emcc('hello_world.c', output_filename='hello_world.mjs')
6131+
self.emcc('hello_world.c', ['-o', 'hello_world.mjs'])
61326132
self.assertContained('add-dep\nremove-dep\nhello, world!\ngot module\n', self.run_js('run.mjs'))
61336133

61346134
def test_modularize_instantiation_error(self):
@@ -6186,7 +6186,7 @@ def test_pthread_print_override_modularize(self):
61866186
main();
61876187
''')
61886188

6189-
self.emcc('main.c', output_filename='test.js')
6189+
self.emcc('main.c', ['-o' 'test.js'])
61906190
output = self.run_js('main.js')
61916191
self.assertNotContained('hello, world!', output)
61926192
self.assertContained('hello, earth!', output)
@@ -9494,7 +9494,7 @@ def test_emcc_sourcemap_options(self, prefixes, sources):
94949494
prefixes = [p.replace('<cwd>', cwd) for p in prefixes]
94959495
self.set_setting('SOURCE_MAP_PREFIXES', prefixes)
94969496
args = ['-gsource-map=inline' if sources else '-gsource-map']
9497-
self.emcc(src_file, args=args, output_filename='test.js')
9497+
self.emcc(src_file, args=args + ['-o', 'test.js'])
94989498
output = read_file('test.wasm.map')
94999499
# Check source file resolution
95009500
p = wasm_sourcemap.Prefixes(prefixes, base_path=cwd)
@@ -12360,7 +12360,7 @@ def test_em_js_dylink_address(self):
1236012360
# See https://github.com/emscripten-core/emscripten/issues/18494
1236112361
self.do_runf('other/test_em_js_main_module_address.c')
1236212362

12363-
self.emcc('other/test_em_js_main_module_address.c', ['-sSIDE_MODULE'], output_filename='libside.so')
12363+
self.emcc('other/test_em_js_main_module_address.c', ['-sSIDE_MODULE', '-o', 'libside.so'])
1236412364
expected = 'Aborted(Assertion failed: Missing signature argument to addFunction: () => { err("hello"); })'
1236512365
self.do_run('', expected, cflags=['-sMAIN_MODULE=2', 'libside.so'], assert_returncode=NON_ZERO)
1236612366

@@ -14998,10 +14998,10 @@ def test_parsetools_make_removed_fs_assert(self):
1499814998

1499914999
removed_fs_assert_content = "IDBFS is no longer included by default"
1500015000

15001-
self.emcc('hello_world.c', output_filename='hello_world.js')
15001+
self.emcc('hello_world.c', ['-o', 'hello_world.js'])
1500215002
self.assertContained(removed_fs_assert_content, read_file('hello_world.js'))
1500315003

15004-
self.emcc('hello_world.c', ['-lidbfs.js'], output_filename='hello_world.js')
15004+
self.emcc('hello_world.c', ['-lidbfs.js', '-o', 'hello_world.js'])
1500515005
self.assertNotContained(removed_fs_assert_content, read_file('hello_world.js'))
1500615006

1500715007
@crossplatform

0 commit comments

Comments
 (0)