From 1f18b1911b28347157e9250deb5e223a3de3d032 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 12 Jun 2023 12:23:56 -0700 Subject: [PATCH] Add a PackageArgs class in preparation for REPO.bazel - Created a PackageArgs class that stores the values passed to the attrs of the `package()` function, so that they can be applied to a package builder in one go - These attr values used to be applied as soon as each attr is processed (i.e. evaluated). We can't do that anymore for repo(), since at the time of REPO.bazel evaluation, the package hasn't started being built yet. - Instead of storing the individual fields, Package now just holds on to a PackageArgs object. - In a follow-up CL, we store all the repo() values in a PackageArgs class, and apply those before the package() ones. - Also removed `Package#isDefaultVisibilitySet` as nobody calls it anymore. Work towards https://github.com/bazelbuild/bazel/issues/18077 PiperOrigin-RevId: 539728608 Change-Id: Ie4a081fa0e52e833ac2a6be50033f95728da3a9b --- .../build/lib/packages/BuildGlobals.java | 4 +- .../devtools/build/lib/packages/Package.java | 214 ++--------------- .../build/lib/packages/PackageArgs.java | 226 ++++++++++++++++++ .../build/lib/packages/PackageCallable.java | 82 +------ .../build/lib/packages/RuleClass.java | 9 +- .../build/lib/pkgcache/PackageOptions.java | 15 +- .../build/lib/skyframe/PackageFunction.java | 9 +- .../lib/packages/PackageFactoryTest.java | 4 +- 8 files changed, 277 insertions(+), 286 deletions(-) create mode 100644 src/main/java/com/google/devtools/build/lib/packages/PackageArgs.java diff --git a/src/main/java/com/google/devtools/build/lib/packages/BuildGlobals.java b/src/main/java/com/google/devtools/build/lib/packages/BuildGlobals.java index 72097be48f9846..03c87efcd1ca1c 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/BuildGlobals.java +++ b/src/main/java/com/google/devtools/build/lib/packages/BuildGlobals.java @@ -121,7 +121,7 @@ public NoneType licenses( PackageContext context = PackageFactory.getContext(thread); try { License license = BuildType.LICENSE.convert(licensesList, "'licenses' operand"); - context.pkgBuilder.setDefaultLicense(license); + context.pkgBuilder.mergePackageArgsFrom(PackageArgs.builder().setLicense(license)); } catch (ConversionException e) { context.eventHandler.handle( Package.error(thread.getCallerLocation(), e.getMessage(), Code.LICENSE_PARSE_FAILURE)); @@ -144,7 +144,7 @@ public NoneType distribs(Object object, StarlarkThread thread) throws EvalExcept try { Set distribs = BuildType.DISTRIBUTIONS.convert(object, "'distribs' operand"); - context.pkgBuilder.setDefaultDistribs(distribs); + context.pkgBuilder.mergePackageArgsFrom(PackageArgs.builder().setDistribs(distribs)); } catch (ConversionException e) { context.eventHandler.handle( Package.error( diff --git a/src/main/java/com/google/devtools/build/lib/packages/Package.java b/src/main/java/com/google/devtools/build/lib/packages/Package.java index da4a12308ab4ab..a46dafde605ae6 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/Package.java +++ b/src/main/java/com/google/devtools/build/lib/packages/Package.java @@ -44,7 +44,6 @@ import com.google.devtools.build.lib.events.EventHandler; import com.google.devtools.build.lib.events.EventKind; import com.google.devtools.build.lib.events.ExtendedEventHandler.Postable; -import com.google.devtools.build.lib.packages.License.DistributionType; import com.google.devtools.build.lib.packages.Package.Builder.PackageSettings; import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions; import com.google.devtools.build.lib.server.FailureDetails.FailureDetail; @@ -66,7 +65,6 @@ import java.io.PrintStream; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; @@ -171,11 +169,7 @@ private NameConflictException(String message) { /** The collection of all targets defined in this package, indexed by name. */ private ImmutableSortedMap targets; - /** - * Default visibility for rules that do not specify it. - */ - private RuleVisibility defaultVisibility; - private boolean defaultVisibilitySet; + private PackageArgs packageArgs = PackageArgs.DEFAULT; /** * How to enforce config_setting visibility settings. @@ -195,16 +189,6 @@ public enum ConfigSettingVisibilityPolicy { private ConfigSettingVisibilityPolicy configSettingVisibilityPolicy; - /** - * Default package-level 'testonly' value for rules that do not specify it. - */ - private boolean defaultTestOnly = false; - - /** - * Default package-level 'deprecation' value for rules that do not specify it. - */ - private String defaultDeprecation; - /** * Default header strictness checking for rules that do not specify it. */ @@ -232,18 +216,6 @@ public enum ConfigSettingVisibilityPolicy { */ @Nullable private FailureDetail failureDetail; - /** The package's default "package_metadata" attribute. */ - private ImmutableList