Skip to content

Commit 8aed677

Browse files
PiotrKorkuspawelrutkaq
authored andcommitted
handle bazel sandbox in saving output
1 parent 1abbc3c commit 8aed677

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

scripts/tooling/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ bazel run //scripts/tooling -- misc --help
1313
## Creating HTML report
1414

1515
```bash
16-
bazel run //scripts/tooling -- misc html_report --output /home/pawel/score/repos/reference_integration/report.html
16+
bazel run //scripts/tooling -- misc html_report
1717
```
1818

1919
## Running tests

scripts/tooling/cli/main.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
import argparse
2+
import os
23
import sys
34
from pathlib import Path
45

56

7+
def _resolve_path_from_bazel(path: Path) -> Path:
8+
"""Resolve path relative to user's working directory when running via bazel run.
9+
10+
Bazel sets BUILD_WORKING_DIRECTORY to the directory where bazel was invoked.
11+
"""
12+
if not path.is_absolute():
13+
# When running via 'bazel run', resolve relative paths against the user's cwd
14+
build_working_dir = os.environ.get("BUILD_WORKING_DIRECTORY")
15+
if build_working_dir:
16+
return (Path(build_working_dir) / path).resolve()
17+
return path.resolve()
18+
19+
620
def _find_repo_root() -> Path:
721
"""Walk up from this file to find the repo root (contains known_good.json)."""
822
candidate = Path(__file__).resolve()
@@ -23,8 +37,7 @@ def _cmd_html_report(args: argparse.Namespace) -> int:
2337
print(f"error: {exc}", file=sys.stderr)
2438
return 1
2539

26-
output = Path(args.output) if args.output else Path("report.html")
27-
output = output.resolve()
40+
output = _resolve_path_from_bazel(Path(args.output))
2841
write_report(known_good, output)
2942
print(f"Report written to {output}")
3043
return 0

0 commit comments

Comments
 (0)