Skip to content

Commit 783fdc8

Browse files
committed
update how subprocess command are constructed
1 parent b9a3140 commit 783fdc8

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

build/build.py

100755100644
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ def add_artifact_subcommand_global_arguments(parser: argparse.ArgumentParser):
300300
action="store_true",
301301
help="""
302302
If true, writes the Bazel options to the .jax_configure.bazelrc file but
303-
does not build the artifacts. Ignored if --use_ci_bazelrc_flags is set.
303+
does not build the artifacts.
304304
""",
305305
)
306306

@@ -444,7 +444,7 @@ async def main():
444444
else:
445445
bazel_command.append("//build:requirements.update")
446446

447-
await executor.run(bazel_command.command, args.dry_run)
447+
await executor.run(bazel_command.get_command_as_string(), args.dry_run)
448448
sys.exit(0)
449449

450450
wheel_cpus = {
@@ -473,9 +473,9 @@ async def main():
473473
clang_path = args.clang_path or utils.get_clang_path_or_exit()
474474
logging.debug("Using Clang as the compiler, clang path: %s", clang_path)
475475
# Use double quotes around clang path to avoid path issues on Windows.
476-
bazel_command.append(f'--action_env=CLANG_COMPILER_PATH="{clang_path}"')
477-
bazel_command.append(f'--repo_env=CC="{clang_path}"')
478-
bazel_command.append(f'--repo_env=BAZEL_COMPILER="{clang_path}"')
476+
bazel_command.append(f"--action_env=CLANG_COMPILER_PATH=\"{clang_path}\"")
477+
bazel_command.append(f"--repo_env=CC=\"{clang_path}\"")
478+
bazel_command.append(f"--repo_env=BAZEL_COMPILER=\"{clang_path}\"")
479479
bazel_command.append("--config=clang")
480480

481481
if not args.disable_mkl_dnn:
@@ -485,7 +485,7 @@ async def main():
485485
if "cuda" in args.command:
486486
bazel_command.append("--config=cuda")
487487
bazel_command.append(
488-
f'--action_env=CLANG_CUDA_COMPILER_PATH="{clang_path}"'
488+
f"--action_env=CLANG_CUDA_COMPILER_PATH=\"{clang_path}\""
489489
)
490490
if args.build_cuda_with_clang:
491491
logging.debug("Building CUDA with Clang")
@@ -550,7 +550,7 @@ async def main():
550550

551551
if args.rocm_path:
552552
logging.debug("ROCm tookit path: %s", args.rocm_path)
553-
bazel_command.append(f'--action_env=ROCM_PATH="{args.rocm_path}"')
553+
bazel_command.append(f"--action_env=ROCM_PATH=\"{args.rocm_path}\"")
554554
if args.rocm_amdgpu_targets:
555555
logging.debug("ROCm AMD GPU targets: %s", args.rocm_amdgpu_targets)
556556
bazel_command.append(
@@ -559,7 +559,7 @@ async def main():
559559

560560
if args.local_xla_path:
561561
logging.debug("Local XLA path: %s", args.local_xla_path)
562-
bazel_command.append(f'--override_repository=xla="{args.local_xla_path}"')
562+
bazel_command.append(f"--override_repository=xla=\"{args.local_xla_path}\"")
563563

564564
if args.bazel_build_options:
565565
logging.debug(
@@ -568,15 +568,14 @@ async def main():
568568
for option in args.bazel_build_options:
569569
bazel_command.append(option)
570570

571-
if not args.use_ci_bazelrc_flags:
571+
if args.configure_only:
572572
with open(".jax_configure.bazelrc", "w") as f:
573-
jax_configure_options = utils.get_jax_configure_bazel_options(bazel_command.parameters)
573+
jax_configure_options = utils.get_jax_configure_bazel_options(bazel_command.get_command_as_list())
574574
if not jax_configure_options:
575575
logging.error("Error retrieving the Bazel options to be written to .jax_configure.bazelrc, exiting.")
576576
sys.exit(1)
577577
f.write(jax_configure_options)
578578
logging.debug("Bazel options written to .jax_configure.bazelrc")
579-
if args.configure_only:
580579
logging.debug("--configure_only is set, exiting without running any Bazel commands.")
581580
sys.exit(0)
582581

@@ -612,8 +611,9 @@ async def main():
612611
git_hash = utils.get_githash()
613612
bazel_command.append(f"--jaxlib_git_hash={git_hash}")
614613

615-
await executor.run(bazel_command.command, args.dry_run)
614+
await executor.run(bazel_command.get_command_as_string(), args.dry_run)
616615

617616

618617
if __name__ == "__main__":
619618
asyncio.run(main())
619+

build/tools/command.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,18 @@
2424

2525
class CommandBuilder:
2626
def __init__(self, base_command: str):
27-
self.command = base_command
28-
self.parameters = [base_command]
27+
self.command = [base_command]
2928

3029
def append(self, parameter: str):
31-
self.command += " {}".format(parameter)
32-
self.parameters.append(parameter)
30+
self.command.append(parameter)
3331
return self
3432

33+
def get_command_as_string(self) -> str:
34+
return " ".join(self.command)
35+
36+
def get_command_as_list(self) -> list[str]:
37+
return self.command
38+
3539
@dataclasses.dataclass
3640
class CommandResult:
3741
"""
@@ -101,4 +105,4 @@ async def log_stream(stream, result: CommandResult):
101105
result.return_code = await process.wait()
102106
result.end_time = datetime.datetime.now()
103107
logger.debug("Command finished with return code %s", result.return_code)
104-
return result
108+
return result

build/tools/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,4 @@ def get_githash():
256256
).stdout.strip()
257257
except OSError:
258258
return ""
259+

0 commit comments

Comments
 (0)