MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / phase_linker_setup

Function phase_linker_setup

tools/link.py:810–1853  ·  view source on GitHub ↗

Future modifications should consider refactoring to reduce complexity. * The McCabe cyclomatiic complexity is currently 244 vs 10 recommended. * There are currently 252 branches vs 12 recommended. * There are currently 563 statements vs 50 recommended. To revalidate these numbers, run `ruf

(options, linker_args)

Source from the content-addressed store, hash-verified

808
809@ToolchainProfiler.profile_block('linker_setup')
810def phase_linker_setup(options, linker_args): # noqa: C901, PLR0912, PLR0915
811 """Future modifications should consider refactoring to reduce complexity.
812
813 * The McCabe cyclomatiic complexity is currently 244 vs 10 recommended.
814 * There are currently 252 branches vs 12 recommended.
815 * There are currently 563 statements vs 50 recommended.
816
817 To revalidate these numbers, run `ruff check --select=C901,PLR091`.
818 """
819 setup_environment_settings()
820
821 apply_library_settings(linker_args)
822
823 if options.shared and not settings.FAKE_DYLIBS:
824 default_setting('SIDE_MODULE', 1)
825
826 if not settings.SIDE_MODULE and not settings.FAKE_DYLIBS:
827 options.dylibs = get_dylibs(options, linker_args)
828 # If there are any dynamic libraries on the command line then enable
829 # `MAIN_MODULE` by default in order to produce JS code that can load them.
830 if options.dylibs and not settings.MAIN_MODULE:
831 default_setting('MAIN_MODULE', 2)
832
833 linker_args += calc_extra_ldflags(options)
834
835 # We used to do this check during on startup during `check_sanity`, but
836 # we now only do it when linking, in order to reduce the overhead when
837 # only compiling.
838 if not shared.SKIP_SUBPROCS:
839 shared.check_llvm_version()
840
841 autoconf = os.environ.get('EMMAKEN_JUST_CONFIGURE') or 'conftest.c' in options.input_files or 'conftest.cpp' in options.input_files
842 if autoconf:
843 # configure tests want a more shell-like style, where we emit return codes on exit()
844 settings.EXIT_RUNTIME = 1
845 # use node.js raw filesystem access, to behave just like a native executable
846 settings.NODERAWFS = 1
847 # Add `#!` line to output JS and make it executable.
848 settings.EXECUTABLE = config.NODE_JS[0]
849 # autoconf declares functions without their proper signatures, and STRICT causes that to trip up by passing --fatal-warnings to the linker.
850 if settings.STRICT:
851 exit_with_error('autoconfiguring is not compatible with STRICT')
852
853 if settings.OPT_LEVEL >= 1:
854 default_setting('ASSERTIONS', 0)
855
856 if options.emrun:
857 options.pre_js.append(utils.path_from_root('src/emrun_prejs.js'))
858 options.post_js.append(utils.path_from_root('src/emrun_postjs.js'))
859 if settings.MINIMAL_RUNTIME:
860 exit_with_error('--emrun is not compatible with MINIMAL_RUNTIME')
861 # emrun mode waits on program exit
862 if user_settings.get('EXIT_RUNTIME') == '0':
863 exit_with_error('--emrun is not compatible with EXIT_RUNTIME=0')
864 settings.EXIT_RUNTIME = 1
865 # emrun_postjs.js needs this library function.
866 settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$addOnExit']
867

Callers 2

run_post_linkFunction · 0.85
runFunction · 0.85

Calls 15

apply_library_settingsFunction · 0.85
default_settingFunction · 0.85
get_dylibsFunction · 0.85
calc_extra_ldflagsFunction · 0.85
exit_with_errorFunction · 0.85
get_file_suffixFunction · 0.85
in_tempFunction · 0.85
get_secondary_targetFunction · 0.85

Tested by

no test coverage detected