17
17
import com .google .common .collect .ImmutableList ;
18
18
import com .google .devtools .build .lib .cmdline .Label ;
19
19
import com .google .devtools .build .lib .packages .License .DistributionType ;
20
+ import com .google .devtools .build .lib .server .FailureDetails .PackageLoading .Code ;
20
21
import java .util .List ;
21
22
import java .util .Set ;
22
23
import net .starlark .java .eval .EvalException ;
@@ -30,15 +31,16 @@ private DefaultPackageArguments() {}
30
31
/** Returns the default set of {@link PackageArgument}s. */
31
32
static ImmutableList <PackageArgument <?>> get () {
32
33
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 ());
42
44
}
43
45
44
46
private static class DefaultVisibility extends PackageArgument <List <Label >> {
@@ -95,17 +97,48 @@ protected void process(Package.Builder pkgBuilder, Location location,
95
97
* specified.
96
98
*/
97
99
private static class DefaultApplicableLicenses extends PackageArgument <List <Label >> {
98
- private static final String DEFAULT_APPLICABLE_LICENSES_ATTRIBUTE =
99
- "default_applicable_licenses" ;
100
-
101
100
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 );
103
129
}
104
130
105
131
@ Override
106
132
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 );
109
142
}
110
143
}
111
144
0 commit comments