Skip to content

Commit

Permalink
Describe failed action sources in more detail.
Browse files Browse the repository at this point in the history
Specifically, some actions are registered by aspects, so mention the aspects when `--verbose_failures` is mentioned.

PiperOrigin-RevId: 684530757
Change-Id: I7b74fcfccc92ce686fd9e078592d1ce31d799c41
  • Loading branch information
katre authored and copybara-github committed Oct 10, 2024
1 parent ed37f39 commit b042810
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue.RunfileSymlinksMode;
import com.google.devtools.build.lib.bugreport.BugReporter;
import com.google.devtools.build.lib.clock.Clock;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventKind;
Expand Down Expand Up @@ -463,7 +462,7 @@ public void maybeReportSubcommand(Spawn spawn) {
if (owner == null) {
reason.append(spawn.getResourceOwner().prettyPrint());
} else {
reason.append(Label.print(owner.getLabel()));
reason.append(owner.getDescription());
reason.append(" [");
reason.append(spawn.getResourceOwner().prettyPrint());
reason.append(", configuration: ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// limitations under the License.
package com.google.devtools.build.lib.actions;

import static java.util.stream.Collectors.joining;

import com.google.auto.value.AutoValue;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -99,6 +101,27 @@ public static ActionOwner createDummy(
execProperties);
}

@Nullable
public String getDescription() {
Label label = getLabel();
if (label == null) {
return null;
}
String targetDescription = "target " + label;

ImmutableList<AspectDescriptor> aspectDescriptors = getAspectDescriptors();
if (aspectDescriptors.isEmpty()) {
return targetDescription;
}

String aspectNames =
aspectDescriptors.stream().map(AspectDescriptor::getDescription).collect(joining(", "));

return String.format(
"aspect%s [%s] on %s",
aspectDescriptors.size() >= 1 ? "s" : "", aspectNames, targetDescription);
}

/**
* Returns the label for this {@link ActionOwner}, or null if the {@link #SYSTEM_ACTION_OWNER}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ default String getConfigurationChecksum() {
}

@Override
@Nullable
default String getTargetDescription() {
return getResourceOwner().getOwner().getDescription();
}

@Nullable
default Label getTargetLabel() {
return getResourceOwner().getOwner().getLabel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ static String describeCommandFailure(
Map<String, String> env,
@Nullable String cwd,
@Nullable String configurationChecksum,
@Nullable Label targetLabel,
@Nullable String targetDescription,
@Nullable Label executionPlatformLabel) {

String commandName = commandLineElements.iterator().next();
Expand All @@ -166,8 +166,8 @@ static String describeCommandFailure(
output.append("error executing ");
output.append(mnemonic);
output.append(" command ");
if (targetLabel != null) {
output.append("(from target ").append(targetLabel).append(") ");
if (targetDescription != null) {
output.append("(from ").append(targetDescription).append(") ");
}
if (verbose) {
output.append("\n ");
Expand All @@ -194,7 +194,7 @@ public static String describeCommandFailure(
command.getEnvironment(),
cwd,
command.getConfigurationChecksum(),
command.getTargetLabel(),
command.getTargetDescription(),
command.getExecutionPlatformLabel());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public interface DescribableExecutionUnit {

@Nullable
default Label getTargetLabel() {
default String getTargetDescription() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void describeCommandFailure() throws Exception {
env,
cwd,
"cfg12345",
target,
"target " + target,
executionPlatform.label());
assertThat(message)
.isEqualTo(
Expand Down Expand Up @@ -79,7 +79,7 @@ public void describeCommandFailure_verbose() throws Exception {
env,
cwd,
"cfg12345",
target,
"target " + target,
executionPlatform.label());
assertThat(message)
.isEqualTo(
Expand Down Expand Up @@ -116,7 +116,7 @@ public void describeCommandFailure_longMessage() throws Exception {
env,
cwd,
"cfg12345",
target,
"target " + target,
executionPlatform.label());
assertThat(message)
.isEqualTo(
Expand Down Expand Up @@ -152,7 +152,7 @@ public void describeCommandFailure_longMessage_verbose() throws Exception {
env,
cwd,
"cfg12345",
target,
"target " + target,
executionPlatform.label());
assertThat(message)
.isEqualTo(
Expand Down Expand Up @@ -190,7 +190,7 @@ public void describeCommandFailure_singleSkippedArgument() throws Exception {
env,
cwd,
"cfg12345",
target,
"target " + target,
executionPlatform.label());
assertThat(message)
.isEqualTo(
Expand Down

0 comments on commit b042810

Please sign in to comment.