Skip to content

Commit

Permalink
Emscripten: More tightly scope fetching of sysroot
Browse files Browse the repository at this point in the history
Prompted by #174
  • Loading branch information
cpsauer committed Mar 15, 2024
1 parent 204aa59 commit 5bcb0bd
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions refresh.template.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,19 +782,6 @@ def _apple_platform_patch(compile_args: typing.List[str]):
return compile_args


def _get_sysroot(args: typing.List[str]):
"""Get path to sysroot from command line arguments."""
for idx, arg in enumerate(args):
if arg == '--sysroot' or arg == '-isysroot':
if idx + 1 < len(args):
return pathlib.PurePath(args[idx + 1])
elif arg.startswith('--sysroot='):
return pathlib.PurePath(arg[len('--sysroot='):])
elif arg.startswith('-isysroot'):
return pathlib.PurePath(arg[len('-isysroot'):])
return None


def _emscripten_platform_patch(compile_action):
"""De-Bazel the command into something clangd can parse.
Expand All @@ -805,8 +792,18 @@ def _emscripten_platform_patch(compile_action):
return compile_action.arguments

workspace_absolute = pathlib.PurePath(os.environ["BUILD_WORKSPACE_DIRECTORY"])
sysroot = _get_sysroot(compile_action.arguments)
assert sysroot, f'Emscripten sysroot not detected in CMD: {compile_action.arguments}'

def _get_sysroot(args: typing.List[str]):
"""Get path to sysroot from command line arguments."""
for idx, arg in enumerate(args):
if arg == '--sysroot' or arg == '-isysroot':
if idx + 1 < len(args):
return pathlib.PurePath(args[idx + 1])
elif arg.startswith('--sysroot='):
return pathlib.PurePath(arg[len('--sysroot='):])
elif arg.startswith('-isysroot'):
return pathlib.PurePath(arg[len('-isysroot'):])
return None

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

0 comments on commit 5bcb0bd

Please sign in to comment.