Skip to content

Commit 5bcb0bd

Browse files
committed
Emscripten: More tightly scope fetching of sysroot
Prompted by #174
1 parent 204aa59 commit 5bcb0bd

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

refresh.template.py

+14-15
Original file line numberDiff line numberDiff line change
@@ -782,19 +782,6 @@ def _apple_platform_patch(compile_args: typing.List[str]):
782782
return compile_args
783783

784784

785-
def _get_sysroot(args: typing.List[str]):
786-
"""Get path to sysroot from command line arguments."""
787-
for idx, arg in enumerate(args):
788-
if arg == '--sysroot' or arg == '-isysroot':
789-
if idx + 1 < len(args):
790-
return pathlib.PurePath(args[idx + 1])
791-
elif arg.startswith('--sysroot='):
792-
return pathlib.PurePath(arg[len('--sysroot='):])
793-
elif arg.startswith('-isysroot'):
794-
return pathlib.PurePath(arg[len('-isysroot'):])
795-
return None
796-
797-
798785
def _emscripten_platform_patch(compile_action):
799786
"""De-Bazel the command into something clangd can parse.
800787
@@ -805,8 +792,18 @@ def _emscripten_platform_patch(compile_action):
805792
return compile_action.arguments
806793

807794
workspace_absolute = pathlib.PurePath(os.environ["BUILD_WORKSPACE_DIRECTORY"])
808-
sysroot = _get_sysroot(compile_action.arguments)
809-
assert sysroot, f'Emscripten sysroot not detected in CMD: {compile_action.arguments}'
795+
796+
def _get_sysroot(args: typing.List[str]):
797+
"""Get path to sysroot from command line arguments."""
798+
for idx, arg in enumerate(args):
799+
if arg == '--sysroot' or arg == '-isysroot':
800+
if idx + 1 < len(args):
801+
return pathlib.PurePath(args[idx + 1])
802+
elif arg.startswith('--sysroot='):
803+
return pathlib.PurePath(arg[len('--sysroot='):])
804+
elif arg.startswith('-isysroot'):
805+
return pathlib.PurePath(arg[len('-isysroot'):])
806+
return None
810807

811808
def get_workspace_root(path_from_execroot: pathlib.PurePath):
812809
if path_from_execroot.parts[0] != 'external':
@@ -818,6 +815,8 @@ def get_workspace_root(path_from_execroot: pathlib.PurePath):
818815
environment['EMCC_SKIP_SANITY_CHECK'] = '1'
819816
environment['EM_COMPILER_WRAPPER'] = str(pathlib.PurePath({print_args_executable}))
820817
if 'EM_BIN_PATH' not in environment:
818+
sysroot = _get_sysroot(compile_action.arguments)
819+
assert sysroot, f'Emscripten sysroot not detected in CMD: {compile_action.arguments}'
821820
environment['EM_BIN_PATH'] = str(get_workspace_root(sysroot))
822821
if 'EM_CONFIG_PATH' not in environment:
823822
environment['EM_CONFIG_PATH'] = str(get_workspace_root(emcc_driver) / 'emscripten_toolchain' / 'emscripten_config')

0 commit comments

Comments
 (0)