Add a FileProvider (which all ConfiguredTargets should have) to PackageGroupConfiguredTarget.
This fixes a crash when a package_group was referenced in an attribute that requires specific file types.
RELNOTES: None.
package com.google.devtools.build.lib.analysis;
+import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
+import com.google.devtools.build.lib.collect.nestedset.Order;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.packages.PackageGroup;
import com.google.devtools.build.lib.packages.PackageSpecification;
@@ -28,6 +30,9 @@ import com.google.devtools.build.lib.util.Preconditions;
*/
public final class PackageGroupConfiguredTarget extends AbstractConfiguredTarget
implements PackageSpecificationProvider {
+ private static final FileProvider NO_FILES = new FileProvider(
+ NestedSetBuilder.<Artifact>emptySet(Order.STABLE_ORDER));
+
private final NestedSet<PackageSpecification> packageSpecifications;
PackageGroupConfiguredTarget(TargetContext targetContext, PackageGroup packageGroup) {
@@ -39,8 +44,8 @@ public final class PackageGroupConfiguredTarget extends AbstractConfiguredTarget
for (Label label : packageGroup.getIncludes()) {
TransitiveInfoCollection include = targetContext.maybeFindDirectPrerequisite(
label, targetContext.getConfiguration());
- PackageSpecificationProvider provider = include == null ? null :
- include.getProvider(PackageSpecificationProvider.class);
+ PackageSpecificationProvider provider = include == null ? null
+ : include.getProvider(PackageSpecificationProvider.class);
if (provider == null) {
targetContext.getAnalysisEnvironment().getEventHandler().handle(Event.error(getTarget().getLocation(),
String.format("label '%s' does not refer to a package group", label)));
@@ -63,4 +68,13 @@ public final class PackageGroupConfiguredTarget extends AbstractConfiguredTarget
public NestedSet<PackageSpecification> getPackageSpecifications() {
return packageSpecifications;
}
+
+ @Override
+ public <P extends TransitiveInfoProvider> P getProvider(Class<P> provider) {
+ if (provider == FileProvider.class) {
+ return (P) NO_FILES;
+ } else {
+ return super.getProvider(provider);
+ }
+ }
}
