8000 Remove the functionality behind LicensesProvider. · coderabbit-test/bazel@092fbd4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 092fbd4

Browse files
aiutocopybara-github
authored andcommitted
Remove the functionality behind LicensesProvider.
- remove `getTransitiveLicenses()`, `getOutputLicenses()`. These methods were only used for --check_licenses, which is now non-functional. - reduce LicensesProvider to a singleton EMPTY instance - remove tests on getTransitiveLicenses. This CL could potentially remove LicensesProvider entirely, but that is a much larger CL. I left it in place at this time so we can see what happens in broader testing against the nightly biulds. If no problems show up, I can remove LicensesProvider entirely. RELNOTES: None PiperOrigin-RevId: 746444137 Change-Id: Ifc859834d83ed2a219784b8360c613c59086b4e0
1 parent 073ade6 commit 092fbd4

File tree

6 files changed

+8
-256
lines changed

6 files changed

+8
-256
lines changed

src/main/java/com/google/devtools/build/lib/analysis/LicensesProvider.java

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,13 @@
1616

1717
import com.google.common.base.Preconditions;
1818
import com.google.devtools.build.lib.cmdline.Label;
19-
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
2019
import com.google.devtools.build.lib.packages.BuiltinProvider;
2120
import com.google.devtools.build.lib.packages.Info;
2221
import com.google.devtools.build.lib.packages.License;
2322
import java.util.Objects;
2423

2524
/** A {@link ConfiguredTarget} that has licensed targets in its transitive closure. */
2625
public interface LicensesProvider extends Info {
27-
/**
28-
* The set of label - license associations in the transitive closure.
29-
*
30-
* <p>Always returns an empty set if {@link
31-
* com.google.devtools.build.lib.analysis.config.BuildConfigurationValue#checkLicenses()} is
32-
* false.
33-
*/
34-
NestedSet<TargetLicense> getTransitiveLicenses();
35-
36-
/**
37-
* A label - license association for output_licenses. If there are no output_licenses it returns
38-
* null.
39-
*/
40-
TargetLicense getOutputLicenses();
41-
42-
/**
43-
* Return whether there is an output_licenses.
44-
*/
45-
boolean hasOutputLicenses();
4626

4727
public static final BuiltinProvider<LicensesProvider> PROVIDER =
4828
new BuiltinProvider<LicensesProvider>("LicenseInfo", LicensesProvider.class) {};
@@ -59,16 +39,12 @@ public TargetLicense(Label label, License license) {
5939
this.license = license;
6040
}
6141

62-
/**
63-
* Returns the label of the associated target.
64-
*/
42+
/** Returns the label of the associated target. */
6543
public Label getLabel() {
6644
return label;
6745
}
6846

69-
/**
70-
* Returns the license for the target.
71-
*/
47+
/** Returns the license for the target. */
7248
public License getLicense() {
7349
return license;
7450
}

src/main/java/com/google/devtools/build/lib/analysis/LicensesProviderImpl.java

Lines changed: 4 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -14,109 +14,24 @@
1414

1515
package com.google.devtools.build.lib.analysis;
1616

17-
import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue;
18-
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
19-
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
20-
import com.google.devtools.build.lib.collect.nestedset.Order;
2117
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
22-
import com.google.devtools.build.lib.packages.Attribute;
23-
import com.google.devtools.build.lib.packages.AttributeMap;
2418
import com.google.devtools.build.lib.packages.BuiltinProvider;
25-
import com.google.devtools.build.lib.packages.License;
26-
import com.google.devtools.build.lib.packages.Rule;
27-
import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndData;
2819
import net.starlark.java.eval.StarlarkValue;
2920

3021
/** A {@link ConfiguredTarget} that has licensed targets in its transitive closure. */
3122
@Immutable
3223
public final class LicensesProviderImpl implements LicensesProvider, StarlarkValue {
33-
public static final LicensesProvider EMPTY =
34-
new LicensesProviderImpl(NestedSetBuilder.<TargetLicense>emptySet(Order.LINK_ORDER), null);
24+
public static final LicensesProvider EMPTY = new LicensesProviderImpl();
3525

36-
private final NestedSet<TargetLicense> transitiveLicenses;
37-
private final TargetLicense outputLicenses;
38-
39-
public LicensesProviderImpl(
40-
NestedSet<TargetLicense> transitiveLicenses, TargetLicense outputLicenses) {
41-
this.transitiveLicenses = transitiveLicenses;
42-
this.outputLicenses = outputLicenses;
43-
}
26+
public LicensesProviderImpl() {}
4427

4528
@Override
4629
public BuiltinProvider<LicensesProvider> getProvider() {
4730
return LicensesProvider.PROVIDER;
4831
}
4932

50-
/**
51-
* Create the appropriate {@link LicensesProvider} for a rule based on its {@code RuleContext}
52-
*/
33+
/** Create the appropriate {@link LicensesProvider} for a rule based on its {@code RuleContext} */
5334
public static LicensesProvider of(RuleContext ruleContext) {
54-
if (!ruleContext.getConfiguration().checkLicenses()) {
55-
return EMPTY;
56-
}
57-
58-
NestedSetBuilder<TargetLicense> builder = NestedSetBuilder.linkOrder();
59-
BuildConfigurationValue configuration = ruleContext.getConfiguration();
60-
Rule rule = ruleContext.getRule();
61-
AttributeMap attributes = ruleContext.attributes();
62-
License toolOutputLicense = rule.getToolOutputLicense(attributes);
63-
TargetLicense outputLicenses =
64-
toolOutputLicense == null ? null : new TargetLicense(rule.getLabel(), toolOutputLicense);
65-
66-
if (configuration.isToolConfiguration() && toolOutputLicense != null) {
67-
if (toolOutputLicense != License.NO_LICENSE) {
68-
builder.add(outputLicenses);
69-
}
70-
} else {
71-
if (rule.getLicense() != License.NO_LICENSE) {
72-
builder.add(new TargetLicense(rule.getLabel(), rule.getLicense()));
73-
}
74-
75-
if (rule.getRuleClassObject().isPackageMetadataRule()) {
76-
// Don't crawl a new-style license, it's effectively a leaf.
77-
// The representation of the new-style rule is unfortunately hardcoded here,
78-
// but this is code in the old-style licensing path that will ultimately be removed.
79-
} else {
80-
for (String depAttrName : attributes.getAttributeNames()) {
81-
// Only add the transitive licenses for the attributes that do not have the
82-
// output_licenses.
83-
Attribute attribute = attributes.getAttributeDefinition(depAttrName);
84-
for (ConfiguredTargetAndData dep :
85-
ruleContext.getPrerequisiteConfiguredTargets(depAttrName)) {
86-
LicensesProvider provider = dep.getConfiguredTarget().get(LicensesProvider.PROVIDER);
87-
if (provider == null) {
88-
continue;
89-
}
90-
if (useOutputLicenses(attribute, configuration) && provider.hasOutputLicenses()) {
91-
builder.add(provider.getOutputLicenses());
92-
} else {
93-
builder.addTransitive(provider.getTransitiveLicenses());
94-
}
95-
}
96-
}
97-
}
98-
}
99-
100-
return new LicensesProviderImpl(builder.build(), outputLicenses);
101-
}
102-
103-
private static boolean useOutputLicenses(
104-
Attribute attribute, BuildConfigurationValue configuration) {
105-
return configuration.isToolConfiguration() || attribute.useOutputLicenses();
106-
}
107-
108-
@Override
109-
public NestedSet<TargetLicense> getTransitiveLicenses() {
110-
return transitiveLicenses;
111-
}
112-
113-
@Override
114-
public TargetLicense getOutputLicenses() {
115-
return outputLicenses;
116-
}
117-
118-
@Override
119-
public boolean hasOutputLicenses() {
120-
return outputLicenses != null;
35+
return EMPTY;
12136
}
12237
}

src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/InputFileConfiguredTarget.java

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,14 @@
2121
import com.google.devtools.build.lib.analysis.LicensesProvider;
2222
import com.google.devtools.build.lib.analysis.TargetContext;
2323
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
24-
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
25-
import com.google.devtools.build.lib.collect.nestedset.Order;
2624
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
2725
import com.google.devtools.build.lib.packages.BuiltinProvider;
2826
import com.google.devtools.build.lib.packages.Info;
2927
import com.google.devtools.build.lib.packages.InputFile;
30-
import com.google.devtools.build.lib.packages.License;
3128
import com.google.devtools.build.lib.packages.PackageSpecification.PackageGroupContents;
3229
import com.google.devtools.build.lib.packages.Provider;
33-
import com.google.devtools.build.lib.packages.Target;
3430
import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization;
3531
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
36-
import java.util.Objects;
3732
import javax.annotation.Nullable;
3833
import net.starlark.java.eval.Printer;
3934

@@ -47,15 +42,13 @@
4742
@AutoCodec
4843
public final class InputFileConfiguredTarget extends FileConfiguredTarget {
4944

50-
private final NestedSet<TargetLicense> licenses;
5145
private final boolean isCreatedInSymbolicMacro;
5246

5347
public InputFileConfiguredTarget(TargetContext targetContext, SourceArtifact artifact) {
5448
this(
5549
targetContext.getAnalysisEnvironment().getOwner(),
5650
targetContext.getVisibility(),
5751
artifact,
58-
makeLicenses(targetContext.getTarget()),
5952
targetContext.getTarget().isCreatedInSymbolicMacro());
6053
checkArgument(targetContext.getTarget() instanceof InputFile, targetContext.getTarget());
6154
checkArgument(getConfigurationKey() == null, getLabel());
@@ -67,21 +60,11 @@ public InputFileConfiguredTarget(TargetContext targetContext, SourceArtifact art
6760
ActionLookupKey lookupKey,
6861
NestedSet<PackageGroupContents> visibility,
6962
SourceArtifact artifact,
70-
NestedSet<TargetLicense> licenses,
7163
boolean isCreatedInSymbolicMacro) {
7264
super(lookupKey, visibility, artifact);
73-
this.licenses = licenses;
7465
this.isCreatedInSymbolicMacro = isCreatedInSymbolicMacro;
7566
}
7667

77-
private static NestedSet<TargetLicense> makeLicenses(Target inputFile) {
78-
License license = inputFile.getLicense();
79-
return Objects.equals(license, License.NO_LICENSE)
80-
? NestedSetBuilder.emptySet(Order.LINK_ORDER)
81-
: NestedSetBuilder.create(
82-
Order.LINK_ORDER, new TargetLicense(inputFile.getLabel(), license));
83-
}
84-
8568
@Override
8669
public boolean isCreatedInSymbolicMacro() {
8770
return isCreatedInSymbolicMacro;
@@ -106,22 +89,6 @@ protected Info rawGetStarlarkProvider(Provider.Key providerKey) {
10689
return null;
10790
}
10891

109-
@Override
110-
public NestedSet<TargetLicense> getTransitiveLicenses() {
111-
return licenses;
112-
}
113-
114-
@Override
115-
@Nullable
116-
public TargetLicense getOutputLicenses() {
117-
return null;
118-
}
119-
120-
@Override
121-
public boolean hasOutputLicenses() {
122-
return false;
123-
}
124-
12592
@Override
12693
public void repr(Printer printer) {
12794
printer.append("<input file target " + getLabel() + ">");

src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/OutputFileConfiguredTarget.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.google.devtools.build.lib.actions.ActionLookupKey;
2222
import com.google.devtools.build.lib.actions.Artifact;
2323
import com.google.devtools.build.lib.analysis.LicensesProvider;
24-
import com.google.devtools.build.lib.analysis.LicensesProviderImpl;
2524
import com.google.devtools.build.lib.analysis.OutputGroupInfo;
2625
import com.google.devtools.build.lib.analysis.RequiredConfigFragmentsProvider;
2726
import com.google.devtools.build.lib.analysis.TargetContext;
@@ -101,10 +100,6 @@ protected Info rawGetStarlarkProvider(Provider.Key providerKey) {
101100
// The following Starlark providers do not implement TransitiveInfoProvider and thus may only be
102101
// requested via this method using a Provider.Key, not via getProvider(Class) above.
103102

104-
if (providerKey.equals(LicensesProvider.PROVIDER.getKey())) {
105-
return generatingRule.get(LicensesProvider.PROVIDER);
106-
}
107-
108103
if (providerKey.equals(InstrumentedFilesInfo.STARLARK_CONSTRUCTOR.getKey())) {
109104
return firstNonNull(
110105
generatingRule.get(InstrumentedFilesInfo.STARLARK_CONSTRUCTOR),
@@ -150,25 +145,6 @@ private void addNativeProviderFromRuleIfPresent(
150145
}
151146
}
152147

153-
@Override
154-
public NestedSet<TargetLicense> getTransitiveLicenses() {
155-
return getLicencesProviderFromGeneratingRule().getTransitiveLicenses();
156-
}
157-
158-
@Override
159-
public TargetLicense getOutputLicenses() {
160-
return getLicencesProviderFromGeneratingRule().getOutputLicenses();
161-
}
162-
163-
@Override
164-
public boolean hasOutputLicenses() {
165-
return getLicencesProviderFromGeneratingRule().hasOutputLicenses();
166-
}
167-
168-
private LicensesProvider getLicencesProviderFromGeneratingRule() {
169-
return firstNonNull(generatingRule.get(LicensesProvider.PROVIDER), LicensesProviderImpl.EMPTY);
170-
}
171-
172148
@Override
173149
public void repr(Printer printer) {
174150
printer.append("<output file target " + getLabel() + ">");

src/main/java/com/google/devtools/build/lib/rules/cpp/CcStarlarkInternal.java

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
import com.google.devtools.build.lib.actions.CommandLineExpansionException;
2828
import com.google.devtools.build.lib.actions.CommandLines.CommandLineAndParamFileInfo;
2929
import com.google.devtools.build.lib.actions.ParameterFile.ParameterFileType;
30-
import com.google.devtools.build.lib.analysis.LicensesProvider;
31-
import com.google.devtools.build.lib.analysis.LicensesProvider.TargetLicense;
32-
import com.google.devtools.build.lib.analysis.LicensesProviderImpl;
3330
import com.google.devtools.build.lib.analysis.RuleContext;
3431
import com.google.devtools.build.lib.analysis.actions.PathMappers;
3532
import com.google.devtools.build.lib.analysis.actions.SymlinkAction;
@@ -41,13 +38,9 @@
4138
import com.google.devtools.build.lib.cmdline.Label;
4239
import com.google.devtools.build.lib.collect.nestedset.Depset;
4340
import com.google.devtools.build.lib.collect.nestedset.Depset.TypeException;
44-
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
45-
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
46-
import com.google.devtools.build.lib.collect.nestedset.Order;
4741
import com.google.devtools.build.lib.packages.Attribute.ComputedDefault;
4842
import com.google.devtools.build.lib.packages.AttributeMap;
4943
import com.google.devtools.build.lib.packages.Info;
50-
import com.google.devtools.build.lib.packages.License;
5144
import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException;
5245
import com.google.devtools.build.lib.packages.StarlarkInfo;
5346
import com.google.devtools.build.lib.packages.StarlarkProvider;
@@ -483,19 +476,8 @@ public String escapeLabel(Label label) {
483476
},
484477
allowReturnNones = true)
485478
@Nullable
486-
public LicensesProvider getLicenses(StarlarkRuleContext starlarkRuleContext) {
487-
RuleContext ruleContext = starlarkRuleContext.getRuleContext();
488-
final License outputLicense =
489-
ruleContext.getRule().getToolOutputLicense(ruleContext.attributes());
490-
if (outputLicense != null && !outputLicense.equals(License.NO_LICENSE)) {
491-
final NestedSet<TargetLicense> license =
492- 7653
NestedSetBuilder.create(
493-
Order.STABLE_ORDER, new TargetLicense(ruleContext.getLabel(), outputLicense));
494-
return new LicensesProviderImpl(
495-
license, new TargetLicense(ruleContext.getLabel(), outputLicense));
496-
} else {
497-
return null;
498-
}
479+
public StarlarkList<String> getLicenses(StarlarkRuleContext starlarkRuleContext) {
480+
return null;
499481
}
500482

501483
@StarlarkMethod(

0 commit comments

Comments
 (0)
0