Skip to content

Commit

Permalink
Uniquify results of FilesOutputFormatterCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed May 23, 2022
1 parent 7a95bb0 commit f37b578
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class BuildOutputFormatterCallback extends CqueryThreadsafeCallback {
OutputStream out,
SkyframeExecutor skyframeExecutor,
TargetAccessor<KeyedConfiguredTarget> accessor) {
super(eventHandler, options, out, skyframeExecutor, accessor);
super(eventHandler, options, out, skyframeExecutor, accessor, /*uniquifyResults=*/false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@


import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue;
import com.google.devtools.build.lib.events.ExtendedEventHandler;
import com.google.devtools.build.lib.query2.NamedThreadSafeOutputFormatterCallback;
Expand Down Expand Up @@ -55,14 +56,16 @@ public abstract class CqueryThreadsafeCallback
protected final ConfiguredTargetAccessor accessor;

private final List<String> result = new ArrayList<>();
private final boolean uniquifyResults;

@SuppressWarnings("DefaultCharset")
CqueryThreadsafeCallback(
ExtendedEventHandler eventHandler,
CqueryOptions options,
OutputStream out,
SkyframeExecutor skyframeExecutor,
TargetAccessor<KeyedConfiguredTarget> accessor) {
TargetAccessor<KeyedConfiguredTarget> accessor,
boolean uniquifyResults) {
this.eventHandler = eventHandler;
this.options = options;
if (out != null) {
Expand All @@ -72,6 +75,7 @@ public abstract class CqueryThreadsafeCallback
}
this.skyframeExecutor = skyframeExecutor;
this.accessor = (ConfiguredTargetAccessor) accessor;
this.uniquifyResults = uniquifyResults;
}

public void addResult(String string) {
Expand All @@ -86,7 +90,8 @@ public List<String> getResult() {
@Override
public void close(boolean failFast) throws InterruptedException, IOException {
if (!failFast && printStream != null) {
for (String s : result) {
List<String> resultsToPrint = uniquifyResults ? ImmutableSet.copyOf(result).asList() : result;
for (String s : resultsToPrint) {
// TODO(ulfjack): We should use queryOptions.getLineTerminator() instead.
printStream.append(s).append("\n");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public class FilesOutputFormatterCallback extends CqueryThreadsafeCallback {
SkyframeExecutor skyframeExecutor,
TargetAccessor<KeyedConfiguredTarget> accessor,
TopLevelArtifactContext topLevelArtifactContext) {
super(eventHandler, options, out, skyframeExecutor, accessor);
// Different targets may provide the same artifact, so we deduplicate the collection of all
// results at the end.
super(eventHandler, options, out, skyframeExecutor, accessor, /*uniquifyResults=*/true);
this.topLevelArtifactContext = topLevelArtifactContext;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public Comparator<KeyedConfiguredTarget> comparator() {
SkyframeExecutor skyframeExecutor,
TargetAccessor<KeyedConfiguredTarget> accessor,
DepsRetriever depsRetriever) {
super(eventHandler, options, out, skyframeExecutor, accessor);
super(eventHandler, options, out, skyframeExecutor, accessor, /*uniquifyResults=*/false);
this.depsRetriever = depsRetriever;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class LabelAndConfigurationOutputFormatterCallback extends CqueryThreadsa
SkyframeExecutor skyframeExecutor,
TargetAccessor<KeyedConfiguredTarget> accessor,
boolean showKind) {
super(eventHandler, options, out, skyframeExecutor, accessor);
super(eventHandler, options, out, skyframeExecutor, accessor, /*uniquifyResults=*/false);
this.showKind = showKind;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public ImmutableList<Configuration> getConfigurations() {
AspectResolver resolver,
OutputType outputType,
@Nullable TransitionFactory<RuleTransitionData> trimmingTransitionFactory) {
super(eventHandler, options, out, skyframeExecutor, accessor);
super(eventHandler, options, out, skyframeExecutor, accessor, /*uniquifyResults=*/false);
this.outputType = outputType;
this.skyframeExecutor = skyframeExecutor;
this.resolver = resolver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public Object providers(ConfiguredTarget target) {
SkyframeExecutor skyframeExecutor,
TargetAccessor<KeyedConfiguredTarget> accessor)
throws QueryException, InterruptedException {
super(eventHandler, options, out, skyframeExecutor, accessor);
super(eventHandler, options, out, skyframeExecutor, accessor, /*uniquifyResults=*/false);

ParserInput input = null;
String exceptionMessagePrefix;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public String getName() {
TargetAccessor<KeyedConfiguredTarget> accessor,
BuildConfigurationValue hostConfiguration,
@Nullable TransitionFactory<RuleTransitionData> trimmingTransitionFactory) {
super(eventHandler, options, out, skyframeExecutor, accessor);
super(eventHandler, options, out, skyframeExecutor, accessor, /*uniquifyResults=*/false);
this.hostConfiguration = hostConfiguration;
this.trimmingTransitionFactory = trimmingTransitionFactory;
this.partialResultMap = Maps.newHashMap();
Expand Down

0 comments on commit f37b578

Please sign in to comment.