Skip to content

Commit ace99b5

Browse files
aiutocopybara-github
authored andcommitted
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
1 parent 9b420b5 commit ace99b5

File tree

3 files changed

+60
-28
lines changed

3 files changed

+60
-28
lines changed

src/main/java/com/google/devtools/build/lib/packages/DefaultPackageArguments.java

+48-15
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.google.common.collect.ImmutableList;
1818
import com.google.devtools.build.lib.cmdline.Label;
1919
import com.google.devtools.build.lib.packages.License.DistributionType;
20+
import com.google.devtools.build.lib.server.FailureDetails.PackageLoading.Code;
2021
import java.util.List;
2122
import java.util.Set;
2223
import net.starlark.java.eval.EvalException;
@@ -30,15 +31,16 @@ private DefaultPackageArguments() {}
3031
/** Returns the default set of {@link PackageArgument}s. */
3132
static ImmutableList<PackageArgument<?>> get() {
3233
return ImmutableList.of(
33-
new DefaultDeprecation(),
34-
new DefaultDistribs(),
35-
new DefaultApplicableLicenses(),
36-
new DefaultLicenses(),
37-
new DefaultTestOnly(),
38-
new DefaultVisibility(),
39-
new Features(),
40-
new DefaultCompatibleWith(),
41-
new DefaultRestrictedTo());
34+
new DefaultDeprecation(),
35+
new DefaultDistribs(),
36+
new DefaultApplicableLicenses(),
37+
new DefaultPackageMetadata(),
38+
new DefaultLicenses(),
39+
new DefaultTestOnly(),
40+
new DefaultVisibility(),
41+
new Features(),
42+
new DefaultCompatibleWith(),
43+
new DefaultRestrictedTo());
4244
}
4345

4446
private static class DefaultVisibility extends PackageArgument<List<Label>> {
@@ -95,17 +97,48 @@ protected void process(Package.Builder pkgBuilder, Location location,
9597
* specified.
9698
*/
9799
private static class DefaultApplicableLicenses extends PackageArgument<List<Label>> {
98-
private static final String DEFAULT_APPLICABLE_LICENSES_ATTRIBUTE =
99-
"default_applicable_licenses";
100-
101100
private DefaultApplicableLicenses() {
102-
super(DEFAULT_APPLICABLE_LICENSES_ATTRIBUTE, BuildType.LABEL_LIST);
101+
super("default_applicable_licenses", BuildType.LABEL_LIST);
102+
}
103+
104+
@Override
105+
protected void process(Package.Builder pkgBuilder, Location location, List<Label> value) {
106+
if (!pkgBuilder.getDefaultPackageMetadata().isEmpty()) {
107+
pkgBuilder.addEvent(
108+
Package.error(
109+
location,
110+
"Can not set both default_package_metadata and default_applicable_licenses."
111+
+ " Move all declarations to default_package_metadata.",
112+
Code.INVALID_PACKAGE_SPECIFICATION));
113+
}
114+
115+
pkgBuilder.setDefaultPackageMetadata(value, "default_package_metadata", location);
116+
}
117+
}
118+
119+
/**
120+
* Declares the package() attribute specifying the default value for {@link
121+
* com.google.devtools.build.lib.packages.RuleClass#APPLICABLE_LICENSES_ATTR} when not explicitly
122+
* specified.
123+
*/
124+
private static class DefaultPackageMetadata extends PackageArgument<List<Label>> {
125+
private static final String DEFAULT_PACKAGE_METADATA_ATTRIBUTE = "default_package_metadata";
126+
127+
private DefaultPackageMetadata() {
128+
super(DEFAULT_PACKAGE_METADATA_ATTRIBUTE, BuildType.LABEL_LIST);
103129
}
104130

105131
@Override
106132
protected void process(Package.Builder pkgBuilder, Location location, List<Label> value) {
107-
pkgBuilder.setDefaultApplicableLicenses(
108-
value, DEFAULT_APPLICABLE_LICENSES_ATTRIBUTE, location);
133+
if (!pkgBuilder.getDefaultPackageMetadata().isEmpty()) {
134+
pkgBuilder.addEvent(
135+
Package.error(
136+
location,
137+
"Can not set both default_package_metadata and default_applicable_licenses."
138+
+ " Move all declarations to default_package_metadata.",
139+
Code.INVALID_PACKAGE_SPECIFICATION));
140+
}
141+
pkgBuilder.setDefaultPackageMetadata(value, DEFAULT_PACKAGE_METADATA_ATTRIBUTE, location);
109142
}
110143
}
111144

src/main/java/com/google/devtools/build/lib/packages/Package.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ public enum ConfigSettingVisibilityPolicy {
222222
/** The list of transitive closure of the Starlark file dependencies. */
223223
private ImmutableList<Label> starlarkFileDependencies;
224224

225-
/** The package's default "applicable_licenses" attribute. */
226-
private Set<Label> defaultApplicableLicenses = ImmutableSet.of();
225+
/** The package's default "package_metadata" attribute. */
226+
private ImmutableSet<Label> defaultPackageMetadata = ImmutableSet.of();
227227

228228
/**
229229
* The package's default "licenses" and "distribs" attributes, as specified
@@ -480,7 +480,7 @@ private void finishInit(Builder builder) {
480480
this.starlarkFileDependencies = builder.starlarkFileDependencies;
481481
this.defaultLicense = builder.defaultLicense;
482482
this.defaultDistributionSet = builder.defaultDistributionSet;
483-
this.defaultApplicableLicenses = ImmutableSortedSet.copyOf(builder.defaultApplicableLicenses);
483+
this.defaultPackageMetadata = ImmutableSortedSet.copyOf(builder.defaultPackageMetadata);
484484
this.features = ImmutableSortedSet.copyOf(builder.features);
485485
this.registeredExecutionPlatforms = ImmutableList.copyOf(builder.registeredExecutionPlatforms);
486486
this.registeredToolchains = ImmutableList.copyOf(builder.registeredToolchains);
@@ -799,9 +799,9 @@ public boolean isDefaultVisibilitySet() {
799799
return defaultVisibilitySet;
800800
}
801801

802-
/** Gets the licenses list for the default applicable_licenses declared by this package. */
803-
public Set<Label> getDefaultApplicableLicenses() {
804-
return defaultApplicableLicenses;
802+
/** Gets the package metadata list for the default metadata declared by this package. */
803+
public Set<Label> getDefaultPackageMetadata() {
804+
return defaultPackageMetadata;
805805
}
806806

807807
/** Gets the parsed license object for the default license declared by this package. */
@@ -1024,7 +1024,7 @@ public boolean recordLoadedModules() {
10241024
// serialize events emitted during its construction/evaluation.
10251025
@Nullable private FailureDetail failureDetailOverride = null;
10261026

1027-
private ImmutableList<Label> defaultApplicableLicenses = ImmutableList.of();
1027+
private ImmutableList<Label> defaultPackageMetadata = ImmutableList.of();
10281028
private License defaultLicense = License.NO_LICENSE;
10291029
private Set<License.DistributionType> defaultDistributionSet = License.DEFAULT_DISTRIB;
10301030

@@ -1431,16 +1431,16 @@ public Builder setStarlarkFileDependencies(ImmutableList<Label> starlarkFileDepe
14311431
* attribute when not explicitly specified by the rule. Records a package error if any labels
14321432
* are duplicated.
14331433
*/
1434-
void setDefaultApplicableLicenses(List<Label> licenses, String attrName, Location location) {
1434+
void setDefaultPackageMetadata(List<Label> licenses, String attrName, Location location) {
14351435
if (hasDuplicateLabels(
14361436
licenses, "package " + pkg.getName(), attrName, location, this::addEvent)) {
14371437
setContainsErrors();
14381438
}
1439-
this.defaultApplicableLicenses = ImmutableList.copyOf(licenses);
1439+
this.defaultPackageMetadata = ImmutableList.copyOf(licenses);
14401440
}
14411441

1442-
ImmutableList<Label> getDefaultApplicableLicenses() {
1443-
return defaultApplicableLicenses;
1442+
ImmutableList<Label> getDefaultPackageMetadata() {
1443+
return defaultPackageMetadata;
14441444
}
14451445

14461446
/**

src/main/java/com/google/devtools/build/lib/packages/RuleClass.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -2262,8 +2262,7 @@ private void populateDefaultRuleAttributeValues(
22622262
if (rule.getRuleClassObject().isPackageMetadataRule()) {
22632263
// Do nothing
22642264
} else {
2265-
rule.setAttributeValue(
2266-
attr, pkgBuilder.getDefaultApplicableLicenses(), /*explicit=*/ false);
2265+
rule.setAttributeValue(attr, pkgBuilder.getDefaultPackageMetadata(), /*explicit=*/ false);
22672266
}
22682267

22692268
} else if (attr.getName().equals("licenses") && attr.getType() == BuildType.LICENSE) {

0 commit comments

Comments
 (0)