Skip to content

Commit 87d0cf6

Browse files
committed
Emscripten: Minor twiddles
Mostly adding environment dict to the compile_action for easy reuse in the future
1 parent 927fbd1 commit 87d0cf6

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

refresh.template.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -745,18 +745,18 @@ def _apple_platform_patch(compile_args: typing.List[str]):
745745
return compile_args
746746

747747

748-
def _emscripten_platform_patch(compile_args: typing.List[str], action_env: typing.Dict[str, str]):
748+
def _emscripten_platform_patch(compile_action):
749749
"""De-Bazel the command into something clangd can parse.
750750
751751
This function has fixes specific to Emscripten platforms, but you should call it on all platforms. It'll determine whether the fixes should be applied or not
752752
"""
753-
emcc_driver = pathlib.Path(compile_args[0])
753+
emcc_driver = pathlib.Path(compile_action.arguments[0])
754754
if not emcc_driver.name.startswith('emcc'):
755-
return compile_args
755+
return compile_action.arguments
756756

757757
workspace_absolute = pathlib.PurePath(os.environ["BUILD_WORKSPACE_DIRECTORY"])
758758

759-
environment = dict(action_env)
759+
environment = compile_action.environmentVariables.copy()
760760
environment['EXT_BUILD_ROOT'] = str(workspace_absolute)
761761
environment['EMCC_SKIP_SANITY_CHECK'] = '1'
762762
environment['EM_COMPILER_WRAPPER'] = str(pathlib.PurePath({print_args_executable}))
@@ -765,9 +765,9 @@ def _emscripten_platform_patch(compile_args: typing.List[str], action_env: typin
765765

766766
# We run the emcc process with the environment variable EM_COMPILER_WRAPPER to intercept the command line arguments passed to `clang`.
767767
emcc_process = subprocess.run(
768-
# On windows, it fails to spawn the subprocess when the path uses forward slashes as a separator.
768+
# On Windows, it fails to spawn the subprocess when the path uses forward slashes as a separator.
769769
# Here, we convert emcc driver path to use the native path separator.
770-
[str(emcc_driver)] + compile_args[1:],
770+
[str(emcc_driver)] + compile_action.arguments[1:],
771771
# MIN_PY=3.7: Replace PIPEs with capture_output.
772772
stdout=subprocess.PIPE,
773773
stderr=subprocess.PIPE,
@@ -1043,14 +1043,12 @@ def _get_cpp_command_for_files(compile_action):
10431043
10441044
Undo Bazel-isms and figures out which files clangd should apply the command to.
10451045
"""
1046-
env_pairs = getattr(compile_action, 'environmentVariables', [])
1047-
env = {}
1048-
for pair in env_pairs:
1049-
env[pair.key] = pair.value
1046+
# Condense aquery's environment variables into a dictionary, the format you might expect.
1047+
compile_action.environmentVariables = {pair.key: pair.value for pair in getattr(compile_action, 'environmentVariables', [])}
10501048

10511049
# Patch command by platform, revealing any hidden arguments.
10521050
compile_action.arguments = _apple_platform_patch(compile_action.arguments)
1053-
compile_action.arguments = _emscripten_platform_patch(compile_action.arguments, action_env=env)
1051+
compile_action.arguments = _emscripten_platform_patch(compile_action)
10541052
# Android and Linux and grailbio LLVM toolchains: Fine as is; no special patching needed.
10551053
compile_action.arguments = _all_platform_patch(compile_action.arguments)
10561054

0 commit comments

Comments
 (0)