Skip to content

Commit 74f5428

Browse files
authored
Make command line options global. NFC (#25708)
Refactor only. This should allows us to start removing some of the internal settings that are currently used to communicate command line flags from part of the python codebase to another. We should only need to add internal settings when a setting needs to be available in the JS compiler.
1 parent e2fecb0 commit 74f5428

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

emcc.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
system_libs,
4141
utils,
4242
)
43-
from tools.cmdline import CLANG_FLAGS_WITH_ARGS
43+
from tools.cmdline import CLANG_FLAGS_WITH_ARGS, options
4444
from tools.response_file import substitute_response_files
4545
from tools.settings import (
4646
COMPILE_TIME_SETTINGS,
@@ -225,7 +225,7 @@ def main(args):
225225

226226
## Process argument and setup the compiler
227227
state = EmccState(args)
228-
options, newargs = cmdline.parse_arguments(state.orig_args)
228+
newargs = cmdline.parse_arguments(state.orig_args)
229229

230230
if not shared.SKIP_SUBPROCS:
231231
shared.check_sanity()
@@ -290,7 +290,7 @@ def main(args):
290290
# settings until we reach the linking phase.
291291
settings.limit_settings(COMPILE_TIME_SETTINGS)
292292

293-
phase_setup(options, state)
293+
phase_setup(state)
294294

295295
if '-print-resource-dir' in args or any(a.startswith('--print-prog-name') for a in args):
296296
shared.exec_process([clang] + compile.get_cflags(tuple(args)) + args)
@@ -384,7 +384,7 @@ def get_next_arg():
384384

385385

386386
@ToolchainProfiler.profile_block('setup')
387-
def phase_setup(options, state):
387+
def phase_setup(state):
388388
"""Second phase: configure and setup the compiler based on the specified settings and arguments.
389389
"""
390390

emscan-deps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
argv = sys.argv[1:]
1717

1818
# Parse and discard any emcc-specific flags (e.g. -sXXX).
19-
newargs = cmdline.parse_arguments(argv)[1]
19+
newargs = cmdline.parse_arguments(argv)
2020

2121
# Add any clang flags that emcc would add.
2222
newargs += compile.get_cflags(tuple(argv))

tools/cmdline.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ class EmccOptions:
114114
valid_abspaths: List[str] = []
115115

116116

117+
# Global/singleton EmccOptions
118+
options = EmccOptions()
119+
120+
117121
def is_int(s):
118122
try:
119123
int(s)
@@ -151,7 +155,7 @@ def version_string():
151155
return f'emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) {utils.EMSCRIPTEN_VERSION}{revision_suffix}'
152156

153157

154-
def is_valid_abspath(options, path_name):
158+
def is_valid_abspath(path_name):
155159
# Any path that is underneath the emscripten repository root must be ok.
156160
if utils.normalize_path(path_name).startswith(utils.normalize_path(utils.path_from_root())):
157161
return True
@@ -225,7 +229,6 @@ def parse_args(newargs): # noqa: C901, PLR0912, PLR0915
225229
226230
To revalidate these numbers, run `ruff check --select=C901,PLR091`.
227231
"""
228-
options = EmccOptions()
229232
should_exit = False
230233
skip = False
231234

@@ -495,7 +498,7 @@ def consume_arg_file():
495498
path_name = arg[2:]
496499
# Look for '/' explicitly so that we can also diagnose identically if -I/foo/bar is passed on Windows.
497500
# Python since 3.13 does not treat '/foo/bar' as an absolute path on Windows.
498-
if (path_name.startswith('/') or os.path.isabs(path_name)) and not is_valid_abspath(options, path_name):
501+
if (path_name.startswith('/') or os.path.isabs(path_name)) and not is_valid_abspath(path_name):
499502
# Of course an absolute path to a non-system-specific library or header
500503
# is fine, and you can ignore this warning. The danger are system headers
501504
# that are e.g. x86 specific and non-portable. The emscripten bundled
@@ -640,8 +643,7 @@ def consume_arg_file():
640643
if should_exit:
641644
sys.exit(0)
642645

643-
newargs = [a for a in newargs if a]
644-
return options, newargs
646+
return [a for a in newargs if a]
645647

646648

647649
def expand_byte_size_suffixes(value):
@@ -853,7 +855,7 @@ def parse_arguments(args):
853855
newargs[i] += newargs[i + 1]
854856
newargs[i + 1] = ''
855857

856-
options, newargs = parse_args(newargs)
858+
newargs = parse_args(newargs)
857859

858860
if options.post_link or options.oformat == OFormat.BARE:
859861
diagnostics.warning('experimental', '--oformat=bare/--post-link are experimental and subject to change.')
@@ -873,4 +875,4 @@ def parse_arguments(args):
873875
# Apply -s settings in newargs here (after optimization levels, so they can override them)
874876
apply_user_settings()
875877

876-
return options, newargs
878+
return newargs

0 commit comments

Comments
 (0)