Skip to content

Commit

Permalink
Add undeclared outputs annotations file in length-delimited proto for…
Browse files Browse the repository at this point in the history
…mat to bazel declared outputs

RELNOTES: Add support to length-delimited protos as undeclared output annotations []
PiperOrigin-RevId: 398115317
  • Loading branch information
Googler authored and copybara-github committed Sep 21, 2021
1 parent 11e55dc commit de0c6bd
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion site/docs/test-encyclopedia.html
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ <h2 id="initial-conditions">Initial conditions</h2>
<tr><td><code>TEST_WORKSPACE</code></td><td>the local repository's workspace name</td><td>optional</td></tr>
<tr><td><code>TEST_UNDECLARED_OUTPUTS_DIR</code></td><td>absolute path to a private writable directory (used to write undeclared test outputs)</td><td>optional</td></tr>

<tr><td><code>TEST_UNDECLARED_OUTPUTS_ANNOTATIONS_DIR</code></td><td>absolute path to a private writable directory (used to write undeclared test output annotation .part files).
<tr><td><code>TEST_UNDECLARED_OUTPUTS_ANNOTATIONS_DIR</code></td><td>absolute path to a private writable directory (used to write undeclared test output annotation .part and .pb files).
</td><td>optional</td></tr>

<tr><td><code>TEST_WARNINGS_OUTPUT_FILE</code></td><td>absolute path to a private file in a writable directory (used to write test target warnings)</td><td>optional</td></tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public class TestRunnerAction extends AbstractAction
private final PathFragment undeclaredOutputsAnnotationsDir;
private final PathFragment undeclaredOutputsManifestPath;
private final PathFragment undeclaredOutputsAnnotationsPath;
private final PathFragment undeclaredOutputsAnnotationsPbPath;
private final PathFragment xmlOutputPath;
@Nullable private final PathFragment testShard;
private final PathFragment testExitSafe;
Expand Down Expand Up @@ -248,6 +249,8 @@ private static ImmutableSet<Artifact> nonNullAsSet(Artifact... artifacts) {
this.undeclaredOutputsAnnotationsDir = baseDir.getChild("test.outputs_manifest");
this.undeclaredOutputsManifestPath = undeclaredOutputsAnnotationsDir.getChild("MANIFEST");
this.undeclaredOutputsAnnotationsPath = undeclaredOutputsAnnotationsDir.getChild("ANNOTATIONS");
this.undeclaredOutputsAnnotationsPbPath =
undeclaredOutputsAnnotationsDir.getChild("ANNOTATIONS.pb");
this.testInfrastructureFailure = baseDir.getChild("test.infrastructure_failure");
this.workspaceName = workspaceName;

Expand Down Expand Up @@ -339,6 +342,7 @@ public List<ActionInput> getSpawnOutputs() {
outputs.add(ActionInputHelper.fromPath(getUndeclaredOutputsZipPath()));
outputs.add(ActionInputHelper.fromPath(getUndeclaredOutputsManifestPath()));
outputs.add(ActionInputHelper.fromPath(getUndeclaredOutputsAnnotationsPath()));
outputs.add(ActionInputHelper.fromPath(getUndeclaredOutputsAnnotationsPbPath()));
if (isCoverageMode()) {
if (!splitCoveragePostProcessing) {
outputs.add(coverageData);
Expand Down Expand Up @@ -397,6 +401,12 @@ public ImmutableList<Pair<String, Path>> getTestOutputsMapping(
TestFileNameConstants.UNDECLARED_OUTPUTS_ANNOTATIONS,
resolvedPaths.getUndeclaredOutputsAnnotationsPath()));
}
if (resolvedPaths.getUndeclaredOutputsAnnotationsPbPath().exists()) {
builder.add(
Pair.of(
TestFileNameConstants.UNDECLARED_OUTPUTS_ANNOTATIONS_PB,
resolvedPaths.getUndeclaredOutputsAnnotationsPbPath()));
}
if (resolvedPaths.getUnusedRunfilesLogPath().exists()) {
builder.add(
Pair.of(
Expand Down Expand Up @@ -735,6 +745,11 @@ public PathFragment getUndeclaredOutputsAnnotationsPath() {
return undeclaredOutputsAnnotationsPath;
}

/** Returns path to the undeclared output annotations file. */
public PathFragment getUndeclaredOutputsAnnotationsPbPath() {
return undeclaredOutputsAnnotationsPbPath;
}

public PathFragment getTestShard() {
return testShard;
}
Expand Down Expand Up @@ -1040,6 +1055,11 @@ public Path getUndeclaredOutputsAnnotationsPath() {
return getPath(undeclaredOutputsAnnotationsPath);
}

/** Returns path to the undeclared output annotations pb file. */
public Path getUndeclaredOutputsAnnotationsPbPath() {
return getPath(undeclaredOutputsAnnotationsPbPath);
}

@Nullable
public Path getTestShard() {
return testShard == null ? null : getPath(testShard);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class TestFileNameConstants {
public static final String TEST_WARNINGS = "test.warnings";
public static final String TEST_XML = "test.xml";
public static final String UNDECLARED_OUTPUTS_ANNOTATIONS = "test.outputs_manifest__ANNOTATIONS";
public static final String UNDECLARED_OUTPUTS_ANNOTATIONS_PB =
"test.outputs_manifest__ANNOTATIONS.pb";
public static final String UNDECLARED_OUTPUTS_MANIFEST = "test.outputs_manifest__MANIFEST";
public static final String UNDECLARED_OUTPUTS_ZIP = "test.outputs__outputs.zip";
public static final String UNUSED_RUNFILES_LOG = "test.unused_runfiles_log";
Expand Down
39 changes: 39 additions & 0 deletions src/test/shell/integration/build_event_stream_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,45 @@ function test_test_attempts() {
expect_not_log 'name:.*SUCCESS'
}

function test_undeclared_output_annotations() {
mkdir -p undeclared_annotations || fail "mkdir undeclared_annotations failed"
cat > undeclared_annotations/undeclared_annotations_test.sh <<'EOF'
#!/bin/sh
base=$TEST_UNDECLARED_OUTPUTS_ANNOTATIONS_DIR
[ -d $base ] || exit 2
[ ! -e $base/1.txt ]] | exit 2
echo "some information" > $base/something.part
EOF
chmod u+x undeclared_annotations/undeclared_annotations_test.sh
echo "sh_test(name='bep_undeclared_test', srcs=['undeclared_annotations_test.sh'], tags=['local'])" \
> undeclared_annotations/BUILD
bazel test --build_event_text_file="${TEST_log}" //undeclared_annotations:bep_undeclared_test || fail "Expected success"
expect_log 'test_result'
expect_log 'test.outputs_manifest__ANNOTATIONS'
expect_not_log 'test.outputs_manifest__ANNOTATIONS.pb'
}

function test_undeclared_output_annotations_pb() {
mkdir -p undeclared_annotations || fail "mkdir undeclared_annotations failed"
cat > undeclared_annotations/undeclared_annotations_test.sh <<'EOF'
#!/bin/sh
base=$TEST_UNDECLARED_OUTPUTS_ANNOTATIONS_DIR
[ -d $base ] || exit 2
[ ! -e $base/1.txt ]] | exit 2
echo "some information" > $base/something.pb
EOF
chmod u+x undeclared_annotations/undeclared_annotations_test.sh
echo "sh_test(name='bep_undeclared_pb_test', srcs=['undeclared_annotations_test.sh'], tags=['local'])" \
> undeclared_annotations/BUILD
bazel test --build_event_text_file="${TEST_log}" //undeclared_annotations:bep_undeclared_pb_test || fail "Expected success"
expect_log 'test_result'
expect_log 'test.outputs_manifest__ANNOTATIONS.pb'
}

function test_test_runtime() {
bazel test --build_event_text_file=$TEST_log pkg:slow \
|| fail "bazel test failed"
Expand Down
5 changes: 5 additions & 0 deletions tools/test/test-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,11 @@ if [[ -n "$TEST_UNDECLARED_OUTPUTS_ANNOTATIONS" && \
shopt -s failglob
cat "$TEST_UNDECLARED_OUTPUTS_ANNOTATIONS_DIR"/*.part > "$TEST_UNDECLARED_OUTPUTS_ANNOTATIONS"
) 2> /dev/null
(
# length-delimited proto files
shopt -s failglob
cat $TEST_UNDECLARED_OUTPUTS_ANNOTATIONS_DIR/*.pb > "${TEST_UNDECLARED_OUTPUTS_ANNOTATIONS}.pb"
) 2> /dev/null
fi

# Zip up undeclared outputs.
Expand Down

0 comments on commit de0c6bd

Please sign in to comment.