Skip to content

Commit 01079b8

Browse files
michaeledgarcopybara-github
authored andcommitted
Set default value for --experimental_build_event_output_group_mode to inline
coverage artifacts in `TargetComplete` events. RELNOTES: By default, coverage artifacts will be reported inline in the `TargetComplete` event. To disable this behavior, pass `--experimental_build_event_output_group_mode=baseline.lcov=named_set_of_files_only`. PiperOrigin-RevId: 671442846 Change-Id: Id91e6c53cdc04d527b45a8c10bee833cbfc64b63
1 parent 84aa0e0 commit 01079b8

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,8 +594,8 @@ private static OutputGroup makeOutputGroupProto(
594594
OutputGroupFileMode fileMode = converters.getFileModeForOutputGroup(outputGroup);
595595
if (fileMode == OutputGroupFileMode.NAMED_SET_OF_FILES_ONLY
596596
|| fileMode == OutputGroupFileMode.BOTH) {
597-
ArtifactGroupNamer namer2 = converters.artifactGroupNamer();
598-
builder.addFileSets(namer2.apply(artifactsToReport.get().toNode()));
597+
ArtifactGroupNamer namer = converters.artifactGroupNamer();
598+
builder.addFileSets(namer.apply(artifactsToReport.get().toNode()));
599599
}
600600
if (fileMode == OutputGroupFileMode.INLINE_ONLY || fileMode == OutputGroupFileMode.BOTH) {
601601
addFilesDirectlyToProtoField(

src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventProtocolOptions.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,16 @@ public interface OutputGroupFileModes {
163163
* Collects the values in {@link #outputGroupFileModes} into a map and returns a {@link
164164
* OutputGroupFileModes} backed by that map and defaulting to {@link
165165
* OutputGroupFileMode.NAMED_SET_OF_FILES_ONLY} for out groups not in that map.
166+
*
167+
* <p>This also implements the default value of the {@code
168+
* --experimental_build_event_output_group_mode} option, which as an {@code allowMultiple} option
169+
* cannot specify a default value. The default value sets the mode for coverage artifacts to BOTH:
170+
* {@code --experimental_build_event_output_group_mode=baseline.lcov=both}.
166171
*/
167172
public OutputGroupFileModes getOutputGroupFileModesMapping() {
168173
var modeMap =
169174
ImmutableMap.<String, OutputGroupFileMode>builder()
175+
.put(TestFileNameConstants.BASELINE_COVERAGE, OutputGroupFileMode.BOTH)
170176
.putAll(outputGroupFileModes)
171177
.buildKeepingLast();
172178
return (outputGroup) ->
@@ -185,6 +191,7 @@ public OutputGroupFileModes getOutputGroupFileModesMapping() {
185191
+ " BEP events. Values are an assignment of an output group name to one of"
186192
+ " 'NAMED_SET_OF_FILES_ONLY', 'INLINE_ONLY', or 'BOTH'. The default value is"
187193
+ " 'NAMED_SET_OF_FILES_ONLY'. If an output group is repeated, the final value to"
188-
+ " appear is used.")
194+
+ " appear is used. The default value sets the mode for coverage artifacts to BOTH: "
195+
+ "--experimental_build_event_output_group_mode=baseline.lcov=both")
189196
public List<Map.Entry<String, OutputGroupFileMode>> outputGroupFileModes;
190197
}

src/test/shell/bazel/bazel_coverage_cc_test_gcc.sh

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ function test_cc_test_coverage_gcov() {
7878
echo "Skipping test." && return
7979
fi
8080
setup_a_cc_lib_and_t_cc_test
81-
81+
BEP=bep.txt
8282
bazel coverage --test_output=all \
83-
--build_event_text_file=bep.txt //:t &>"$TEST_log" \
83+
--build_event_text_file="${BEP}" //:t &>"$TEST_log" \
8484
|| fail "Coverage for //:t failed"
8585

8686
local coverage_file_path="$( get_coverage_file_path_from_test_log )"
@@ -109,12 +109,22 @@ end_of_record"
109109

110110
# Verify that this is also true for cached coverage actions.
111111
bazel coverage --test_output=all \
112-
--build_event_text_file=bep.txt //:t \
112+
--build_event_text_file="${BEP}" //:t \
113113
&>"$TEST_log" || fail "Coverage for //:t failed"
114114
expect_log '//:t.*cached'
115115
# Verify the files are reported correctly in the build event protocol.
116-
assert_contains 'name: "test.lcov"' bep.txt
117-
assert_contains 'name: "baseline.lcov"' bep.txt
116+
assert_contains 'name: "test.lcov"' "${BEP}"
117+
assert_contains 'name: "baseline.lcov"' "${BEP}"
118+
# Assert coverage output is reported in the right proto fields
119+
grep 'name: "baseline.lcov"' -B1 "${BEP}" | grep -q 'output_group'\
120+
|| fail "File 'baseline.lcov' missing in output_group!"
121+
grep 'name: "t/baseline_coverage.dat"' -B1 "${BEP}"\
122+
| grep -q 'inline_files'\
123+
|| fail "File 'baseline_coverage.dat' missing in inline_files!"
124+
grep 'name: "baseline.lcov"' -B1 "${BEP}" | grep -q 'important_output'\
125+
|| fail "File 'baseline.lcov' missing in important_output!"
126+
grep 'name: "test.lcov"' -B1 "${BEP}" | grep -q 'test_action_output'\
127+
|| fail "File 'test.lcov' missing in test_action_output!"
118128
}
119129

120130
# TODO(#6254): Enable this test when #6254 is fixed.

0 commit comments

Comments
 (0)