From 09f1e89b4b32e3d34c5abd18577c0f3be22c0287 Mon Sep 17 00:00:00 2001 From: Dave Roth Date: Fri, 10 Jan 2025 10:57:21 -0800 Subject: [PATCH] Remove BUILD.bazel before symlinking when creating new_local_repository Fixes #24770 Closes #24887. PiperOrigin-RevId: 714107497 Change-Id: Ib914aa54b2afa2a90fcce2f2263b9c1b2d2c193c --- tools/build_defs/repo/local.bzl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/build_defs/repo/local.bzl b/tools/build_defs/repo/local.bzl index 69e0c1ae0b98a5..67da117c421c05 100644 --- a/tools/build_defs/repo/local.bzl +++ b/tools/build_defs/repo/local.bzl @@ -94,6 +94,9 @@ def _new_local_repository_impl(rctx): rctx.watch(child) if rctx.attr.build_file != None: + # Remove any existing BUILD.bazel in the repository to ensure + # the symlink to the defined build_file doesn't fail. + rctx.delete("BUILD.bazel") rctx.symlink(rctx.attr.build_file, "BUILD.bazel") if rctx.os.name.startswith("windows"): rctx.watch(rctx.attr.build_file) # same reason as above