From 638f293a0f608db0ea6de4e0b58cd61870086db6 Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 2 Aug 2024 02:39:01 -0700 Subject: [PATCH] Apply a workaround for absolute paths in .d files which can lead to cache issues with the Android NDK on Windows. See https://github.com/bazelbuild/bazel/issues/11817 PiperOrigin-RevId: 658725449 Change-Id: I09edfa9af8a4956d661174bef76a7f8776891a8b --- .../devtools/build/lib/util/DependencySet.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/google/devtools/build/lib/util/DependencySet.java b/src/main/java/com/google/devtools/build/lib/util/DependencySet.java index 88dfa36c5f2433..524cda148e0c39 100644 --- a/src/main/java/com/google/devtools/build/lib/util/DependencySet.java +++ b/src/main/java/com/google/devtools/build/lib/util/DependencySet.java @@ -26,6 +26,8 @@ import java.util.Collection; import java.util.Collections; import java.util.concurrent.atomic.AtomicReference; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.annotation.Nullable; /** @@ -104,7 +106,7 @@ private String translatePath(String path) { if (OS.getCurrent() != OS.WINDOWS) { return path; } - return WindowsPath.translateWindowsPath(path); + return WindowsPath.removeWorkspace(WindowsPath.translateWindowsPath(path)); } /** Reads a dotd file into this DependencySet instance. */ @@ -251,6 +253,17 @@ public int hashCode() { private static final class WindowsPath { private static final AtomicReference UNIX_ROOT = new AtomicReference<>(null); + private static final Pattern EXECROOT_BASE_HEADER_PATTERN = + Pattern.compile(".*execroot[\\\\/](?.*)"); + + private static String removeWorkspace(String path) { + Matcher m = EXECROOT_BASE_HEADER_PATTERN.matcher(path); + if (m.matches()) { + path = "../" + m.group("headerPath"); + } + return path; + } + private static String translateWindowsPath(String path) { int n = path.length(); if (n == 0 || path.charAt(0) != '/') {