Skip to content

Commit 060136d

Browse files
committed
enable windows symlinks, cleanup error handling
1 parent d270b8b commit 060136d

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

.bazelrc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,14 @@ common --incompatible_disallow_struct_provider_syntax
2121
# Makes Bazel 7 act more like Bazel 8
2222
common --incompatible_use_plus_in_repo_names
2323

24-
# Windows makes use of runfiles for some rules
24+
# Windows has enable_runfiles disabled by default, so explicitly enable it.
25+
# We're heavily reliant on runfile trees.
2526
build --enable_runfiles
27+
# Have Windows create symlinks instead of junctions. This requires permissions
28+
# to create symlinks (Developer mode, Administrator, or certain registry keys).
29+
# This is required because runfiles create file->file entries, but junctions
30+
# only work for directory->directory entries.
31+
startup --windows_enable_symlinks
2632

2733
# Make Bazel 7 use bzlmod by default
2834
common --enable_bzlmod
@@ -45,4 +51,3 @@ build --lockfile_mode=update
4551
# See issue 3567. Disable implicit python zip creation.
4652
common --build_python_zip=false
4753
common --@rules_python//python/config_settings:build_python_zip=false
48-
startup --windows_enable_symlinks

python/private/stage2_bootstrap_template.py

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,39 +70,29 @@ def get_build_data(self):
7070
if is_windows():
7171
path = os.path.normpath(path)
7272
try:
73-
path = os.path.dirname(__file__)
74-
path = os.path.join(path, "print_build_data.build_data.txt")
75-
# Use utf-8-sig to handle Windows BOM
7673
with open(path, 'rb') as fp:
7774
data = fp.read()
75+
# Use utf-8-sig to handle Windows BOM, just in case; it's easy
76+
# for it to sneak in on Windows.
7877
return data.decode('utf-8-sig')
7978
except Exception as exc:
8079
if hasattr(exc, "add_note"):
81-
exc.add_note(f"version: {sys.version}")
82-
exc.add_note(f"path: {path}")
80+
exc.add_note(f"python version: {sys.version}")
81+
exc.add_note(f"attempted path: {path}")
8382
exc.add_note(f"runfiles lookup path: {rlocation_path}")
8483
exc.add_note(f"exists: {os.path.exists(path)}")
8584
exc.add_note(f"lexists: {os.path.lexists(path)}")
8685
exc.add_note(f"islink: {os.path.islink(path)}")
8786
exc.add_note(f"isfile: {os.path.isfile(path)}")
8887
if hasattr(os.path, "isjunction"):
89-
exc.add_note(f"isjunction: {os.path.isjunction(path)}")
88+
is_junction = os.path.isjunction(path)
89+
else:
90+
import stat
91+
st = os.lstat(path)
92+
is_junction = bool(st.st_reparse_tag == stat.IO_REPARSE_TAG_MOUNT_POINT)
93+
exc.add_note(f"isjunction: {is_junction}")
9094
can_read = os.access(path, os.R_OK)
9195
exc.add_note(f"readable: {can_read}")
92-
try:
93-
exc.add_note(f"stat: {os.stat(path)}")
94-
except Exception as e:
95-
exc.add_note(f"stat error: {e}")
96-
try:
97-
exc.add_note(f"lstat: {os.lstat(path)}")
98-
except Exception as e:
99-
exc.add_note(f"lstat error: {e}")
100-
try:
101-
import subprocess
102-
out = subprocess.check_output(f'dir "{os.path.dirname(path)}"', shell=True)
103-
exc.add_note(f"dir: {out.decode('utf-8', 'replace')}")
104-
except Exception as e:
105-
exc.add_note(f"dir error: {e}")
10696
raise
10797

10898

0 commit comments

Comments
 (0)