From 56f54daf9ff3b1177eee31e342e8d6b959d5ac34 Mon Sep 17 00:00:00 2001 From: aiuto Date: Fri, 4 Nov 2022 11:24:04 -0400 Subject: [PATCH] Rollup of SBOM correctness fixes (#16655) * Rename default_applicable_licenses to default_package_metadata. Leave default_applicable_licenses as an alias. Don't allow both to be set. Step 1 of https://docs.google.com/document/d/1uyJjkKbE8kV8EinakaR9q-Un25zCukhoH_dRBkWHSKQ/edit# PiperOrigin-RevId: 485705150 Change-Id: I5e0012e37e5bca55ed43f83dd9f26a26f78b543d * Improve the check for being a package metadata rule This allows the refactoring which will happen after default_applicable_licenses is renamed to default_package_metadata. The current behavior is intended to prevent `applicable_licenses` from being set on a `license` rule. The required behavior is that we don't set `applicable_licenses` on any of the metadata rules. Future changes might have to take into account the ability to set the license for a tool rule within `rules_package`. For background, see https://docs.google.com/document/d/1uyJjkKbE8kV8EinakaR9q-Un25zCukhoH_dRBkWHSKQ/edit#heading=h.izpa22p82m6c Closes #16596. PiperOrigin-RevId: 485457037 Change-Id: Ifb105f646ae0c291a6841b3ddb84ed536e9d71e3 * Make constraint_setting / constraint_value non_configurable. The concept of allowing what is fundamentally a constant to vary by target we are building for is too much to reason about, let along get the code correct. PiperOrigin-RevId: 483748098 Change-Id: I966b7d21ad8d38de9867c870a0669e2123063809 --- .../lib/analysis/LicensesProviderImpl.java | 2 +- .../lib/packages/DefaultPackageArguments.java | 63 ++++++++++++++----- .../devtools/build/lib/packages/Package.java | 22 +++---- .../devtools/build/lib/packages/Rule.java | 2 +- .../build/lib/packages/RuleClass.java | 59 +++++++++-------- .../rules/platform/ConstraintSettingRule.java | 4 +- .../rules/platform/ConstraintValueRule.java | 3 +- 7 files changed, 99 insertions(+), 56 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/analysis/LicensesProviderImpl.java b/src/main/java/com/google/devtools/build/lib/analysis/LicensesProviderImpl.java index 98d087632ebe48..6e00fc278606c7 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/LicensesProviderImpl.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/LicensesProviderImpl.java @@ -68,7 +68,7 @@ public static LicensesProvider of(RuleContext ruleContext) { ListMultimap configuredMap = ruleContext.getConfiguredTargetMap(); - if (rule.getRuleClassObject().isBazelLicense()) { + if (rule.getRuleClassObject().isPackageMetadataRule()) { // Don't crawl a new-style license, it's effectively a leaf. // The representation of the new-style rule is unfortunately hardcoded here, // but this is code in the old-style licensing path that will ultimately be removed. diff --git a/src/main/java/com/google/devtools/build/lib/packages/DefaultPackageArguments.java b/src/main/java/com/google/devtools/build/lib/packages/DefaultPackageArguments.java index ae89e98788d517..a32f000ce70f26 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/DefaultPackageArguments.java +++ b/src/main/java/com/google/devtools/build/lib/packages/DefaultPackageArguments.java @@ -17,6 +17,7 @@ import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.packages.License.DistributionType; +import com.google.devtools.build.lib.server.FailureDetails.PackageLoading.Code; import java.util.List; import java.util.Set; import net.starlark.java.eval.EvalException; @@ -30,15 +31,16 @@ private DefaultPackageArguments() {} /** Returns the default set of {@link PackageArgument}s. */ static ImmutableList> get() { return ImmutableList.of( - new DefaultDeprecation(), - new DefaultDistribs(), - new DefaultApplicableLicenses(), - new DefaultLicenses(), - new DefaultTestOnly(), - new DefaultVisibility(), - new Features(), - new DefaultCompatibleWith(), - new DefaultRestrictedTo()); + new DefaultDeprecation(), + new DefaultDistribs(), + new DefaultApplicableLicenses(), + new DefaultPackageMetadata(), + new DefaultLicenses(), + new DefaultTestOnly(), + new DefaultVisibility(), + new Features(), + new DefaultCompatibleWith(), + new DefaultRestrictedTo()); } private static class DefaultVisibility extends PackageArgument> { @@ -95,17 +97,48 @@ protected void process(Package.Builder pkgBuilder, Location location, * specified. */ private static class DefaultApplicableLicenses extends PackageArgument> { - private static final String DEFAULT_APPLICABLE_LICENSES_ATTRIBUTE = - "default_applicable_licenses"; - private DefaultApplicableLicenses() { - super(DEFAULT_APPLICABLE_LICENSES_ATTRIBUTE, BuildType.LABEL_LIST); + super("default_applicable_licenses", BuildType.LABEL_LIST); + } + + @Override + protected void process(Package.Builder pkgBuilder, Location location, List