Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.3.0] Expose metadata_files parameter in coverage_common.instrumented_files_info #18838

Merged
merged 2 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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