aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/cpp/IncludeScanner.java
diff options
context:
space:
mode:
authorGravatar tomlu <tomlu@google.com>2017-12-27 13:33:35 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2017-12-27 13:35:42 -0800
commita0d84f68c3555b600828695affaacf6872d4a886 (patch)
tree32ee55d00b8f2ddfbbcf329d56414d0fab7c7e38 /src/main/java/com/google/devtools/build/lib/rules/cpp/IncludeScanner.java
parentc13b2ad87917251856db135314f03806c32aaae0 (diff)
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
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/cpp/IncludeScanner.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/IncludeScanner.java15
1 files changed, 8 insertions, 7 deletions
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<Artifact> 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());
}