From 6f705ce66fb8a37324542be4eebacd0a0f511e12 Mon Sep 17 00:00:00 2001 From: Googler Date: Sat, 28 Sep 2024 07:08:18 -0700 Subject: [PATCH] RuleVisibility concatenation doesn't add redundant items This is useful if you have several nested symbolic macros, since it avoids generating a long visibility value like `["//A:__pkg__", "//A:__pkg__", ..., "//A:__pkg__"]` when each macro's body is defined in the same package `A`. Also clarify the purpose of the label accessors on `RuleVisibility` and flip their declaration order. Work toward #19922. PiperOrigin-RevId: 679962558 Change-Id: Iebb55d0256d72d7bc0a8b575446dea83c9bbf632 --- .../build/lib/packages/RuleVisibility.java | 52 ++++++++++-------- .../lib/packages/PackageFactoryTest.java | 7 +-- .../lib/packages/RuleVisibilityTest.java | 54 +++++++++---------- 3 files changed, 61 insertions(+), 52 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/packages/RuleVisibility.java b/src/main/java/com/google/devtools/build/lib/packages/RuleVisibility.java index 3b93a041560b38..1fb555c1e5e657 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/RuleVisibility.java +++ b/src/main/java/com/google/devtools/build/lib/packages/RuleVisibility.java @@ -34,20 +34,20 @@ public interface RuleVisibility { /** - * Returns the list of labels that need to be loaded so that the visibility decision can be made - * during analysis time. E.g. for package group visibility, this is the list of package groups - * referenced. Does not include labels that have special meanings in the visibility declaration, - * e.g. "//visibility:*" or "//*:__pkg__". + * Returns the list of all labels comprising this visibility. + * + *

This includes labels that are not loadable, such as //visibility:public and //foo:__pkg__. */ - List

I.e., this returns the labels of the top-level {@code package_group}s that must be loaded in + * order to determine the complete set of packages represented by this visibility. (Additional + * {@code package_group}s may need to be loaded due to their {@code includes} attribute.) */ - List

If {@code element} is already present in {@code visibility}, the result is just {@code + * visibility}. + * * @throws EvalException if there's a problem parsing {@code element} into a visibility */ static RuleVisibility concatWithElement(RuleVisibility visibility, Label element) @@ -175,10 +178,15 @@ static RuleVisibility concatWithElement(RuleVisibility visibility, Label element // Public is idempotent. return RuleVisibility.PUBLIC; } else { - ImmutableList.Builder