Skip to content

Commit

Permalink
[6.3.0] Expose metadata_files parameter in coverage_common.instrument…
Browse files Browse the repository at this point in the history
…ed_files_info (#18838)

* Add internal metadata_files parameter to instrumented_files_info(..)

Partial cherry-pick of c449a82 onto the 6.3.0 branch.

* Expose metadata_files parameter in coverage_common.instrumented_files_info

Cherry-pick of ef54ef5.

RELNOTES: coverage_common.instrumented_files_info now has a metadata_files argument
  • Loading branch information
c-mita authored Jul 5, 2023
1 parent ce5c491 commit 601f909
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public InstrumentedFilesInfoApi instrumentedFilesInfo(
Object supportFiles, // Depset or Sequence of <Artifact>
Dict<?, ?> environment, // <String, String>
Object extensions,
Sequence<?> metadataFiles, // Sequence<Artifact>
StarlarkThread thread)
throws EvalException, TypeException {
List<String> extensionsList =
Expand Down Expand Up @@ -81,7 +82,8 @@ public InstrumentedFilesInfoApi instrumentedFilesInfo(
Sequence.cast(dependencyAttributes, String.class, "dependency_attributes"),
supportFilesBuilder.build(),
NestedSetBuilder.wrap(Order.COMPILE_ORDER, environmentPairs),
extensionsList);
extensionsList,
Sequence.cast(metadataFiles, Artifact.class, "metadata_files"));
}

/**
Expand Down Expand Up @@ -109,7 +111,8 @@ public static InstrumentedFilesInfo createInstrumentedFilesInfo(
dependencyAttributes,
NestedSetBuilder.emptySet(Order.STABLE_ORDER),
NestedSetBuilder.emptySet(Order.STABLE_ORDER),
extensions);
extensions,
null);
}

private static InstrumentedFilesInfo createInstrumentedFilesInfo(
Expand All @@ -118,7 +121,8 @@ private static InstrumentedFilesInfo createInstrumentedFilesInfo(
List<String> dependencyAttributes,
NestedSet<Artifact> supportFiles,
NestedSet<Pair<String, String>> environment,
@Nullable List<String> extensions) {
@Nullable List<String> extensions,
@Nullable List<Artifact> metadataFiles) {
FileTypeSet fileTypeSet = FileTypeSet.ANY_FILE;
if (extensions != null) {
if (extensions.isEmpty()) {
Expand All @@ -137,11 +141,12 @@ private static InstrumentedFilesInfo createInstrumentedFilesInfo(
ruleContext,
instrumentationSpec,
InstrumentedFilesCollector.NO_METADATA_COLLECTOR,
/* rootFiles = */ ImmutableList.of(),
/* coverageSupportFiles = */ supportFiles,
/* coverageEnvironment = */ environment,
/* withBaselineCoverage = */ !TargetUtils.isTestRule(ruleContext.getTarget()),
/* reportedToActualSources= */ NestedSetBuilder.create(Order.STABLE_ORDER));
/* rootFiles= */ ImmutableList.of(),
/* coverageSupportFiles= */ supportFiles,
/* coverageEnvironment= */ environment,
/* withBaselineCoverage= */ !TargetUtils.isTestRule(ruleContext.getTarget()),
/* reportedToActualSources= */ NestedSetBuilder.create(Order.STABLE_ORDER),
/* additionalMetadata= */ metadataFiles);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ public interface CoverageCommonApi<
positional = false,
named = true,
defaultValue = "None"),
@Param(
name = "metadata_files",
doc =
"Additional files required to generate coverage LCOV files after code execution."
+ " e.g. .gcno files for C++.",
named = true,
positional = false,
defaultValue = "[]",
allowedTypes = {
@ParamType(type = Sequence.class, generic1 = FileApi.class),
})
},
useStarlarkThread = true)
InstrumentedFilesInfoApi instrumentedFilesInfo(
Expand All @@ -102,6 +113,7 @@ InstrumentedFilesInfoApi instrumentedFilesInfo(
Object supportFiles, // Sequence or Depset of <FileApi> expected
Dict<?, ?> environment, // <String, String>
Object extensions,
Sequence<?> metadataFiles,
StarlarkThread thread)
throws EvalException, TypeException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,8 @@ public void testInstrumentedFilesInfo_coverageEnabled() throws Exception {
"load('//myinfo:myinfo.bzl', 'MyInfo')",
"",
"def custom_rule_impl(ctx):",
" metadata = ctx.actions.declare_file(ctx.label.name + '.metadata')",
" ctx.actions.write(metadata, '')",
" return [",
" coverage_common.instrumented_files_info(",
" ctx,",
Expand All @@ -966,6 +968,7 @@ public void testInstrumentedFilesInfo_coverageEnabled() throws Exception {
// Missing attrs are ignored
" 'missing_dep_attr',",
" ],",
" metadata_files = [metadata],",
" ),",
" ]",
"",
Expand Down Expand Up @@ -1032,7 +1035,7 @@ public void testInstrumentedFilesInfo_coverageEnabled() throws Exception {
assertThat(
ActionsTestUtil.baseArtifactNames(
((Depset) myInfo.getValue("metadata_files")).getSet(Artifact.class)))
.containsExactly("label_dep.gcno", "label_list_dep.gcno", "dict_dep.gcno");
.containsExactly("label_dep.gcno", "label_list_dep.gcno", "dict_dep.gcno", "cr.metadata");
ConfiguredTarget customRule = getConfiguredTarget("//test/starlark:cr");
assertThat(
ActionsTestUtil.baseArtifactNames(
Expand Down

0 comments on commit 601f909

Please sign in to comment.