From 809ec30eef8ad968dd3836dabc49a82156d038b5 Mon Sep 17 00:00:00 2001 From: Christian Sigg Date: Sat, 19 Sep 2026 11:21:04 -0700 Subject: [PATCH] Watch the patch files listed in a quilt series before downloading the archive. Registering the dependency lazily, i.e. when ctx.patch() is called, makes Bazel restart the repository rule and download and extract the archive a second time. PiperOrigin-RevId: 984474711 --- third_party/xla/third_party/quilt_repo.bzl | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/third_party/xla/third_party/quilt_repo.bzl b/third_party/xla/third_party/quilt_repo.bzl index 6d5d4273e7453c..bd0445a676d57a 100644 --- a/third_party/xla/third_party/quilt_repo.bzl +++ b/third_party/xla/third_party/quilt_repo.bzl @@ -36,12 +36,22 @@ def read_patch_series(ctx, series_spec): fail("Patch series file does not exist: %s" % series_label) for line in ctx.read(series_file).splitlines(): line = line.strip() - if line and not line.startswith("#"): - patch_path = series_file.dirname - for part in line.split("/"): - if part and part != ".": - patch_path = patch_path.get_child(part) - patches.append(patch_path) + if not line or line.startswith("#"): + continue + patch_path = series_file.dirname + for part in line.split("/"): + if part and part != ".": + patch_path = patch_path.get_child(part) + + # `dirname` and `get_child` are pure path arithmetic and do not + # register a dependency, so watch each patch explicitly. Otherwise + # the implicit watch inside `ctx.patch` is the first access to the + # file and forces a Skyframe restart after the archive has already + # been downloaded and extracted. + ctx.watch(patch_path) + if not patch_path.exists: + fail("Patch file listed in %s does not exist: %s" % (series_label, patch_path)) + patches.append(patch_path) return patches def _get_link_dict(ctx, link_files, build_file):