diff options
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java index 597e5dd1a8..e9ef99984f 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java @@ -414,7 +414,7 @@ public final class CcCommon { List<PathFragment> getSystemIncludeDirs() { List<PathFragment> result = new ArrayList<>(); PackageIdentifier packageIdentifier = ruleContext.getLabel().getPackageIdentifier(); - PathFragment packageFragment = packageIdentifier.getPathUnderExecRoot(); + PathFragment pathUnderExecRoot = packageIdentifier.getPathUnderExecRoot(); for (String includesAttr : ruleContext.attributes().get("includes", Type.STRING_LIST)) { includesAttr = ruleContext.expandMakeVariables("includes", includesAttr); if (includesAttr.startsWith("/")) { @@ -422,10 +422,14 @@ public final class CcCommon { "ignoring invalid absolute path '" + includesAttr + "'"); continue; } - PathFragment includesPath = packageFragment.getRelative(includesAttr).normalize(); - if (!includesPath.isNormalized()) { + PathFragment includesPath = pathUnderExecRoot.getRelative(includesAttr).normalize(); + // It's okay for the includes path to start with ../workspace-name for external repos. + if ((packageIdentifier.getRepository().isMain() && !includesPath.isNormalized()) + || (!packageIdentifier.getRepository().isMain() + && !includesPath.startsWith( + packageIdentifier.getRepository().getPathUnderExecRoot()))) { ruleContext.attributeError("includes", - "Path references a path above the execution root."); + includesAttr + " references a path above the execution root (" + includesPath + ")."); } if (includesPath.segmentCount() == 0) { ruleContext.attributeError( @@ -435,7 +439,7 @@ public final class CcCommon { + "' resolves to the workspace root, which would allow this rule and all of its " + "transitive dependents to include any file in your workspace. Please include only" + " what you need"); - } else if (!includesPath.startsWith(packageFragment)) { + } else if (!includesPath.startsWith(pathUnderExecRoot)) { ruleContext.attributeWarning( "includes", "'" @@ -443,11 +447,14 @@ public final class CcCommon { + "' resolves to '" + includesPath + "' not below the relative path of its package '" - + packageFragment + + pathUnderExecRoot + "'. This will be an error in the future"); } result.add(includesPath); - result.add(ruleContext.getConfiguration().getGenfilesFragment().getRelative(includesPath)); + result.add(packageIdentifier.getRepository().getPathUnderExecRoot() + .getRelative(ruleContext.getConfiguration().getGenfilesFragment()) + .getRelative(packageIdentifier.getPackageFragment()) + .getRelative(includesAttr)); } return result; } |