summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorbrettw <brettw@chromium.org>2015-10-15 22:34:24 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-16 05:35:03 +0000
commita2d721a90e955ee4fad4584c150e4aaca42e94d7 (patch)
tree41f8e1a03f02494c5cd42522ee82f844fb30a9fb /tools
parent3ceb2d9e5d85f364256981ae370503411618f666 (diff)
downloadchromium_src-a2d721a90e955ee4fad4584c150e4aaca42e94d7.zip
chromium_src-a2d721a90e955ee4fad4584c150e4aaca42e94d7.tar.gz
chromium_src-a2d721a90e955ee4fad4584c150e4aaca42e94d7.tar.bz2
Handle Mozilla license blocks in the GN header checker.
The include iterator doesn't handle real C preprocessor. Mozilla license blocks use C-style comments with *'s along the left, and are long enough that the header checker gives up. This patch doesn't fix the general comment issue, different types of comments can still confuse us, but Mozilla license blocks in particular are now handled. BUG=543850 Review URL: https://codereview.chromium.org/1411573002 Cr-Commit-Position: refs/heads/master@{#354454}
Diffstat (limited to 'tools')
-rw-r--r--tools/gn/c_include_iterator.cc2
-rw-r--r--tools/gn/c_include_iterator_unittest.cc23
2 files changed, 25 insertions, 0 deletions
diff --git a/tools/gn/c_include_iterator.cc b/tools/gn/c_include_iterator.cc
index 9e719c7..120295e 100644
--- a/tools/gn/c_include_iterator.cc
+++ b/tools/gn/c_include_iterator.cc
@@ -48,6 +48,8 @@ base::StringPiece TrimLeadingWhitespace(const base::StringPiece& str) {
bool ShouldCountTowardNonIncludeLines(const base::StringPiece& line) {
if (StartsWith(line, "//"))
return false; // Don't count comments.
+ if (StartsWith(line, "/*") || StartsWith(line, " *"))
+ return false; // C-style comment blocks with stars along the left side.
if (StartsWith(line, "#"))
return false; // Don't count preprocessor.
if (base::ContainsOnlyChars(line, base::kWhitespaceASCII))
diff --git a/tools/gn/c_include_iterator_unittest.cc b/tools/gn/c_include_iterator_unittest.cc
index 11fa991..1add29b5 100644
--- a/tools/gn/c_include_iterator_unittest.cc
+++ b/tools/gn/c_include_iterator_unittest.cc
@@ -132,3 +132,26 @@ TEST(CIncludeIterator, TolerateNonIncludes) {
}
EXPECT_FALSE(iter.GetNextIncludeString(&contents, &range));
}
+
+// Tests that comments of the form
+// /*
+// *
+// */
+// are not counted toward the non-include line count.
+TEST(CIncludeIterator, CStyleComments) {
+ std::string buffer("/*");
+ for (size_t i = 0; i < 1000; i++)
+ buffer.append(" *\n");
+ buffer.append(" */\n\n");
+ buffer.append("#include \"foo/bar.h\"\n");
+
+ InputFile file(SourceFile("//foo.cc"));
+ file.SetContents(buffer);
+
+ base::StringPiece contents;
+ LocationRange range;
+
+ CIncludeIterator iter(&file);
+ EXPECT_TRUE(iter.GetNextIncludeString(&contents, &range));
+ EXPECT_EQ("foo/bar.h", contents);
+}