diff --git a/src/main/java/com/google/devtools/build/lib/analysis/platform/PlatformUtils.java b/src/main/java/com/google/devtools/build/lib/analysis/platform/PlatformUtils.java index 621a598b25aea4..8d906d47c50195 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/platform/PlatformUtils.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/platform/PlatformUtils.java @@ -17,6 +17,7 @@ import build.bazel.remote.execution.v2.Platform; import build.bazel.remote.execution.v2.Platform.Property; import com.google.common.base.Strings; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.Ordering; import com.google.devtools.build.lib.actions.Spawn; @@ -61,7 +62,8 @@ public static Platform buildPlatformProto(Map executionPropertie } @Nullable - public static Platform getPlatformProto(Spawn spawn, @Nullable RemoteOptions remoteOptions) + public static Platform getPlatformProto(Spawn spawn, @Nullable RemoteOptions remoteOptions, + List extraProperties) throws UserExecException { SortedMap defaultExecProperties = remoteOptions != null @@ -101,10 +103,18 @@ public static Platform getPlatformProto(Spawn spawn, @Nullable RemoteOptions rem } } + platformBuilder.addAllProperties(extraProperties); + sortPlatformProperties(platformBuilder); return platformBuilder.build(); } + @Nullable + public static Platform getPlatformProto(Spawn spawn, @Nullable RemoteOptions remoteOptions) + throws UserExecException { + return getPlatformProto(spawn, remoteOptions, ImmutableList.of()); + } + private static FailureDetail createFailureDetail(String message, Code detailedCode) { return FailureDetail.newBuilder() .setMessage(message) diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java index 322321e81bf303..eca55d3bbf75f2 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java +++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java @@ -139,7 +139,8 @@ public CacheHandle lookup(Spawn spawn, SpawnExecutionContext context) Digest merkleTreeRoot = merkleTree.getRootDigest(); // Get the remote platform properties. - Platform platform = PlatformUtils.getPlatformProto(spawn, options); + Platform platform = PlatformUtils.getPlatformProto(spawn, options, + RemoteSpawnRunner.getExtraPlatformProperties(spawn, execRoot)); Command command = RemoteSpawnRunner.buildCommand( diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnRunner.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnRunner.java index 4085946f68a139..f235e0ed221282 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnRunner.java +++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnRunner.java @@ -35,6 +35,7 @@ import build.bazel.remote.execution.v2.ExecutionStage.Value; import build.bazel.remote.execution.v2.LogFile; import build.bazel.remote.execution.v2.Platform; +import build.bazel.remote.execution.v2.Platform.Property; import build.bazel.remote.execution.v2.RequestMetadata; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; @@ -696,6 +697,22 @@ private SpawnResult handleError( .build(); } + static List getExtraPlatformProperties(Spawn spawn, Path execRoot) { + // Hack on Windows. The included headers dumped by cl.exe in stdout contain absolute paths. + // When compiling the file from different workspace, the shared cache will cause header + // dependency checking to fail. This was initially fixed by a hack (see + // https://github.com/bazelbuild/bazel/issues/9172 for more details), but is broken again due + // to cl/356735700. We include workspace name here so action results from different workspaces + // on Windows won't be shared. + boolean isWindows = System.getProperty("os.name").startsWith("Windows"); + if (isWindows) { + return ImmutableList + .of(Property.newBuilder().setName("workspace").setValue(execRoot.getBaseName()).build()); + } + + return ImmutableList.of(); + } + static Action buildAction( Digest command, Digest inputRoot,