Skip to content

Commit

Permalink
Warn when setting used on the command line more than once
Browse files Browse the repository at this point in the history
See #19938
  • Loading branch information
sbc100 committed Mar 6, 2024
1 parent 2a9af50 commit d54431e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ See docs/process.md for more on how version tagging works.

3.1.56 (in development)
-----------------------
- emscripten will now generate an `unused-command-line-argument` warning if
a `-s` setting is specified more than once on the command line with
conflicting values. In this case the first setting is ignored. (#21464)

3.1.55 - 03/01/24
-----------------
Expand Down
3 changes: 3 additions & 0 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,9 @@ def phase_parse_arguments(state):
for s in settings_changes:
key, value = s.split('=', 1)
key, value = normalize_boolean_setting(key, value)
old_value = user_settings.get(key)
if old_value and old_value != value:
diagnostics.warning('unused-command-line-argument', f'-s{key} specified multiple times. Ignoring previous value (`{old_value}`)')
user_settings[key] = value

# STRICT is used when applying settings so it needs to be applied first before
Expand Down
2 changes: 1 addition & 1 deletion test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ def setUp(self):
# For historical reasons emcc compiles and links as C++ by default.
# However we want to run our tests in a more strict manner. We can
# remove this if the issue above is ever fixed.
self.set_setting('NO_DEFAULT_TO_CXX')
self.set_setting('DEFAULT_TO_CXX', 0)
self.ldflags = []
# Increate stack trace limit to maximise usefulness of test failure reports
self.node_args = ['--stack-trace-limit=50']
Expand Down
3 changes: 2 additions & 1 deletion test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9153,8 +9153,9 @@ def test_pthread_create_embind_stack_check(self):
# embind should work with stack overflow checks (see #12356)
self.set_setting('STACK_OVERFLOW_CHECK', 2)
self.set_setting('EXIT_RUNTIME')
self.set_setting('DEFAULT_TO_CXX')
self.emcc_args += ['-lembind']
self.do_run_in_out_file_test('core/pthread/create.c', emcc_args=['-sDEFAULT_TO_CXX'])
self.do_run_in_out_file_test('core/pthread/create.c')

@node_pthreads
def test_pthread_exceptions(self):
Expand Down
4 changes: 4 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -7811,6 +7811,10 @@ def test_dash_s_bad_json_types(self):
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sEXPORTED_FUNCTIONS=[{"a":1}]'])
self.assertContained("list members in settings must be strings (not $<class 'dict'>)", err)

def test_dash_s_repeated(self):
err = self.expect_fail([EMCC, '-Werror', test_file('hello_world.c'), '-sEXPORTED_FUNCTIONS=foo', '-sEXPORTED_FUNCTIONS=bar'])
self.assertContained('emcc: error: -sEXPORTED_FUNCTIONS specified multiple times. Ignoring previous value (`foo`) [-Wunused-command-line-argument]', err)

def test_zeroinit(self):
create_file('src.c', r'''
#include <stdio.h>
Expand Down

0 comments on commit d54431e

Please sign in to comment.