From d2515e36351911ebae4d267c1d8adfc7c72bad19 Mon Sep 17 00:00:00 2001 From: Janak Ramakrishnan Date: Mon, 11 Apr 2016 19:25:23 +0000 Subject: RELNOTES[INC]: It is now an error for a cc rule's includes attribute to point to the workspace root. -- MOS_MIGRATED_REVID=119558172 --- .../com/google/devtools/build/lib/rules/cpp/CcCommon.java | 10 +++++++++- .../build/lib/rules/cpp/CcCommonConfiguredTargetTest.java | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'src') 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 b1639ea9a2..69763d4513 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,7 +408,15 @@ public final class CcCommon { ruleContext.attributeError("includes", "Path references a path above the execution root."); } - if (!includesPath.startsWith(packageFragment)) { + if (includesPath.segmentCount() == 0) { + ruleContext.attributeError( + "includes", + "'" + + includesAttr + + "' 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)) { ruleContext.attributeWarning( "includes", "'" 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 582400a740..abf21165dd 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 @@ -518,6 +518,21 @@ public class CcCommonConfiguredTargetTest extends BuildViewTestCase { " includes = ['../bar'])"); } + @Test + public void testCcLibraryRootIncludesError() throws Exception { + checkError( + "root", + "lib", + // message: + "in includes attribute of cc_library rule //root:lib: '..' 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", + // build file: + "cc_library(name = 'lib',", + " srcs = ['foo.cc'],", + " includes = ['..'])"); + } + @Test public void testStaticallyLinkedBinaryNeedsSharedObject() throws Exception { scratch.file( -- cgit v1.2.3