Skip to content

Commit

Permalink
Expose metadata_files parameter in coverage_common.instrumented_files…
Browse files Browse the repository at this point in the history
…_info

Allows all rules to provide additional metadata files to the
InstrumentedFilesInfo provider.

It was always a little odd that the metadata_files attribute on the provider
was exposed, but there was no way of populating it from Starlark.

The other parameters are still considered too tied up with internal details at
the moment to be exposed at this time.

RELNOTES: coverage_common.instrumented_files_info now has a metadata_files argument
PiperOrigin-RevId: 545391150
Change-Id: I3febdaf23c82d60c32b241a3935da27fd086fb7a
  • Loading branch information
c-mita authored and copybara-github committed Jul 4, 2023
1 parent 92d6f22 commit ef54ef5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,9 @@ public InstrumentedFilesInfoApi instrumentedFilesInfo(
// Should have been verified by Starlark before this function is called
throw new IllegalStateException();
}
if (!supportFilesBuilder.isEmpty() || !environmentPairs.isEmpty()) {
BuiltinRestriction.throwIfNotBuiltinUsage(thread);
}
if (!metadataFiles.isEmpty() || !reportedToActualSources.isEmpty()) {
if (!supportFilesBuilder.isEmpty()
|| !reportedToActualSources.isEmpty()
|| !environmentPairs.isEmpty()) {
BuiltinRestriction.throwIfNotBuiltinUsage(thread);
}
return createInstrumentedFilesInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,11 @@ public interface CoverageCommonApi<
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,
documented = false,
defaultValue = "[]",
allowedTypes = {
@ParamType(type = Sequence.class, generic1 = FileApi.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,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 @@ -967,6 +969,7 @@ public void testInstrumentedFilesInfo_coverageEnabled() throws Exception {
// Missing attrs are ignored
" 'missing_dep_attr',",
" ],",
" metadata_files = [metadata],",
" ),",
" ]",
"",
Expand Down Expand Up @@ -1033,7 +1036,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 ef54ef5

Please sign in to comment.