diff --git a/src/main/java/com/google/devtools/build/lib/analysis/starlark/UnresolvedSymlinkAction.java b/src/main/java/com/google/devtools/build/lib/analysis/starlark/UnresolvedSymlinkAction.java index 95910b3413c29d..11a54bfad32735 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/starlark/UnresolvedSymlinkAction.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/starlark/UnresolvedSymlinkAction.java @@ -103,6 +103,10 @@ protected String getRawProgressMessage() { return progressMessage; } + public PathFragment getTarget() { + return target; + } + private static DetailedExitCode createDetailedExitCode(String message, Code detailedCode) { return DetailedExitCode.of( FailureDetail.newBuilder() diff --git a/src/main/java/com/google/devtools/build/lib/query2/aquery/ActionGraphTextOutputFormatterCallback.java b/src/main/java/com/google/devtools/build/lib/query2/aquery/ActionGraphTextOutputFormatterCallback.java index cb7763a5a3cb4f..e87ad3fec7f35a 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/aquery/ActionGraphTextOutputFormatterCallback.java +++ b/src/main/java/com/google/devtools/build/lib/query2/aquery/ActionGraphTextOutputFormatterCallback.java @@ -35,6 +35,7 @@ import com.google.devtools.build.lib.analysis.actions.ParameterFileWriteAction; import com.google.devtools.build.lib.analysis.actions.Substitution; import com.google.devtools.build.lib.analysis.actions.TemplateExpansionAction; +import com.google.devtools.build.lib.analysis.starlark.UnresolvedSymlinkAction; import com.google.devtools.build.lib.buildeventstream.BuildEvent; import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos; import com.google.devtools.build.lib.cmdline.RepositoryMapping; @@ -345,6 +346,13 @@ private void writeAction(ActionAnalysisMetadata action, PrintStream printStream) .append("]\n"); } + if (action instanceof UnresolvedSymlinkAction) { + stringBuilder + .append(" UnresolvedSymlinkTarget: ") + .append(((UnresolvedSymlinkAction) action).getTarget()) + .append("\n"); + } + stringBuilder.append('\n'); printStream.write(stringBuilder.toString().getBytes(UTF_8)); diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/actiongraph/v2/ActionGraphDump.java b/src/main/java/com/google/devtools/build/lib/skyframe/actiongraph/v2/ActionGraphDump.java index 7e80cc27864339..0dc5c0be9322bf 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/actiongraph/v2/ActionGraphDump.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/actiongraph/v2/ActionGraphDump.java @@ -36,6 +36,7 @@ import com.google.devtools.build.lib.analysis.actions.TemplateExpansionAction; import com.google.devtools.build.lib.analysis.actions.TemplateExpansionException; import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget; +import com.google.devtools.build.lib.analysis.starlark.UnresolvedSymlinkAction; import com.google.devtools.build.lib.buildeventstream.BuildEvent; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.events.ExtendedEventHandler; @@ -201,6 +202,11 @@ private void dumpSingleAction(ConfiguredTarget configuredTarget, ActionAnalysisM actionBuilder.setFileContents(contents); } + if (action instanceof UnresolvedSymlinkAction) { + actionBuilder.setUnresolvedSymlinkTarget( + ((UnresolvedSymlinkAction) action).getTarget().toString()); + } + // Include the content of param files in output. if (includeParamFiles) { // Assumption: if an Action takes a params file as an input, it will be used diff --git a/src/main/protobuf/analysis_v2.proto b/src/main/protobuf/analysis_v2.proto index d3ae80b04f19dc..cfe4d76797baca 100644 --- a/src/main/protobuf/analysis_v2.proto +++ b/src/main/protobuf/analysis_v2.proto @@ -116,6 +116,10 @@ message Action { // The contents of the file for the actions.write() action // (guarded by the --include_file_write_contents flag). string file_contents = 17; + + // The target of the symlink created by UnresolvedSymlink actions. + // For regular Symlink actions, the target is represented as an input. + string unresolved_symlink_target = 18; } // Represents a single target (without configuration information) that is diff --git a/src/test/shell/integration/aquery_test.sh b/src/test/shell/integration/aquery_test.sh index 0ebf8cb8739653..3e328b31c0e0ca 100755 --- a/src/test/shell/integration/aquery_test.sh +++ b/src/test/shell/integration/aquery_test.sh @@ -1768,6 +1768,46 @@ EOF fi } +function test_unresolved_symlinks() { + local pkg="${FUNCNAME[0]}" + mkdir -p "$pkg" || fail "mkdir -p $pkg" + touch "$pkg/foo.sh" + cat > "$pkg/unresolved_symlink.bzl" <<'EOF' +def _impl(ctx): + out = ctx.actions.declare_symlink(ctx.label.name) + ctx.actions.symlink( + output = out, + target_path = ctx.attr.path + ) + return [ + DefaultInfo(files = depset([out])) + ] +unresolved_symlink = rule( + implementation = _impl, + attrs = { + "path": attr.string(), + }, +) +EOF + cat > "$pkg/BUILD" <<'EOF' +load(":unresolved_symlink.bzl", "unresolved_symlink") +unresolved_symlink( + name = "foo", + path = "bar/baz.txt", +) +EOF + bazel aquery --output=textproto \ + "//$pkg:foo" >output 2> "$TEST_log" || fail "Expected success" + cat output >> "$TEST_log" + assert_contains "^unresolved_symlink_target:.*bar/baz.txt" output + + bazel aquery --output=text "//$pkg:foo" | \ + sed -nr '/Mnemonic: UnresolvedSymlink/,/^ *$/p' >output \ + 2> "$TEST_log" || fail "Expected success" + cat output >> "$TEST_log" + assert_contains "^ *UnresolvedSymlinkTarget:.*bar/baz.txt" output +} + function test_does_not_fail_horribly_with_file() { rm -rf peach mkdir -p peach