From a0d84f68c3555b600828695affaacf6872d4a886 Mon Sep 17 00:00:00 2001 From: tomlu Date: Wed, 27 Dec 2017 13:33:35 -0800 Subject: Fix include scanner's absolute path handling. When absolute include dirs are used we can discover absolute includes outside any known root. * Fix bug where we try to create an absolute exec path. Instead, make the exec path relative to the root directory '/'. * Reverse the condition we use to filter absolute includes. We can identify these by their fake root ('/') before we create a path and linearly check if it is a system include. PiperOrigin-RevId: 180217154 --- .../devtools/build/lib/rules/cpp/IncludeScanner.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib/rules/cpp/IncludeScanner.java') diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/IncludeScanner.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/IncludeScanner.java index c3592846ee..b07f75e86f 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/IncludeScanner.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/IncludeScanner.java @@ -26,7 +26,6 @@ import com.google.devtools.build.lib.profiler.Profiler; import com.google.devtools.build.lib.profiler.ProfilerTask; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.PathFragment; - import java.io.IOException; import java.util.ArrayList; import java.util.Collection; @@ -154,12 +153,14 @@ public interface IncludeScanner { // Collect inputs and output List inputs = new ArrayList<>(); for (Artifact included : includes) { - if (FileSystemUtils.startsWithAny(included.getPath().asFragment(), - absoluteBuiltInIncludeDirs)) { - // Skip include files found in absolute include directories. - continue; - } - if (included.getRoot().getPath().getParentDirectory() == null) { + // Check for absolute includes -- we assign the file system root as + // the root path for such includes + if (included.getRoot().getPath().isRootDirectory()) { + if (FileSystemUtils.startsWithAny( + included.getPath().asFragment(), absoluteBuiltInIncludeDirs)) { + // Skip include files found in absolute include directories. + continue; + } throw new UserExecException( "illegal absolute path to include file: " + included.getPath()); } -- cgit v1.2.3