Skip to content

Commit

Permalink
[emcc.py] Consolidate early-exit flag handling. NFC (#23437)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 authored Jan 16, 2025
1 parent f3a4b65 commit a2ab73a
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,8 @@ def run(args):
if not shared.SKIP_SUBPROCS:
shared.check_sanity()

# Begin early-exit flag handling.

if '--version' in args:
print(version_string())
print('''\
Expand Down Expand Up @@ -608,45 +610,26 @@ def run(args):
print(shared.shlex_join(parts[1:]))
return 0

if 'EMMAKEN_NO_SDK' in os.environ:
exit_with_error('EMMAKEN_NO_SDK is no longer supported. The standard -nostdlib and -nostdinc flags should be used instead')

if 'EMMAKEN_COMPILER' in os.environ:
exit_with_error('`EMMAKEN_COMPILER` is no longer supported.\n' +
'Please use the `LLVM_ROOT` and/or `COMPILER_WRAPPER` config settings instead')

if 'EMMAKEN_CFLAGS' in os.environ:
exit_with_error('`EMMAKEN_CFLAGS` is no longer supported, please use `EMCC_CFLAGS` instead')

if 'EMCC_REPRODUCE' in os.environ:
options.reproduce = os.environ['EMCC_REPRODUCE']

# For internal consistency, ensure we don't attempt or read or write any link time
# settings until we reach the linking phase.
settings.limit_settings(COMPILE_TIME_SETTINGS)

newargs, input_files = phase_setup(options, state, newargs)

if '-dumpmachine' in newargs or '-print-target-triple' in newargs or '--print-target-triple' in newargs:
if '-dumpmachine' in args or '-print-target-triple' in args or '--print-target-triple' in args:
print(shared.get_llvm_target())
return 0

if '-print-search-dirs' in newargs or '--print-search-dirs' in newargs:
if '-print-search-dirs' in args or '--print-search-dirs' in args:
print(f'programs: ={config.LLVM_ROOT}')
print(f'libraries: ={cache.get_lib_dir(absolute=True)}')
return 0

if '-print-resource-dir' in newargs:
shared.check_call([clang] + newargs)
if '-print-resource-dir' in args:
shared.check_call([clang] + args)
return 0

if '-print-libgcc-file-name' in newargs or '--print-libgcc-file-name' in newargs:
if '-print-libgcc-file-name' in args or '--print-libgcc-file-name' in args:
settings.limit_settings(None)
compiler_rt = system_libs.Library.get_usable_variations()['libcompiler_rt']
print(compiler_rt.get_path(absolute=True))
return 0

print_file_name = [a for a in newargs if a.startswith(('-print-file-name=', '--print-file-name='))]
print_file_name = [a for a in args if a.startswith(('-print-file-name=', '--print-file-name='))]
if print_file_name:
libname = print_file_name[-1].split('=')[1]
system_libpath = cache.get_lib_dir(absolute=True)
Expand All @@ -657,6 +640,27 @@ def run(args):
print(libname)
return 0

# End early-exit flag handling

if 'EMMAKEN_NO_SDK' in os.environ:
exit_with_error('EMMAKEN_NO_SDK is no longer supported. The standard -nostdlib and -nostdinc flags should be used instead')

if 'EMMAKEN_COMPILER' in os.environ:
exit_with_error('`EMMAKEN_COMPILER` is no longer supported.\n' +
'Please use the `LLVM_ROOT` and/or `COMPILER_WRAPPER` config settings instead')

if 'EMMAKEN_CFLAGS' in os.environ:
exit_with_error('`EMMAKEN_CFLAGS` is no longer supported, please use `EMCC_CFLAGS` instead')

if 'EMCC_REPRODUCE' in os.environ:
options.reproduce = os.environ['EMCC_REPRODUCE']

# For internal consistency, ensure we don't attempt or read or write any link time
# settings until we reach the linking phase.
settings.limit_settings(COMPILE_TIME_SETTINGS)

newargs, input_files = phase_setup(options, state, newargs)

if options.reproduce:
create_reproduce_file(options.reproduce, args)

Expand Down

0 comments on commit a2ab73a

Please sign in to comment.