diff --git a/src/main/java/com/google/devtools/build/lib/actions/AbstractAction.java b/src/main/java/com/google/devtools/build/lib/actions/AbstractAction.java index 262754415cf3cb..e76a72dcfedf13 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/AbstractAction.java +++ b/src/main/java/com/google/devtools/build/lib/actions/AbstractAction.java @@ -27,6 +27,7 @@ import com.google.devtools.build.lib.actions.extra.ExtraActionInfo; import com.google.devtools.build.lib.analysis.platform.PlatformInfo; import com.google.devtools.build.lib.cmdline.Label; +import com.google.devtools.build.lib.cmdline.RepositoryMapping; import com.google.devtools.build.lib.collect.nestedset.Depset; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; @@ -363,14 +364,47 @@ public boolean showsOutputUnconditionally() { @Nullable @Override public final String getProgressMessage() { + return getProgressMessageChecked(null); + } + + @Nullable + @Override + public final String getProgressMessage(RepositoryMapping mainRepositoryMapping) { + Preconditions.checkNotNull(mainRepositoryMapping); + return getProgressMessageChecked(mainRepositoryMapping); + } + + private String getProgressMessageChecked(@Nullable RepositoryMapping mainRepositoryMapping) { String message = getRawProgressMessage(); if (message == null) { return null; } + message = replaceProgressMessagePlaceholders(message, mainRepositoryMapping); String additionalInfo = getOwner().getAdditionalProgressInfo(); return additionalInfo == null ? message : message + " [" + additionalInfo + "]"; } + private String replaceProgressMessagePlaceholders( + String progressMessage, @Nullable RepositoryMapping mainRepositoryMapping) { + if (progressMessage.contains("%{label}") && getOwner().getLabel() != null) { + String labelString; + if (mainRepositoryMapping != null) { + labelString = getOwner().getLabel().getDisplayForm(mainRepositoryMapping); + } else { + labelString = getOwner().getLabel().toString(); + } + progressMessage = progressMessage.replace("%{label}", labelString); + } + if (progressMessage.contains("%{output}") && getPrimaryOutput() != null) { + progressMessage = + progressMessage.replace("%{output}", getPrimaryOutput().getExecPathString()); + } + if (progressMessage.contains("%{input}") && getPrimaryInput() != null) { + progressMessage = progressMessage.replace("%{input}", getPrimaryInput().getExecPathString()); + } + return progressMessage; + } + /** * Returns a progress message string that is specific for this action. This is then annotated with * additional information, currently the string '[for tool]' for actions in the tool diff --git a/src/main/java/com/google/devtools/build/lib/actions/ActionExecutionMetadata.java b/src/main/java/com/google/devtools/build/lib/actions/ActionExecutionMetadata.java index 338fb06993fdbc..4d21092df79b82 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/ActionExecutionMetadata.java +++ b/src/main/java/com/google/devtools/build/lib/actions/ActionExecutionMetadata.java @@ -13,6 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.actions; +import com.google.devtools.build.lib.cmdline.RepositoryMapping; import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe; import javax.annotation.Nullable; @@ -33,6 +34,19 @@ public interface ActionExecutionMetadata extends ActionAnalysisMetadata { @Nullable String getProgressMessage(); + /** + * A variant of {@link #getProgressMessage} that additionally takes the {@link RepositoryMapping} + * of the main repository, which can be used by the implementation to emit labels with apparent + * instead of canonical repository names. A return value of {@code null} indicates no message + * should be reported. + * + *

The default implementation simply returns the result of {@link #getProgressMessage}. + */ + @Nullable + default String getProgressMessage(RepositoryMapping mainRepositoryMapping) { + return getProgressMessage(); + } + /** * Returns a human-readable description of the inputs to {@link #getKey(ActionKeyContext)}. Used * in the output from '--explain', and in error messages for '--check_up_to_date' and diff --git a/src/main/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseCompleteEvent.java b/src/main/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseCompleteEvent.java index aad9f721f1ba05..f40f7a2ceb5aae 100644 --- a/src/main/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseCompleteEvent.java +++ b/src/main/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseCompleteEvent.java @@ -16,6 +16,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.cmdline.Label; +import com.google.devtools.build.lib.cmdline.RepositoryMapping; import com.google.devtools.build.lib.events.ExtendedEventHandler; /** @@ -24,6 +25,7 @@ public final class LoadingPhaseCompleteEvent implements ExtendedEventHandler.Postable { private final ImmutableSet