Skip to content

Commit

Permalink
Expand error message for LTO compilation with list of missing files i…
Browse files Browse the repository at this point in the history
…n imports.

LtoBackendAction checks whether bitcode files are available for all of the
imports. Expand the error message not only to indicate there was a difference
but also to list the missing files. Please note that there cannot be extra
files given the constructed NetsedSet is always a subset of the imports.

PiperOrigin-RevId: 315269362
  • Loading branch information
alexjski authored and copybara-github committed Jun 8, 2020
1 parent 5cab53a commit 0f0ca6e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets;
import com.google.devtools.build.lib.actions.AbstractAction;
import com.google.devtools.build.lib.actions.ActionEnvironment;
import com.google.devtools.build.lib.actions.ActionExecutionContext;
Expand All @@ -41,6 +42,8 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Nullable;

/**
Expand Down Expand Up @@ -157,9 +160,22 @@ public NestedSet<Artifact> discoverInputs(ActionExecutionContext actionExecution
// Convert the import set of paths to the set of bitcode file artifacts.
NestedSet<Artifact> bitcodeInputSet = computeBitcodeInputs(importSet);
if (bitcodeInputSet.memoizedFlattenAndGetSize() != importSet.size()) {
Set<PathFragment> missingInputs =
Sets.difference(
importSet,
bitcodeInputSet.toList().stream()
.map(Artifact::getExecPath)
.collect(Collectors.toSet()));
throw new ActionExecutionException(
"error computing inputs from imports file "
+ actionExecutionContext.getInputPath(imports),
String.format(
"error computing inputs from imports file: %s, missing bitcode files (first 10): %s",
actionExecutionContext.getInputPath(imports),
// Limit the reported count to protect against a large error message.
missingInputs.stream()
.map(Object::toString)
.sorted()
.limit(10)
.collect(Collectors.joining(", "))),
this,
false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
package com.google.devtools.build.lib.rules.cpp;

import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.actions.AbstractAction;
import com.google.devtools.build.lib.actions.Action;
import com.google.devtools.build.lib.actions.ActionExecutionContext;
import com.google.devtools.build.lib.actions.ActionExecutionContext.LostInputsCheck;
import com.google.devtools.build.lib.actions.ActionExecutionException;
import com.google.devtools.build.lib.actions.ActionInputPrefetcher;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.Executor;
Expand All @@ -38,6 +40,7 @@
import com.google.devtools.build.lib.exec.BinTools;
import com.google.devtools.build.lib.exec.util.TestExecutorBuilder;
import com.google.devtools.build.lib.util.io.FileOutErr;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -245,4 +248,25 @@ public Action generate(ImmutableSet<KeyAttributes> attributesToFlip) {
},
actionKeyContext);
}

@Test
public void discoverInputs_missingInputErrorMessage() throws Exception {
FileSystemUtils.writeIsoLatin1(imports1Artifact.getPath(), "file1.o", "file2.o", "file3.o");

Action[] actions =
new LtoBackendAction.Builder()
.addImportsInfo(
new BitcodeFiles(
new NestedSetBuilder<Artifact>(Order.STABLE_ORDER)
.add(getSourceArtifact("file2.o"))
.build()),
imports1Artifact)
.setExecutable(scratch.file("/bin/clang").asFragment())
.addOutput(destinationArtifact)
.build(ActionsTestUtil.NULL_ACTION_OWNER, targetConfig);
ActionExecutionException e =
assertThrows(ActionExecutionException.class, () -> actions[0].discoverInputs(context));

assertThat(e).hasMessageThat().endsWith("(first 10): file1.o, file3.o");
}
}

0 comments on commit 0f0ca6e

Please sign in to comment.