Skip to content

Commit cf6313d

Browse files
committed
chore: better build data error handling
1 parent 2c539bb commit cf6313d

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

python/private/stage2_bootstrap_template.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
COVERAGE_INSTRUMENTED = "%coverage_instrumented%" == "1"
4949

5050
# runfiles-root-relative path to a file with binary-specific build information
51+
# It uses forward slashes, so must be converted for proper usage on Windows.
5152
BUILD_DATA_FILE = "%build_data_file%"
5253

5354
# ===== Template substitutions end =====
@@ -64,9 +65,23 @@ def get_build_data(self):
6465
import runfiles
6566
except ImportError:
6667
from python.runfiles import runfiles
67-
path = runfiles.Create().Rlocation(self.BUILD_DATA_FILE)
68-
with open(path) as fp:
69-
return fp.read()
68+
rlocation_path = self.BUILD_DATA_FILE
69+
if is_windows():
70+
rlocation_path = rlocation_path.replace("/", "")
71+
path = runfiles.Create().Rlocation(rlocation_path)
72+
if is_windows():
73+
path = os.path.normpath(path)
74+
try:
75+
# Use utf-8-sig to handle Windows BOM
76+
with open(path, encoding='utf-8-sig') as fp:
77+
return fp.read()
78+
except Exception as exc:
79+
if hasattr(exc, "add_note"):
80+
exc.add_note(f"runfiles lookup path: {rlocation_path}")
81+
exc.add_note(f"exists: {os.path.exists(path)}")
82+
can_read = os.access(path, os.R_OK)
83+
exc.add_note(f"readable: {can_read}")
84+
raise
7085

7186

7287
sys.modules["bazel_binary_info"] = BazelBinaryInfoModule("bazel_binary_info")

0 commit comments

Comments
 (0)