Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2325)

Unified Diff: net/spdy/PRESUBMIT.py

Issue 2847613002: Add net/spdy/PRESUBMIT.py. (Closed)
Patch Set: Rebase. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/spdy/PRESUBMIT.py
diff --git a/net/spdy/PRESUBMIT.py b/net/spdy/PRESUBMIT.py
new file mode 100644
index 0000000000000000000000000000000000000000..3a8e27c12860a056ff64f2ef41445be932afe00c
--- /dev/null
+++ b/net/spdy/PRESUBMIT.py
@@ -0,0 +1,64 @@
+# Copyright 2017 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import re
+
+def CheckForbiddenRegex(change, forbidden_regex, message_type, message):
+ problems = []
+ for path, change_per_file in change:
+ line_num = 1
+ for line in change_per_file:
+ if forbidden_regex.match(line):
+ problems.extend([" %s:%d" % (path, line_num)])
+ line_num += 1
+ if not problems:
+ return []
+ return [message_type(message + ":\n" + "\n".join(problems))]
+
+
+def CheckChange(input_api, message_type):
+ result = []
+ shared_source_files = re.compile("^net/spdy/(core|platform/api)/.*\.(h|cc)$")
+ change = [(affected_file.LocalPath(), affected_file.NewContents())
+ for affected_file in input_api.AffectedTestableFiles()
+ if shared_source_files.match(affected_file.LocalPath())]
+ forbidden_regex_list = [
+ r"^#include \"net/base/net_export.h\"$",
+ r"\bNET_EXPORT\b",
+ r"\bNET_EXPORT_PRIVATE\b",
+ "^#include <string>$",
+ r"\bstd::string\b",
+ r"^#include \"base/strings/string_piece.h\"$",
+ r"\bbase::StringPiece\b",
+ r"\bbase::StringPrintf\b",
+ r"\bbase::StringAppendF\b",
+ r"\bbase::HexDigitToInt\b",
+ ]
+ messages = [
+ "Include \"spdy/platform/api/spdy_export.h\" "
+ "instead of \"net/base/net_export.h\"",
+ "Use SPDY_EXPORT instead of NET_EXPORT",
+ "Use SPDY_EXPORT_PRIVATE instead of NET_EXPORT_PRIVATE",
+ "Include \"spdy/platform/api/spdy_string.h\" instead of <string>",
+ "Use SpdyString instead of std::string",
+ "Include \"spdy/platform/api/spdy_string_piece.h\" "
+ "instead of \"base/strings/string_piece.h\"",
+ "Use SpdyStringPiece instead of base::StringPiece",
+ "Use SpdyStringPrintf instead of base::StringPrintf",
+ "Use SpdyStringAppendF instead of base::StringAppendF",
+ "Use SpdyHexDigitToInt instead of base::HexDigitToInt",
+ ]
+ for forbidden_regex, message in zip(forbidden_regex_list, messages):
+ result.extend(CheckForbiddenRegex(
+ change, re.compile(forbidden_regex), message_type, message))
+ return result
+
+# Warn before uploading but allow developer to skip warning
+# so that CLs can be shared and reviewed before addressing all issues.
+def CheckChangeOnUpload(input_api, output_api):
+ return CheckChange(input_api, output_api.PresubmitPromptWarning)
+
+# Do not allow code with forbidden patterns to be checked in.
+def CheckChangeOnCommit(input_api, output_api):
+ return CheckChange(input_api, output_api.PresubmitError)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698