Skip to content

Commit c814217

Browse files
committed
Refactor legacy cmdline flag handling
This does turn some warnings into errors, but I also think its appropriate to error when unsupported command line flags are passed.
1 parent 23242cb commit c814217

File tree

2 files changed

+22
-35
lines changed

2 files changed

+22
-35
lines changed

test/test_other.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3691,9 +3691,7 @@ def test_embind_tsgen_exceptions(self, legacy):
36913691
# Check that when Wasm exceptions and assertions are enabled bindings still generate.
36923692
self.run_process([EMXX, test_file('other/embind_tsgen.cpp'),
36933693
'-lembind', '-fwasm-exceptions', '-sASSERTIONS',
3694-
# Use the deprecated `--embind-emit-tsd` to ensure it
3695-
# still works until removed.
3696-
'--embind-emit-tsd', 'embind_tsgen.d.ts', '-Wno-deprecated'] +
3694+
'--emit-tsd', 'embind_tsgen.d.ts', '-Wno-deprecated'] +
36973695
self.get_cflags())
36983696
self.assertFileContents(test_file('other/embind_tsgen.d.ts'), read_file('embind_tsgen.d.ts'))
36993697

@@ -11494,11 +11492,12 @@ def test_backwards_deps_in_archive(self):
1149411492

1149511493
def test_warning_flags(self):
1149611494
self.run_process([EMCC, '-c', '-o', 'hello.o', test_file('hello_world.c')])
11497-
cmd = [EMCC, 'hello.o', '-o', 'a.js', '-g', '--llvm-opts=""']
11495+
# -g4 will generte a deprecated warning
11496+
cmd = [EMCC, 'hello.o', '-o', 'a.js', '-g4']
1149811497

1149911498
# warning that is enabled by default
1150011499
stderr = self.run_process(cmd, stderr=PIPE).stderr
11501-
self.assertContained('emcc: warning: --llvm-opts is deprecated. All non-emcc args are passed through to clang. [-Wdeprecated]', stderr)
11500+
self.assertContained('emcc: warning: please replace -g4 with -gsource-map [-Wdeprecated]', stderr)
1150211501

1150311502
# -w to suppress warnings
1150411503
stderr = self.run_process(cmd + ['-w'], stderr=PIPE).stderr
@@ -11509,12 +11508,12 @@ def test_warning_flags(self):
1150911508
self.assertNotContained('warning', stderr)
1151011509

1151111510
# with -Werror should fail
11512-
expected = 'error: --llvm-opts is deprecated. All non-emcc args are passed through to clang. [-Wdeprecated] [-Werror]'
11511+
expected = 'error: please replace -g4 with -gsource-map [-Wdeprecated] [-Werror]'
1151311512
self.assert_fail(cmd + ['-Werror'], expected)
1151411513

1151511514
# with -Werror + -Wno-error=<type> should only warn
1151611515
stderr = self.run_process(cmd + ['-Werror', '-Wno-error=deprecated'], stderr=PIPE).stderr
11517-
self.assertContained('emcc: warning: --llvm-opts is deprecated. All non-emcc args are passed through to clang. [-Wdeprecated]', stderr)
11516+
self.assertContained('emcc: warning: please replace -g4 with -gsource-map [-Wdeprecated]', stderr)
1151811517

1151911518
# check that `-Werror=foo` also enales foo
1152011519
expected = 'error: use of legacy setting: TOTAL_MEMORY (setting renamed to INITIAL_MEMORY) [-Wlegacy-settings] [-Werror]'
@@ -14072,7 +14071,7 @@ def test_wasi_with_sjlj(self):
1407214071
self.do_runf('core/test_longjmp.c', cflags=self.get_cflags())
1407314072

1407414073
def test_memory_init_file_unsupported(self):
14075-
self.assert_fail([EMCC, test_file('hello_world.c'), '--memory-init-file=1'], 'error: --memory-init-file is no longer supported')
14074+
self.assert_fail([EMCC, test_file('hello_world.c'), '-Werror', '--memory-init-file=1'], 'error: --memory-init-file is no longer supported')
1407614075

1407714076
@node_pthreads
1407814077
def test_node_pthreads_err_out(self):

tools/cmdline.py

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ def parse_args(newargs): # noqa: C901, PLR0912, PLR0915
210210
"""
211211
should_exit = False
212212
skip = False
213+
LEGACY_ARGS = {'--js-opts', '--llvm-opts', '--llvm-lto', '--memory-init-file'}
214+
LEGACY_FLAGS = {'--separate-asm', '--jcache', '--proxy-to-worker', '--default-obj-ext',
215+
'--embind-emit-tsd', '--remove-duplicates', '--no-heap-copy'}
213216

214217
for i in range(len(newargs)):
215218
if skip:
@@ -238,9 +241,9 @@ def check_flag(value):
238241
return False
239242

240243
def check_arg(name):
241-
nonlocal arg_value
244+
nonlocal arg, arg_value
242245
if arg.startswith(name) and '=' in arg:
243-
arg_value = arg.split('=', 1)[1]
246+
arg, arg_value = arg.split('=', 1)
244247
newargs[i] = ''
245248
return True
246249
if arg == name:
@@ -265,6 +268,16 @@ def consume_arg_file():
265268
exit_with_error("'%s': file not found: '%s'" % (arg, name))
266269
return name
267270

271+
if arg in LEGACY_FLAGS:
272+
diagnostics.warning('deprecated', f'{arg} is no longer supported')
273+
continue
274+
275+
for l in LEGACY_ARGS:
276+
if check_arg(l):
277+
consume_arg()
278+
diagnostics.warning('deprecated', f'{arg} is no longer supported')
279+
continue
280+
268281
if arg.startswith('-s') and is_dash_s_for_emcc(newargs, i):
269282
s_arg = arg
270283
if arg == '-s':
@@ -301,11 +314,6 @@ def consume_arg_file():
301314
newargs[i] = '-O3'
302315
level = 3
303316
settings.OPT_LEVEL = level
304-
elif check_arg('--js-opts'):
305-
logger.warning('--js-opts ignored when using llvm backend')
306-
consume_arg()
307-
elif check_arg('--llvm-opts'):
308-
diagnostics.warning('deprecated', '--llvm-opts is deprecated. All non-emcc args are passed through to clang.')
309317
elif arg.startswith('-flto'):
310318
if '=' in arg:
311319
settings.LTO = arg.split('=')[1]
@@ -315,9 +323,6 @@ def consume_arg_file():
315323
settings.LTO = 0
316324
elif arg == "--save-temps":
317325
options.save_temps = True
318-
elif check_arg('--llvm-lto'):
319-
logger.warning('--llvm-lto ignored when using llvm backend')
320-
consume_arg()
321326
elif check_arg('--closure-args'):
322327
args = consume_arg()
323328
settings.CLOSURE_ARGS += shlex.split(args)
@@ -432,8 +437,6 @@ def consume_arg_file():
432437
options.exclude_files.append(consume_arg())
433438
elif check_flag('--use-preload-cache'):
434439
options.use_preload_cache = True
435-
elif check_flag('--no-heap-copy'):
436-
diagnostics.warning('legacy-settings', 'ignoring legacy flag --no-heap-copy (that is the only mode supported now)')
437440
elif check_flag('--use-preload-plugins'):
438441
options.use_preload_plugins = True
439442
elif check_flag('--ignore-dynamic-linking'):
@@ -446,17 +449,10 @@ def consume_arg_file():
446449
options.shell_path = consume_arg_file()
447450
elif check_arg('--source-map-base'):
448451
options.source_map_base = consume_arg()
449-
elif check_arg('--embind-emit-tsd'):
450-
diagnostics.warning('deprecated', '--embind-emit-tsd is deprecated. Use --emit-tsd instead.')
451-
options.emit_tsd = consume_arg()
452452
elif check_arg('--emit-tsd'):
453453
options.emit_tsd = consume_arg()
454454
elif check_flag('--no-entry'):
455455
options.no_entry = True
456-
elif check_flag('--remove-duplicates'):
457-
diagnostics.warning('legacy-settings', '--remove-duplicates is deprecated as it is no longer needed. If you cannot link without it, file a bug with a testcase')
458-
elif check_flag('--jcache'):
459-
logger.error('jcache is no longer supported')
460456
elif check_arg('--cache'):
461457
config.CACHE = os.path.abspath(consume_arg())
462458
cache.setup()
@@ -481,14 +477,8 @@ def consume_arg_file():
481477
elif check_flag('--show-ports'):
482478
ports.show_ports()
483479
should_exit = True
484-
elif check_arg('--memory-init-file'):
485-
exit_with_error('--memory-init-file is no longer supported')
486-
elif check_flag('--proxy-to-worker'):
487-
exit_with_error('--proxy-to-worker is no longer supported')
488480
elif check_arg('--valid-abspath'):
489481
options.valid_abspaths.append(consume_arg())
490-
elif check_flag('--separate-asm'):
491-
exit_with_error('cannot --separate-asm with the wasm backend, since not emitting asm.js')
492482
elif arg.startswith(('-I', '-L')):
493483
path_name = arg[2:]
494484
# Look for '/' explicitly so that we can also diagnose identically if -I/foo/bar is passed on Windows.
@@ -549,8 +539,6 @@ def consume_arg_file():
549539
settings.DISABLE_EXCEPTION_CATCHING = 1
550540
elif arg == '-ffast-math':
551541
options.fast_math = True
552-
elif check_arg('--default-obj-ext'):
553-
exit_with_error('--default-obj-ext is no longer supported by emcc')
554542
elif arg.startswith('-fsanitize=cfi'):
555543
exit_with_error('emscripten does not currently support -fsanitize=cfi')
556544
elif check_arg('--output_eol') or check_arg('--output-eol'):

0 commit comments

Comments
 (0)