aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Janak Ramakrishnan <janakr@google.com>2016-03-18 15:44:28 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2016-03-21 09:33:23 +0000
commita9b88ae448644137c0b15d83e117b84072a80d2f (patch)
tree29ef454c0f94fdb5ce5e238113a489003c49f7e7 /src
parentf0cc5b838b851d3f2872492ce5e1441738c29105 (diff)
RELNOTES: Bazel warns if a cc rule's includes attribute contains up-level references that escape its package.
-- MOS_MIGRATED_REVID=117550535
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java12
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonConfiguredTargetTest.java15
2 files changed, 27 insertions, 0 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 b4ded0ef29..851aaf25a9 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
@@ -408,6 +408,18 @@ public final class CcCommon {
ruleContext.attributeError("includes",
"Path references a path above the execution root.");
}
+ if (!includesPath.startsWith(packageFragment)) {
+ ruleContext.attributeWarning(
+ "includes",
+ "'"
+ + includesAttr
+ + "' resolves to '"
+ + includesPath
+ + "' not below the relative path of its package '"
+ + packageFragment
+ + "'. This will be an error in the future");
+ // TODO(janakr): Add a link to a page explaining the problem and fixes?
+ }
result.add(includesPath);
result.add(ruleContext.getConfiguration().getGenfilesFragment().getRelative(includesPath));
}
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonConfiguredTargetTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonConfiguredTargetTest.java
index aa06687265..65e3044aa1 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonConfiguredTargetTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonConfiguredTargetTest.java
@@ -505,6 +505,21 @@ public class CcCommonConfiguredTargetTest extends BuildViewTestCase {
}
@Test
+ public void testCcLibraryUplevelIncludesWarned() throws Exception {
+ checkWarning(
+ "uplevel",
+ "lib",
+ // message:
+ "in includes attribute of cc_library rule //uplevel:lib: '../bar' resolves to 'bar' not "
+ + "below the relative path of its package 'uplevel'. This will be an error in the "
+ + "future",
+ // build file:
+ "cc_library(name = 'lib',",
+ " srcs = ['foo.cc'],",
+ " includes = ['../bar'])");
+ }
+
+ @Test
public void testStaticallyLinkedBinaryNeedsSharedObject() throws Exception {
scratch.file(
"third_party/sophos_av_pua/BUILD",