Skip to content

Commit 62f8c57

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 c6f9259 commit 62f8c57

File tree

2 files changed

+12
-32
lines changed

2 files changed

+12
-32
lines changed

test/test_other.py

Lines changed: 6 additions & 7 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

@@ -11495,11 +11493,12 @@ def test_backwards_deps_in_archive(self):
1149511493

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

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

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

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

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

1152011519
# check that `-Werror=foo` also enales foo
1152111520
expected = 'error: use of legacy setting: TOTAL_MEMORY (setting renamed to INITIAL_MEMORY) [-Wlegacy-settings] [-Werror]'

tools/cmdline.py

Lines changed: 6 additions & 25 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:
@@ -224,6 +227,9 @@ def parse_args(newargs): # noqa: C901, PLR0912, PLR0915
224227
arg = newargs[i]
225228
arg_value = None
226229

230+
if arg in LEGACY_FLAGS or any(arg.startswith(a) for a in LEGACY_ARGS):
231+
exit_with_error(f'{arg} is no longer supported')
232+
227233
if arg in CLANG_FLAGS_WITH_ARGS:
228234
# Ignore the next argument rather than trying to parse it. This is needed
229235
# because that next arg could, for example, start with `-o` and we don't want
@@ -301,11 +307,6 @@ def consume_arg_file():
301307
newargs[i] = '-O3'
302308
level = 3
303309
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.')
309310
elif arg.startswith('-flto'):
310311
if '=' in arg:
311312
settings.LTO = arg.split('=')[1]
@@ -315,9 +316,6 @@ def consume_arg_file():
315316
settings.LTO = 0
316317
elif arg == "--save-temps":
317318
options.save_temps = True
318-
elif check_arg('--llvm-lto'):
319-
logger.warning('--llvm-lto ignored when using llvm backend')
320-
consume_arg()
321319
elif check_arg('--closure-args'):
322320
args = consume_arg()
323321
settings.CLOSURE_ARGS += shlex.split(args)
@@ -432,8 +430,6 @@ def consume_arg_file():
432430
options.exclude_files.append(consume_arg())
433431
elif check_flag('--use-preload-cache'):
434432
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)')
437433
elif check_flag('--use-preload-plugins'):
438434
options.use_preload_plugins = True
439435
elif check_flag('--ignore-dynamic-linking'):
@@ -446,17 +442,10 @@ def consume_arg_file():
446442
options.shell_path = consume_arg_file()
447443
elif check_arg('--source-map-base'):
448444
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()
452445
elif check_arg('--emit-tsd'):
453446
options.emit_tsd = consume_arg()
454447
elif check_flag('--no-entry'):
455448
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')
460449
elif check_arg('--cache'):
461450
config.CACHE = os.path.abspath(consume_arg())
462451
cache.setup()
@@ -481,14 +470,8 @@ def consume_arg_file():
481470
elif check_flag('--show-ports'):
482471
ports.show_ports()
483472
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')
488473
elif check_arg('--valid-abspath'):
489474
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')
492475
elif arg.startswith(('-I', '-L')):
493476
path_name = arg[2:]
494477
# Look for '/' explicitly so that we can also diagnose identically if -I/foo/bar is passed on Windows.
@@ -549,8 +532,6 @@ def consume_arg_file():
549532
settings.DISABLE_EXCEPTION_CATCHING = 1
550533
elif arg == '-ffast-math':
551534
options.fast_math = True
552-
elif check_arg('--default-obj-ext'):
553-
exit_with_error('--default-obj-ext is no longer supported by emcc')
554535
elif arg.startswith('-fsanitize=cfi'):
555536
exit_with_error('emscripten does not currently support -fsanitize=cfi')
556537
elif check_arg('--output_eol') or check_arg('--output-eol'):

0 commit comments

Comments
 (0)