Skip to content

Commit c8e4fa5

Browse files
committed
fix: convert relative symlinks in test_module_repo to absolute
Although relative links are valid in Windows, it seems that they fail under some circumstances. For example, see bazelbuild/bazel-central-registry#5205
1 parent 337638d commit c8e4fa5

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

buildkite/bazel-central-registry/bcr_presubmit.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import json
2525
import os
2626
import pathlib
27+
import platform
2728
import re
2829
import sys
2930
import subprocess
@@ -240,6 +241,22 @@ def unpack_archive(archive_file, output_dir):
240241
else:
241242
shutil.unpack_archive(archive_file, output_dir)
242243

244+
if platform.system() != "Windows":
245+
return
246+
247+
# Windows has issues with relative symlinks (see
248+
# https://github.com/bazelbuild/bazel-central-registry/pull/5205) so let's
249+
# make all of the symlinks in the unpacked archive absolute
250+
for root, dirs, files in os.walk(output_dir):
251+
for name in files + dirs:
252+
path = pathlib.Path(root) / name
253+
if path.is_symlink():
254+
target = path.readlink()
255+
if not target.is_absolute():
256+
absolute_target = (path.parent / target).resolve()
257+
path.unlink()
258+
path.symlink_to(absolute_target)
259+
243260
def prepare_test_module_repo(module_name, module_version, overwrite_bazel_version=None, root=None, suppress_log=False):
244261
"""Prepare the test module repo and the presubmit yml file it should use"""
245262
suppress_log or bazelci.print_collapsed_group(":information_source: Prepare test module repo")

0 commit comments

Comments
 (0)