From b83c5f800699a1bbcac11baeab1155d85880d9e4 Mon Sep 17 00:00:00 2001 From: cparsons Date: Wed, 21 Nov 2018 14:46:57 -0800 Subject: [PATCH] Migrate InstrumentedFilesProvider to Starlark provider pattern Progress toward #6241 RELNOTES: None. PiperOrigin-RevId: 222463226 --- .../build/lib/analysis/BuildView.java | 4 +- .../analysis/RuleConfiguredTargetBuilder.java | 7 +- .../lib/analysis/TargetCompleteEvent.java | 6 +- .../FileConfiguredTarget.java | 11 ++- .../InputFileConfiguredTarget.java | 2 +- .../OutputFileConfiguredTarget.java | 59 +++------------ .../SkylarkRuleConfiguredTargetUtil.java | 6 +- .../analysis/skylark/SkylarkRuleContext.java | 4 +- .../test/InstrumentedFilesCollector.java | 22 +++--- ...erImpl.java => InstrumentedFilesInfo.java} | 63 +++++++++++++--- .../test/InstrumentedFilesProvider.java | 75 ------------------- .../lib/analysis/test/TestActionBuilder.java | 5 +- .../build/lib/bazel/rules/sh/ShBinary.java | 4 +- .../build/lib/rules/cpp/CcBinary.java | 6 +- .../build/lib/rules/cpp/CcCommon.java | 9 +-- .../build/lib/rules/cpp/CcLibrary.java | 6 +- .../build/lib/rules/filegroup/Filegroup.java | 9 +-- .../build/lib/rules/java/JavaCommon.java | 7 +- .../build/lib/rules/objc/AppleBinary.java | 8 +- .../lib/rules/objc/CompilationSupport.java | 14 ++-- .../build/lib/rules/objc/ObjcLibrary.java | 4 +- .../build/lib/rules/python/PyCommon.java | 4 +- .../lib/analysis/util/BuildViewTestCase.java | 7 +- .../cpp/CcLibraryConfiguredTargetTest.java | 4 +- .../build/lib/rules/objc/AppleBinaryTest.java | 6 +- .../lib/skylark/SkylarkIntegrationTest.java | 6 +- 26 files changed, 138 insertions(+), 220 deletions(-) rename src/main/java/com/google/devtools/build/lib/analysis/test/{InstrumentedFilesProviderImpl.java => InstrumentedFilesInfo.java} (56%) delete mode 100644 src/main/java/com/google/devtools/build/lib/analysis/test/InstrumentedFilesProvider.java diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java b/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java index d0dbde19ded23d..ae8875e6339a95 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java @@ -39,7 +39,7 @@ import com.google.devtools.build.lib.analysis.constraints.TopLevelConstraintSemantics; import com.google.devtools.build.lib.analysis.test.CoverageReportActionFactory; import com.google.devtools.build.lib.analysis.test.CoverageReportActionFactory.CoverageReportActionsWrapper; -import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider; +import com.google.devtools.build.lib.analysis.test.InstrumentedFilesInfo; 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; @@ -528,7 +528,7 @@ private static NestedSet getBaselineCoverageArtifacts( ArtifactsToOwnerLabels.Builder topLevelArtifactsToOwnerLabels) { NestedSetBuilder baselineCoverageArtifacts = NestedSetBuilder.stableOrder(); for (ConfiguredTarget target : configuredTargets) { - InstrumentedFilesProvider provider = target.getProvider(InstrumentedFilesProvider.class); + InstrumentedFilesInfo provider = target.get(InstrumentedFilesInfo.SKYLARK_CONSTRUCTOR); if (provider != null) { TopLevelArtifactHelper.addArtifactsWithOwnerLabel( provider.getBaselineCoverageArtifacts(), diff --git a/src/main/java/com/google/devtools/build/lib/analysis/RuleConfiguredTargetBuilder.java b/src/main/java/com/google/devtools/build/lib/analysis/RuleConfiguredTargetBuilder.java index 181f6d51d2f63b..74d51a826ef503 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/RuleConfiguredTargetBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/RuleConfiguredTargetBuilder.java @@ -34,7 +34,7 @@ import com.google.devtools.build.lib.analysis.test.AnalysisTestActionBuilder; import com.google.devtools.build.lib.analysis.test.AnalysisTestResultInfo; import com.google.devtools.build.lib.analysis.test.ExecutionInfo; -import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider; +import com.google.devtools.build.lib.analysis.test.InstrumentedFilesInfo; import com.google.devtools.build.lib.analysis.test.TestActionBuilder; import com.google.devtools.build.lib.analysis.test.TestEnvironmentInfo; import com.google.devtools.build.lib.analysis.test.TestProvider; @@ -269,7 +269,10 @@ private TestProvider initializeTestProvider(FilesToRunProvider filesToRunProvide } TestActionBuilder testActionBuilder = new TestActionBuilder(ruleContext) - .setInstrumentedFiles(providersBuilder.getProvider(InstrumentedFilesProvider.class)); + .setInstrumentedFiles( + (InstrumentedFilesInfo) + providersBuilder.getProvider( + InstrumentedFilesInfo.SKYLARK_CONSTRUCTOR.getKey())); TestEnvironmentInfo environmentProvider = (TestEnvironmentInfo) diff --git a/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java b/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java index a4c793b4b9fedf..cf72a5ab09a227 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java @@ -26,7 +26,7 @@ import com.google.devtools.build.lib.analysis.TopLevelArtifactHelper.ArtifactsInOutputGroup; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget; -import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider; +import com.google.devtools.build.lib.analysis.test.InstrumentedFilesInfo; import com.google.devtools.build.lib.analysis.test.TestConfiguration; import com.google.devtools.build.lib.analysis.test.TestProvider; import com.google.devtools.build.lib.buildeventstream.ArtifactGroupNamer; @@ -152,8 +152,8 @@ private TargetCompleteEvent( isTest ? targetAndData.getConfiguredTarget().getProvider(TestProvider.class).getTestParams() : null; - InstrumentedFilesProvider instrumentedFilesProvider = - targetAndData.getConfiguredTarget().getProvider(InstrumentedFilesProvider.class); + InstrumentedFilesInfo instrumentedFilesProvider = + targetAndData.getConfiguredTarget().get(InstrumentedFilesInfo.SKYLARK_CONSTRUCTOR); if (instrumentedFilesProvider == null) { this.baselineCoverageArtifacts = null; } else { diff --git a/src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/FileConfiguredTarget.java b/src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/FileConfiguredTarget.java index 10825725ad55a8..a19914c6d3ab6c 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/FileConfiguredTarget.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/FileConfiguredTarget.java @@ -23,7 +23,7 @@ import com.google.devtools.build.lib.analysis.TransitiveInfoProviderMap; import com.google.devtools.build.lib.analysis.TransitiveInfoProviderMapBuilder; import com.google.devtools.build.lib.analysis.VisibilityProvider; -import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider; +import com.google.devtools.build.lib.analysis.test.InstrumentedFilesInfo; 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; @@ -33,6 +33,7 @@ import com.google.devtools.build.lib.packages.Provider; import com.google.devtools.build.lib.skyframe.BuildConfigurationValue; import com.google.devtools.build.lib.util.FileType; +import javax.annotation.Nullable; /** * A ConfiguredTarget for a source FileTarget. (Generated files use a subclass, @@ -47,7 +48,8 @@ public abstract class FileConfiguredTarget extends AbstractConfiguredTarget Label label, BuildConfigurationValue.Key configurationKey, NestedSet visibility, - Artifact artifact) { + Artifact artifact, + @Nullable InstrumentedFilesInfo instrumentedFilesInfo) { super(label, configurationKey, visibility); NestedSet filesToBuild = NestedSetBuilder.create(Order.STABLE_ORDER, artifact); FileProvider fileProvider = new FileProvider(filesToBuild); @@ -59,8 +61,9 @@ public abstract class FileConfiguredTarget extends AbstractConfiguredTarget .put(LicensesProvider.class, this) .add(fileProvider) .add(filesToRunProvider); - if (this instanceof InstrumentedFilesProvider) { - builder.put(InstrumentedFilesProvider.class, this); + + if (instrumentedFilesInfo != null) { + builder.put(instrumentedFilesInfo); } this.providers = builder.build(); } diff --git a/src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/InputFileConfiguredTarget.java b/src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/InputFileConfiguredTarget.java index 16eca3a5c3257a..79d839d312ad07 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/InputFileConfiguredTarget.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/InputFileConfiguredTarget.java @@ -49,7 +49,7 @@ public final class InputFileConfiguredTarget extends FileConfiguredTarget implem NestedSet visibility, SourceArtifact artifact, NestedSet licenses) { - super(label, null, visibility, artifact); + super(label, null, visibility, artifact, null); this.artifact = artifact; this.licenses = licenses; } diff --git a/src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/OutputFileConfiguredTarget.java b/src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/OutputFileConfiguredTarget.java index ab170a534b59b3..bbe02d5b3d7bb3 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/OutputFileConfiguredTarget.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/configuredtargets/OutputFileConfiguredTarget.java @@ -21,8 +21,7 @@ import com.google.devtools.build.lib.analysis.TargetContext; import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; import com.google.devtools.build.lib.analysis.TransitiveInfoProvider; -import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider; -import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProviderImpl; +import com.google.devtools.build.lib.analysis.test.InstrumentedFilesInfo; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.packages.OutputFile; @@ -32,12 +31,10 @@ import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.Instantiator; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter; -import com.google.devtools.build.lib.util.Pair; /** A ConfiguredTarget for an OutputFile. */ @AutoCodec -public class OutputFileConfiguredTarget extends FileConfiguredTarget - implements InstrumentedFilesProvider { +public class OutputFileConfiguredTarget extends FileConfiguredTarget { private final Artifact artifact; private final TransitiveInfoCollection generatingRule; @@ -62,11 +59,18 @@ public OutputFileConfiguredTarget( NestedSet visibility, Artifact artifact, TransitiveInfoCollection generatingRule) { - super(label, configurationKey, visibility, artifact); + super(label, configurationKey, visibility, artifact, instrumentedFilesInfo(generatingRule)); this.artifact = artifact; this.generatingRule = Preconditions.checkNotNull(generatingRule); } + private static InstrumentedFilesInfo instrumentedFilesInfo( + TransitiveInfoCollection generatingRule) { + Preconditions.checkNotNull(generatingRule); + InstrumentedFilesInfo provider = generatingRule.get(InstrumentedFilesInfo.SKYLARK_CONSTRUCTOR); + return provider == null ? InstrumentedFilesInfo.EMPTY : provider; + } + public TransitiveInfoCollection getGeneratingRule() { return generatingRule; } @@ -94,49 +98,6 @@ public boolean hasOutputLicenses() { .hasOutputLicenses(); } - - @Override - public NestedSet getInstrumentedFiles() { - return getProvider(InstrumentedFilesProvider.class, InstrumentedFilesProviderImpl.EMPTY) - .getInstrumentedFiles(); - } - - @Override - public NestedSet getInstrumentationMetadataFiles() { - return getProvider(InstrumentedFilesProvider.class, InstrumentedFilesProviderImpl.EMPTY) - .getInstrumentationMetadataFiles(); - } - - @Override - public NestedSet getBaselineCoverageInstrumentedFiles() { - return getProvider(InstrumentedFilesProvider.class, InstrumentedFilesProviderImpl.EMPTY) - .getBaselineCoverageInstrumentedFiles(); - } - - @Override - public NestedSet getBaselineCoverageArtifacts() { - return getProvider(InstrumentedFilesProvider.class, InstrumentedFilesProviderImpl.EMPTY) - .getBaselineCoverageArtifacts(); - } - - @Override - public NestedSet getCoverageSupportFiles() { - return getProvider(InstrumentedFilesProvider.class, InstrumentedFilesProviderImpl.EMPTY) - .getCoverageSupportFiles(); - } - - @Override - public NestedSet> getCoverageEnvironment() { - return getProvider(InstrumentedFilesProvider.class, InstrumentedFilesProviderImpl.EMPTY) - .getCoverageEnvironment(); - } - - @Override - public NestedSet> getReportedToActualSources() { - return getProvider(InstrumentedFilesProvider.class, InstrumentedFilesProviderImpl.EMPTY) - .getReportedToActualSources(); - } - /** * Returns the corresponding provider from the generating rule, if it is non-null, or {@code * defaultValue} otherwise. diff --git a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleConfiguredTargetUtil.java b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleConfiguredTargetUtil.java index c0d611ad553b0c..64247f094d26e3 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleConfiguredTargetUtil.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleConfiguredTargetUtil.java @@ -31,7 +31,7 @@ import com.google.devtools.build.lib.analysis.Whitelist; import com.google.devtools.build.lib.analysis.test.InstrumentedFilesCollector; import com.google.devtools.build.lib.analysis.test.InstrumentedFilesCollector.InstrumentationSpec; -import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider; +import com.google.devtools.build.lib.analysis.test.InstrumentedFilesInfo; 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; @@ -260,14 +260,14 @@ private static void addInstrumentedFiles( new InstrumentationSpec(fileTypeSet) .withSourceAttributes(sourceAttributes.toArray(new String[0])) .withDependencyAttributes(dependencyAttributes.toArray(new String[0])); - InstrumentedFilesProvider instrumentedFilesProvider = + InstrumentedFilesInfo instrumentedFilesProvider = InstrumentedFilesCollector.collect( ruleContext, instrumentationSpec, InstrumentedFilesCollector.NO_METADATA_COLLECTOR, /* rootFiles= */ Collections.emptySet(), /* reportedToActualSources= */ NestedSetBuilder.create(Order.STABLE_ORDER)); - builder.addProvider(InstrumentedFilesProvider.class, instrumentedFilesProvider); + builder.addNativeDeclaredProvider(instrumentedFilesProvider); } public static NestedSet convertToOutputGroupValue(Location loc, String outputGroup, diff --git a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleContext.java b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleContext.java index 136ab5577e04a0..72ac8b07f88910 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleContext.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleContext.java @@ -50,7 +50,7 @@ import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget.Mode; import com.google.devtools.build.lib.analysis.stringtemplate.ExpansionException; import com.google.devtools.build.lib.analysis.test.InstrumentedFilesCollector; -import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider; +import com.google.devtools.build.lib.analysis.test.InstrumentedFilesInfo; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.events.Location; import com.google.devtools.build.lib.packages.Aspect; @@ -611,7 +611,7 @@ public boolean instrumentCoverage(Object targetUnchecked) throws EvalException { return InstrumentedFilesCollector.shouldIncludeLocalSources(ruleContext); } TransitiveInfoCollection target = (TransitiveInfoCollection) targetUnchecked; - return (target.getProvider(InstrumentedFilesProvider.class) != null) + return (target.get(InstrumentedFilesInfo.SKYLARK_CONSTRUCTOR) != null) && InstrumentedFilesCollector.shouldIncludeLocalSources(config, target); } diff --git a/src/main/java/com/google/devtools/build/lib/analysis/test/InstrumentedFilesCollector.java b/src/main/java/com/google/devtools/build/lib/analysis/test/InstrumentedFilesCollector.java index 2f1ae0edc72a39..e10f4fc9b916c3 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/test/InstrumentedFilesCollector.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/test/InstrumentedFilesCollector.java @@ -42,13 +42,13 @@ public final class InstrumentedFilesCollector { /** - * Forwards any instrumented files from the given target's dependencies (as defined in - * {@code dependencyAttributes}) for further export. No files from this target are considered + * Forwards any instrumented files from the given target's dependencies (as defined in {@code + * dependencyAttributes}) for further export. No files from this target are considered * instrumented. * * @return instrumented file provider of all dependencies in {@code dependencyAttributes} */ - public static InstrumentedFilesProvider forward( + public static InstrumentedFilesInfo forward( RuleContext ruleContext, String... dependencyAttributes) { return collect( ruleContext, @@ -58,7 +58,7 @@ public static InstrumentedFilesProvider forward( /* reportedToActualSources= */ NestedSetBuilder.create(Order.STABLE_ORDER)); } - public static InstrumentedFilesProvider collect( + public static InstrumentedFilesInfo collect( RuleContext ruleContext, InstrumentationSpec spec, LocalMetadataCollector localMetadataCollector, @@ -71,7 +71,7 @@ public static InstrumentedFilesProvider collect( /* reportedToActualSources= */ NestedSetBuilder.create(Order.STABLE_ORDER)); } - public static InstrumentedFilesProvider collect( + public static InstrumentedFilesInfo collect( RuleContext ruleContext, InstrumentationSpec spec, LocalMetadataCollector localMetadataCollector, @@ -95,7 +95,7 @@ public static InstrumentedFilesProvider collect( * coverage actions for the transitive closure of source files (if withBaselineCoverage * is true). */ - public static InstrumentedFilesProvider collect( + public static InstrumentedFilesInfo collect( RuleContext ruleContext, InstrumentationSpec spec, LocalMetadataCollector localMetadataCollector, @@ -114,7 +114,7 @@ public static InstrumentedFilesProvider collect( /* reportedToActualSources= */ NestedSetBuilder.create(Order.STABLE_ORDER)); } - public static InstrumentedFilesProvider collect( + public static InstrumentedFilesInfo collect( RuleContext ruleContext, InstrumentationSpec spec, LocalMetadataCollector localMetadataCollector, @@ -127,7 +127,7 @@ public static InstrumentedFilesProvider collect( Preconditions.checkNotNull(spec); if (!ruleContext.getConfiguration().isCodeCoverageEnabled()) { - return InstrumentedFilesProviderImpl.EMPTY; + return InstrumentedFilesInfo.EMPTY; } NestedSetBuilder instrumentedFilesBuilder = NestedSetBuilder.stableOrder(); @@ -145,7 +145,7 @@ public static InstrumentedFilesProvider collect( // Transitive instrumentation data. for (TransitiveInfoCollection dep : getAllPrerequisites(ruleContext, spec.dependencyAttributes)) { - InstrumentedFilesProvider provider = dep.getProvider(InstrumentedFilesProvider.class); + InstrumentedFilesInfo provider = dep.get(InstrumentedFilesInfo.SKYLARK_CONSTRUCTOR); if (provider != null) { instrumentedFilesBuilder.addTransitive(provider.getInstrumentedFiles()); metadataFilesBuilder.addTransitive(provider.getInstrumentationMetadataFiles()); @@ -162,7 +162,7 @@ public static InstrumentedFilesProvider collect( NestedSetBuilder localSourcesBuilder = NestedSetBuilder.stableOrder(); for (TransitiveInfoCollection dep : getAllPrerequisites(ruleContext, spec.sourceAttributes)) { - if (!spec.splitLists && dep.getProvider(InstrumentedFilesProvider.class) != null) { + if (!spec.splitLists && dep.get(InstrumentedFilesInfo.SKYLARK_CONSTRUCTOR) != null) { continue; } for (Artifact artifact : dep.getProvider(FileProvider.class).getFilesToBuild()) { @@ -194,7 +194,7 @@ public static InstrumentedFilesProvider collect( // Create one baseline coverage action per target, but for the transitive closure of files. NestedSet baselineCoverageArtifacts = BaselineCoverageAction.create(ruleContext, baselineCoverageFiles); - return new InstrumentedFilesProviderImpl( + return new InstrumentedFilesInfo( instrumentedFilesBuilder.build(), metadataFilesBuilder.build(), baselineCoverageFiles, diff --git a/src/main/java/com/google/devtools/build/lib/analysis/test/InstrumentedFilesProviderImpl.java b/src/main/java/com/google/devtools/build/lib/analysis/test/InstrumentedFilesInfo.java similarity index 56% rename from src/main/java/com/google/devtools/build/lib/analysis/test/InstrumentedFilesProviderImpl.java rename to src/main/java/com/google/devtools/build/lib/analysis/test/InstrumentedFilesInfo.java index 19219d54161c0c..cf59445acc9894 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/test/InstrumentedFilesProviderImpl.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/test/InstrumentedFilesInfo.java @@ -17,14 +17,21 @@ 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.Location; +import com.google.devtools.build.lib.packages.BuiltinProvider; +import com.google.devtools.build.lib.packages.Info; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.lib.util.Pair; /** An implementation class for the InstrumentedFilesProvider interface. */ @AutoCodec -public final class InstrumentedFilesProviderImpl implements InstrumentedFilesProvider { - public static final InstrumentedFilesProvider EMPTY = - new InstrumentedFilesProviderImpl( +public final class InstrumentedFilesInfo extends Info { + /** Singleton provider instance for {@link InstrumentedFilesInfo}. */ + public static final InstrumentedFilesProvider SKYLARK_CONSTRUCTOR = + new InstrumentedFilesProvider(); + + public static final InstrumentedFilesInfo EMPTY = + new InstrumentedFilesInfo( NestedSetBuilder.emptySet(Order.STABLE_ORDER), NestedSetBuilder.emptySet(Order.STABLE_ORDER), NestedSetBuilder.emptySet(Order.STABLE_ORDER), @@ -41,7 +48,7 @@ public final class InstrumentedFilesProviderImpl implements InstrumentedFilesPro private final NestedSet> coverageEnvironment; private final NestedSet> reportedToActualSources; - public InstrumentedFilesProviderImpl( + public InstrumentedFilesInfo( NestedSet instrumentedFiles, NestedSet instrumentationMetadataFiles, NestedSet baselineCoverageFiles, @@ -49,6 +56,7 @@ public InstrumentedFilesProviderImpl( NestedSet coverageSupportFiles, NestedSet> coverageEnvironment, NestedSet> reportedToActualSources) { + super(SKYLARK_CONSTRUCTOR, Location.BUILTIN); this.instrumentedFiles = instrumentedFiles; this.instrumentationMetadataFiles = instrumentationMetadataFiles; this.baselineCoverageFiles = baselineCoverageFiles; @@ -58,38 +66,71 @@ public InstrumentedFilesProviderImpl( this.reportedToActualSources = reportedToActualSources; } - @Override + /** The transitive closure of instrumented source files. */ public NestedSet getInstrumentedFiles() { return instrumentedFiles; } - @Override + /** Returns a collection of instrumentation metadata files. */ public NestedSet getInstrumentationMetadataFiles() { return instrumentationMetadataFiles; } - @Override + /** + * The transitive closure of instrumented source files for which baseline coverage should be + * generated. In general, this is a subset of the instrumented source files: it only contains + * instrumented source files from rules that support baseline coverage. + */ + // TODO(ulfjack): Change this to a single Artifact. Also change how it's generated. It's better to + // generate actions such that each action only covers the source files of a single rule, in + // particular because baseline coverage is language-specific (it requires a parser for the + // specific language), and we don't want to depend on all language parsers from any single rule. public NestedSet getBaselineCoverageInstrumentedFiles() { return baselineCoverageFiles; } - @Override + /** + * The output artifact of the baseline coverage action; this is only ever a single artifact, which + * contains baseline coverage for the entire transitive closure of source files. + */ public NestedSet getBaselineCoverageArtifacts() { return baselineCoverageArtifacts; } - @Override + /** + * Extra files that are needed on the inputs of test actions for coverage collection to happen, + * for example, {@code gcov}. + * + *

They aren't mentioned in the instrumented files manifest. + */ public NestedSet getCoverageSupportFiles() { return coverageSupportFiles; } - @Override + /** Environment variables that need to be set for tests collecting code coverage. */ public NestedSet> getCoverageEnvironment() { return coverageEnvironment; } - @Override + /** + * A set of pairs of reported source file path and the actual source file path, relative to the + * workspace directory, if the two values are different. If the reported source file is the same + * as the actual source path it will not be included in this set. + * + *

This is useful for virtual include paths in C++, which get reported at the include location + * and not the real source path. For example, the reported include source file can be + * "bazel-out/k8-fastbuild/bin/include/common/_virtual_includes/strategy/strategy.h", but its + * actual source path is "include/common/strategy.h". + */ public NestedSet> getReportedToActualSources() { return reportedToActualSources; } + + /** Provider implementation for {@link InstrumentedFilesInfo}. */ + public static class InstrumentedFilesProvider extends BuiltinProvider { + + public InstrumentedFilesProvider() { + super("InstrumentedFilesInfo", InstrumentedFilesInfo.class); + } + } } diff --git a/src/main/java/com/google/devtools/build/lib/analysis/test/InstrumentedFilesProvider.java b/src/main/java/com/google/devtools/build/lib/analysis/test/InstrumentedFilesProvider.java deleted file mode 100644 index 5fc7efcd2b7980..00000000000000 --- a/src/main/java/com/google/devtools/build/lib/analysis/test/InstrumentedFilesProvider.java +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2014 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.analysis.test; - -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.analysis.TransitiveInfoProvider; -import com.google.devtools.build.lib.collect.nestedset.NestedSet; -import com.google.devtools.build.lib.util.Pair; - -/** A provider of instrumented file sources and instrumentation metadata. */ -public interface InstrumentedFilesProvider extends TransitiveInfoProvider { - /** - * The transitive closure of instrumented source files. - */ - NestedSet getInstrumentedFiles(); - - /** - * Returns a collection of instrumentation metadata files. - */ - NestedSet getInstrumentationMetadataFiles(); - - /** - * The transitive closure of instrumented source files for which baseline coverage should be - * generated. In general, this is a subset of the instrumented source files: it only contains - * instrumented source files from rules that support baseline coverage. - */ - NestedSet getBaselineCoverageInstrumentedFiles(); - - /** - * The output artifact of the baseline coverage action; this is only ever a single artifact, which - * contains baseline coverage for the entire transitive closure of source files. - */ - // TODO(ulfjack): Change this to a single Artifact. Also change how it's generated. It's better to - // generate actions such that each action only covers the source files of a single rule, in - // particular because baseline coverage is language-specific (it requires a parser for the - // specific language), and we don't want to depend on all language parsers from any single rule. - NestedSet getBaselineCoverageArtifacts(); - - /** - * Extra files that are needed on the inputs of test actions for coverage collection to happen, - * for example, {@code gcov}. - * - *

They aren't mentioned in the instrumented files manifest. - */ - NestedSet getCoverageSupportFiles(); - - /** - * Environment variables that need to be set for tests collecting code coverage. - */ - NestedSet> getCoverageEnvironment(); - - /** - * A set of pairs of reported source file path and the actual source file path, relative to the - * workspace directory, if the two values are different. If the reported source file is the same - * as the actual source path it will not be included in this set. - * - *

This is useful for virtual include paths in C++, which get reported at the include location - * and not the real source path. For example, the reported include source file can be - * "bazel-out/k8-fastbuild/bin/include/common/_virtual_includes/strategy/strategy.h", but its - * actual source path is "include/common/strategy.h". - */ - NestedSet> getReportedToActualSources(); -} diff --git a/src/main/java/com/google/devtools/build/lib/analysis/test/TestActionBuilder.java b/src/main/java/com/google/devtools/build/lib/analysis/test/TestActionBuilder.java index 9947bebc528c23..d2d1df4b7b825f 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/test/TestActionBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/test/TestActionBuilder.java @@ -75,7 +75,7 @@ enum CcCoverageTool { private RunfilesSupport runfilesSupport; private Artifact executable; private ExecutionInfo executionRequirements; - private InstrumentedFilesProvider instrumentedFiles; + private InstrumentedFilesInfo instrumentedFiles; private int explicitShardCount; private Map extraEnv; @@ -125,8 +125,7 @@ public TestActionBuilder setFilesToRunProvider(FilesToRunProvider provider) { return this; } - public TestActionBuilder setInstrumentedFiles( - @Nullable InstrumentedFilesProvider instrumentedFiles) { + public TestActionBuilder setInstrumentedFiles(@Nullable InstrumentedFilesInfo instrumentedFiles) { this.instrumentedFiles = instrumentedFiles; return this; } diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/sh/ShBinary.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/sh/ShBinary.java index 91432d0cd0c19a..9541d0567d75bc 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/sh/ShBinary.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/sh/ShBinary.java @@ -33,7 +33,6 @@ import com.google.devtools.build.lib.analysis.test.InstrumentedFilesCollector; import com.google.devtools.build.lib.analysis.test.InstrumentedFilesCollector.InstrumentationSpec; import com.google.devtools.build.lib.analysis.test.InstrumentedFilesCollector.LocalMetadataCollector; -import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider; 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; @@ -99,8 +98,7 @@ public ConfiguredTarget create(RuleContext ruleContext) .setFilesToBuild(filesToBuild) .setRunfilesSupport(runfilesSupport, mainExecutable) .addProvider(RunfilesProvider.class, RunfilesProvider.simple(runfiles)) - .addProvider( - InstrumentedFilesProvider.class, + .addNativeDeclaredProvider( InstrumentedFilesCollector.collect( ruleContext, new InstrumentationSpec(FileTypeSet.ANY_FILE, "srcs", "deps", "data"), diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java index 66e8e9f11e82c4..9c8fd591f42658 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java @@ -45,7 +45,7 @@ import com.google.devtools.build.lib.analysis.actions.SymlinkAction; import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget.Mode; import com.google.devtools.build.lib.analysis.test.ExecutionInfo; -import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider; +import com.google.devtools.build.lib.analysis.test.InstrumentedFilesInfo; 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; @@ -913,7 +913,7 @@ private static void addTransitiveInfoProviders( List instrumentedObjectFiles = new ArrayList<>(); instrumentedObjectFiles.addAll(ccCompilationOutputs.getObjectFiles(false)); instrumentedObjectFiles.addAll(ccCompilationOutputs.getObjectFiles(true)); - InstrumentedFilesProvider instrumentedFilesProvider = + InstrumentedFilesInfo instrumentedFilesProvider = common.getInstrumentedFilesProvider( instrumentedObjectFiles, !TargetUtils.isTestRule(ruleContext.getRule()) && !fake, @@ -934,7 +934,7 @@ private static void addTransitiveInfoProviders( new CcNativeLibraryProvider( collectTransitiveCcNativeLibraries( ruleContext, linkingOutputs.getDynamicLibrariesForLinking()))) - .addProvider(InstrumentedFilesProvider.class, instrumentedFilesProvider) + .addNativeDeclaredProvider(instrumentedFilesProvider) .addProvider( CppDebugFileProvider.class, new CppDebugFileProvider( diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java index 3c5318f48d44d4..02ab81e655c668 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java @@ -35,7 +35,7 @@ import com.google.devtools.build.lib.analysis.skylark.SkylarkRuleContext; import com.google.devtools.build.lib.analysis.test.InstrumentedFilesCollector; import com.google.devtools.build.lib.analysis.test.InstrumentedFilesCollector.LocalMetadataCollector; -import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider; +import com.google.devtools.build.lib.analysis.test.InstrumentedFilesInfo; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.cmdline.PackageIdentifier; import com.google.devtools.build.lib.collect.nestedset.NestedSet; @@ -695,9 +695,8 @@ Artifact getWinDefFile() { } /** Provides support for instrumentation. */ - public InstrumentedFilesProvider getInstrumentedFilesProvider( - Iterable files, - boolean withBaselineCoverage) { + public InstrumentedFilesInfo getInstrumentedFilesProvider( + Iterable files, boolean withBaselineCoverage) { return getInstrumentedFilesProvider( files, withBaselineCoverage, @@ -705,7 +704,7 @@ public InstrumentedFilesProvider getInstrumentedFilesProvider( ); } - public InstrumentedFilesProvider getInstrumentedFilesProvider( + public InstrumentedFilesInfo getInstrumentedFilesProvider( Iterable files, boolean withBaselineCoverage, NestedSet> virtualToOriginalHeaders) { diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java index f6b8b9710a2dba..efcb7264ffc32c 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java @@ -39,7 +39,7 @@ import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException; import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget.Mode; -import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider; +import com.google.devtools.build.lib.analysis.test.InstrumentedFilesInfo; 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; @@ -406,7 +406,7 @@ public static void init( List instrumentedObjectFiles = new ArrayList<>(); instrumentedObjectFiles.addAll(compilationInfo.getCcCompilationOutputs().getObjectFiles(false)); instrumentedObjectFiles.addAll(compilationInfo.getCcCompilationOutputs().getObjectFiles(true)); - InstrumentedFilesProvider instrumentedFilesProvider = + InstrumentedFilesInfo instrumentedFilesProvider = common.getInstrumentedFilesProvider( instrumentedObjectFiles, /* withBaselineCoverage= */ true, @@ -444,7 +444,7 @@ public static void init( .addOutputGroups( CcCommon.mergeOutputGroups( ImmutableList.of(compilationInfo.getOutputGroups(), outputGroups.build()))) - .addProvider(InstrumentedFilesProvider.class, instrumentedFilesProvider) + .addNativeDeclaredProvider(instrumentedFilesProvider) .addProvider(RunfilesProvider.withData(defaultRunfiles.build(), dataRunfiles.build())) .addOutputGroup( OutputGroupInfo.HIDDEN_TOP_LEVEL, diff --git a/src/main/java/com/google/devtools/build/lib/rules/filegroup/Filegroup.java b/src/main/java/com/google/devtools/build/lib/rules/filegroup/Filegroup.java index e33d2cf7952c0d..cff45255c9d391 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/filegroup/Filegroup.java +++ b/src/main/java/com/google/devtools/build/lib/rules/filegroup/Filegroup.java @@ -33,7 +33,7 @@ import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget.Mode; import com.google.devtools.build.lib.analysis.test.InstrumentedFilesCollector; import com.google.devtools.build.lib.analysis.test.InstrumentedFilesCollector.InstrumentationSpec; -import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider; +import com.google.devtools.build.lib.analysis.test.InstrumentedFilesInfo; 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; @@ -72,7 +72,7 @@ public ConfiguredTarget create(RuleContext ruleContext) CompilationHelper.getAggregatingMiddleman( ruleContext, Actions.escapeLabel(ruleContext.getLabel()), filesToBuild); - InstrumentedFilesProvider instrumentedFilesProvider = + InstrumentedFilesInfo instrumentedFilesProvider = InstrumentedFilesCollector.collect( ruleContext, // what do *we* know about whether this is a source file or not @@ -98,10 +98,9 @@ public ConfiguredTarget create(RuleContext ruleContext) .add(RunfilesProvider.class, runfilesProvider) .setFilesToBuild(filesToBuild) .setRunfilesSupport(null, getExecutable(filesToBuild)) - .add(InstrumentedFilesProvider.class, instrumentedFilesProvider) + .addNativeDeclaredProvider(instrumentedFilesProvider) .add(MiddlemanProvider.class, new MiddlemanProvider(middleman)) - .add(FilegroupPathProvider.class, - new FilegroupPathProvider(getFilegroupPath(ruleContext))) + .add(FilegroupPathProvider.class, new FilegroupPathProvider(getFilegroupPath(ruleContext))) .build(); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java index 10d9dd91bf3123..82d6f0b0bee625 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java @@ -37,7 +37,7 @@ import com.google.devtools.build.lib.analysis.test.InstrumentedFilesCollector; import com.google.devtools.build.lib.analysis.test.InstrumentedFilesCollector.InstrumentationSpec; import com.google.devtools.build.lib.analysis.test.InstrumentedFilesCollector.LocalMetadataCollector; -import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider; +import com.google.devtools.build.lib.analysis.test.InstrumentedFilesInfo; 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; @@ -687,8 +687,7 @@ public void addTransitiveInfoProviders( JavaExportsProvider exportsProvider = collectTransitiveExports(); builder - .add( - InstrumentedFilesProvider.class, + .addNativeDeclaredProvider( getInstrumentationFilesProvider(ruleContext, filesToBuild, instrumentationSpec)) .addOutputGroup(OutputGroupInfo.FILES_TO_COMPILE, getFilesToCompile(classJar)); @@ -696,7 +695,7 @@ public void addTransitiveInfoProviders( javaInfoBuilder.addProvider(JavaCompilationInfoProvider.class, compilationInfoProvider); } - private static InstrumentedFilesProvider getInstrumentationFilesProvider( + private static InstrumentedFilesInfo getInstrumentationFilesProvider( RuleContext ruleContext, NestedSet filesToBuild, InstrumentationSpec instrumentationSpec) { diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleBinary.java b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleBinary.java index 12352268f31b8f..6092f97f7f4e34 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleBinary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleBinary.java @@ -36,7 +36,7 @@ import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget.Mode; import com.google.devtools.build.lib.analysis.test.InstrumentedFilesCollector; -import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider; +import com.google.devtools.build.lib.analysis.test.InstrumentedFilesInfo; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.packages.NativeInfo; @@ -344,15 +344,15 @@ private static ConfiguredTarget ruleConfiguredTargetFromProvider( targetBuilder.addNativeDeclaredProvider(objcProvider); } - InstrumentedFilesProvider instrumentedFilesProvider = + InstrumentedFilesInfo instrumentedFilesProvider = InstrumentedFilesCollector.forward(ruleContext, "deps", "bundle_loader"); - return targetBuilder.addProvider(InstrumentedFilesProvider.class, instrumentedFilesProvider) + return targetBuilder + .addNativeDeclaredProvider(instrumentedFilesProvider) .addNativeDeclaredProvider(nativeInfo) .addNativeDeclaredProvider(appleBinaryOutput.getDebugOutputsProvider()) .addOutputGroups(appleBinaryOutput.getOutputGroups()) .build(); - } /** diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java index 87f360835c4e45..15a0441be97877 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java @@ -75,7 +75,7 @@ import com.google.devtools.build.lib.analysis.test.InstrumentedFilesCollector; import com.google.devtools.build.lib.analysis.test.InstrumentedFilesCollector.InstrumentationSpec; import com.google.devtools.build.lib.analysis.test.InstrumentedFilesCollector.LocalMetadataCollector; -import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider; +import com.google.devtools.build.lib.analysis.test.InstrumentedFilesInfo; 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; @@ -255,15 +255,12 @@ public static final FilesToRunProvider libtool(RuleContext ruleContext) { /** * Files which can be instrumented along with the attributes in which they may occur and the - * attributes along which they are propagated from dependencies (via - * {@link InstrumentedFilesProvider}). + * attributes along which they are propagated from dependencies (via {@link + * InstrumentedFilesInfo}). */ private static final InstrumentationSpec INSTRUMENTATION_SPEC = new InstrumentationSpec( - FileTypeSet.of( - ObjcRuleClasses.NON_CPP_SOURCES, - ObjcRuleClasses.CPP_SOURCES, - HEADERS)) + FileTypeSet.of(ObjcRuleClasses.NON_CPP_SOURCES, ObjcRuleClasses.CPP_SOURCES, HEADERS)) .withSourceAttributes("srcs", "non_arc_srcs", "hdrs") .withDependencyAttributes("deps", "data", "binary", "xctest_app"); @@ -877,8 +874,7 @@ public CompilationSupport build() { * @param objectFiles the object files generated by this target * @return an instrumented files provider */ - public InstrumentedFilesProvider getInstrumentedFilesProvider( - ImmutableList objectFiles) { + public InstrumentedFilesInfo getInstrumentedFilesProvider(ImmutableList objectFiles) { return InstrumentedFilesCollector.collect( ruleContext, INSTRUMENTATION_SPEC, diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcLibrary.java index ee393ffeca09bc..76e81f6ccce4f4 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcLibrary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcLibrary.java @@ -22,7 +22,6 @@ import com.google.devtools.build.lib.analysis.RuleConfiguredTargetFactory; import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget.Mode; -import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.rules.cpp.ArtifactCategory; @@ -120,8 +119,7 @@ public ConfiguredTarget create(RuleContext ruleContext) .addNativeDeclaredProvider(common.getObjcProvider()) .addProvider(J2ObjcEntryClassProvider.class, j2ObjcEntryClassProvider) .addProvider(J2ObjcMappingFileProvider.class, j2ObjcMappingFileProvider) - .addProvider( - InstrumentedFilesProvider.class, + .addNativeDeclaredProvider( compilationSupport.getInstrumentedFilesProvider(objectFilesCollector.build())) .addNativeDeclaredProvider( CcInfo.builder() diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PyCommon.java b/src/main/java/com/google/devtools/build/lib/rules/python/PyCommon.java index 314404fbe8f8ff..cd83ea12416c9e 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/python/PyCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/python/PyCommon.java @@ -34,7 +34,6 @@ import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget.Mode; import com.google.devtools.build.lib.analysis.test.InstrumentedFilesCollector; import com.google.devtools.build.lib.analysis.test.InstrumentedFilesCollector.LocalMetadataCollector; -import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider; 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; @@ -163,8 +162,7 @@ public void addCommonTransitiveInfoProviders( NestedSet imports) { builder - .add( - InstrumentedFilesProvider.class, + .addNativeDeclaredProvider( InstrumentedFilesCollector.collect( ruleContext, semantics.getCoverageInstrumentationSpec(), diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java index 22d3093be11290..2edf89d7b9ffe5 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java @@ -92,7 +92,7 @@ import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget; import com.google.devtools.build.lib.analysis.extra.ExtraAction; import com.google.devtools.build.lib.analysis.test.BaselineCoverageAction; -import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider; +import com.google.devtools.build.lib.analysis.test.InstrumentedFilesInfo; import com.google.devtools.build.lib.buildtool.BuildRequestOptions; import com.google.devtools.build.lib.clock.BlazeClock; import com.google.devtools.build.lib.cmdline.Label; @@ -2018,9 +2018,8 @@ public ActionKeyContext getActionKeyContext() { protected Iterable baselineCoverageArtifactBasenames(ConfiguredTarget target) throws Exception { ImmutableList.Builder basenames = ImmutableList.builder(); - for (Artifact baselineCoverage : target - .getProvider(InstrumentedFilesProvider.class) - .getBaselineCoverageArtifacts()) { + for (Artifact baselineCoverage : + target.get(InstrumentedFilesInfo.SKYLARK_CONSTRUCTOR).getBaselineCoverageArtifacts()) { BaselineCoverageAction baselineAction = (BaselineCoverageAction) getGeneratingAction(baselineCoverage); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java index eca984f1a1e1f5..6a2dc70a203834 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java @@ -32,7 +32,7 @@ import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.OutputGroupInfo; import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException; -import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider; +import com.google.devtools.build.lib.analysis.test.InstrumentedFilesInfo; import com.google.devtools.build.lib.analysis.util.AnalysisMock; import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; import com.google.devtools.build.lib.packages.ImplicitOutputsFunction; @@ -613,7 +613,7 @@ public void testCodeCoverage() throws Exception { "cc_library(name = 'x', srcs = ['x.cc'])"); assertThat( ActionsTestUtil.baseArtifactNames( - x.getProvider(InstrumentedFilesProvider.class).getInstrumentationMetadataFiles())) + x.get(InstrumentedFilesInfo.SKYLARK_CONSTRUCTOR).getInstrumentationMetadataFiles())) .containsExactly("x.pic.gcno"); } diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/AppleBinaryTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/AppleBinaryTest.java index 9813e645153888..597579aaa11402 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/AppleBinaryTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/objc/AppleBinaryTest.java @@ -28,7 +28,7 @@ import com.google.devtools.build.lib.analysis.actions.SpawnAction; import com.google.devtools.build.lib.analysis.actions.SymlinkAction; import com.google.devtools.build.lib.analysis.config.CompilationMode; -import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider; +import com.google.devtools.build.lib.analysis.test.InstrumentedFilesInfo; import com.google.devtools.build.lib.cmdline.RepositoryName; import com.google.devtools.build.lib.rules.apple.AppleConfiguration.ConfigurationDistinguisher; import com.google.devtools.build.lib.rules.apple.ApplePlatform; @@ -1301,8 +1301,8 @@ public void testInstrumentedFilesProviderContainsDepsAndBundleLoaderFiles() thro ")"); ConfiguredTarget bundleTarget = getConfiguredTarget("//examples:bundle"); - InstrumentedFilesProvider instrumentedFilesProvider = - bundleTarget.getProvider(InstrumentedFilesProvider.class); + InstrumentedFilesInfo instrumentedFilesProvider = + bundleTarget.get(InstrumentedFilesInfo.SKYLARK_CONSTRUCTOR); assertThat(instrumentedFilesProvider).isNotNull(); assertThat(Artifact.toRootRelativePaths(instrumentedFilesProvider.getInstrumentedFiles())) diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java index 18d959391e16f9..88c6e28e8ec5bc 100644 --- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java +++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java @@ -32,7 +32,7 @@ import com.google.devtools.build.lib.analysis.test.AnalysisFailure; import com.google.devtools.build.lib.analysis.test.AnalysisFailureInfo; import com.google.devtools.build.lib.analysis.test.AnalysisTestResultInfo; -import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider; +import com.google.devtools.build.lib.analysis.test.InstrumentedFilesInfo; import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.collect.nestedset.NestedSet; @@ -675,7 +675,7 @@ public void testInstrumentedFilesProviderWithCodeCoverageDiabled() throws Except ConfiguredTarget target = getConfiguredTarget("//test/skylark:cr"); assertThat(target.getLabel().toString()).isEqualTo("//test/skylark:cr"); - InstrumentedFilesProvider provider = target.getProvider(InstrumentedFilesProvider.class); + InstrumentedFilesInfo provider = target.get(InstrumentedFilesInfo.SKYLARK_CONSTRUCTOR); assertWithMessage("InstrumentedFilesProvider should be set.").that(provider).isNotNull(); assertThat(ActionsTestUtil.baseArtifactNames(provider.getInstrumentedFiles())).isEmpty(); } @@ -707,7 +707,7 @@ public void testInstrumentedFilesProviderWithCodeCoverageEnabled() throws Except ConfiguredTarget target = getConfiguredTarget("//test/skylark:cr"); assertThat(target.getLabel().toString()).isEqualTo("//test/skylark:cr"); - InstrumentedFilesProvider provider = target.getProvider(InstrumentedFilesProvider.class); + InstrumentedFilesInfo provider = target.get(InstrumentedFilesInfo.SKYLARK_CONSTRUCTOR); assertWithMessage("InstrumentedFilesProvider should be set.").that(provider).isNotNull(); assertThat(ActionsTestUtil.baseArtifactNames(provider.getInstrumentedFiles())) .containsExactly("a.txt", "A.java");