Skip to content

Commit

Permalink
Tolerate the possibility of a swig action depending on headers genera…
Browse files Browse the repository at this point in the history
…ted by shared actions.

Shared actions produce artifacts with equal exec paths, so we can't use `Maps#uniqueIndex`.

PiperOrigin-RevId: 589123066
Change-Id: Id472319c41ff287218e35173fbecb6a0bd0e089d
  • Loading branch information
justinhorvitz authored and copybara-github committed Dec 8, 2023
1 parent 77fc949 commit 65da015
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
// limitations under the License.
package com.google.devtools.build.lib.includescanning;

import static com.google.common.collect.ImmutableMap.toImmutableMap;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.common.flogger.GoogleLogger;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
Expand Down Expand Up @@ -209,14 +210,22 @@ public void extractSwigIncludes(
env.getDirectories(),
env.getSkyframeBuildView().getArtifactFactory(),
env.getExecRoot());
// For Swig include scanning, just point to the output file in the map.
ImmutableMap<PathFragment, Artifact> pathToDeclaredHeader =
legalOutputPaths.stream()
.collect(
toImmutableMap(
Artifact::getExecPath,
artifact -> artifact,
// Headers may be generated by shared actions. If both shared actions' outputs
// are present, just use the first (b/304564144).
(a, b) -> a));
try {
scanner.processAsync(
source,
ImmutableList.of(source),
// For Swig include scanning just point to the output file in the map.
new IncludeScanningHeaderData.Builder(
Maps.uniqueIndex(legalOutputPaths, Artifact::getExecPath),
/*modularHeaders=*/ ImmutableSet.of())
pathToDeclaredHeader, /* modularHeaders= */ ImmutableSet.of())
.build(),
ImmutableList.of(),
includes,
Expand Down Expand Up @@ -329,8 +338,8 @@ public void executorCreated() {
threads,
0L,
TimeUnit.SECONDS,
new SynchronousQueue<Runnable>(),
new ThreadFactoryBuilder().setNameFormat("Include scanner" + " %d").build(),
new SynchronousQueue<>(),
new ThreadFactoryBuilder().setNameFormat("Include scanner %d").build(),
(r, e) -> r.run());
} else {
includePool = ExecutorUtil.newSlackPool(threads, "Include scanner");
Expand Down

0 comments on commit 65da015

Please sign in to comment.