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

Side by Side Diff: net/spdy/PRESUBMIT.py

Issue 2847613002: Add net/spdy/PRESUBMIT.py. (Closed)
Patch Set: Rebase. Created 3 years, 7 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2017 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import re
6
7 def CheckForbiddenRegex(change, forbidden_regex, message_type, message):
8 problems = []
9 for path, change_per_file in change:
10 line_num = 1
11 for line in change_per_file:
12 if forbidden_regex.match(line):
13 problems.extend([" %s:%d" % (path, line_num)])
14 line_num += 1
15 if not problems:
16 return []
17 return [message_type(message + ":\n" + "\n".join(problems))]
18
19
20 def CheckChange(input_api, message_type):
21 result = []
22 shared_source_files = re.compile("^net/spdy/(core|platform/api)/.*\.(h|cc)$")
23 change = [(affected_file.LocalPath(), affected_file.NewContents())
24 for affected_file in input_api.AffectedTestableFiles()
25 if shared_source_files.match(affected_file.LocalPath())]
26 forbidden_regex_list = [
27 r"^#include \"net/base/net_export.h\"$",
28 r"\bNET_EXPORT\b",
29 r"\bNET_EXPORT_PRIVATE\b",
30 "^#include <string>$",
31 r"\bstd::string\b",
32 r"^#include \"base/strings/string_piece.h\"$",
33 r"\bbase::StringPiece\b",
34 r"\bbase::StringPrintf\b",
35 r"\bbase::StringAppendF\b",
36 r"\bbase::HexDigitToInt\b",
37 ]
38 messages = [
39 "Include \"spdy/platform/api/spdy_export.h\" "
40 "instead of \"net/base/net_export.h\"",
41 "Use SPDY_EXPORT instead of NET_EXPORT",
42 "Use SPDY_EXPORT_PRIVATE instead of NET_EXPORT_PRIVATE",
43 "Include \"spdy/platform/api/spdy_string.h\" instead of <string>",
44 "Use SpdyString instead of std::string",
45 "Include \"spdy/platform/api/spdy_string_piece.h\" "
46 "instead of \"base/strings/string_piece.h\"",
47 "Use SpdyStringPiece instead of base::StringPiece",
48 "Use SpdyStringPrintf instead of base::StringPrintf",
49 "Use SpdyStringAppendF instead of base::StringAppendF",
50 "Use SpdyHexDigitToInt instead of base::HexDigitToInt",
51 ]
52 for forbidden_regex, message in zip(forbidden_regex_list, messages):
53 result.extend(CheckForbiddenRegex(
54 change, re.compile(forbidden_regex), message_type, message))
55 return result
56
57 # Warn before uploading but allow developer to skip warning
58 # so that CLs can be shared and reviewed before addressing all issues.
59 def CheckChangeOnUpload(input_api, output_api):
60 return CheckChange(input_api, output_api.PresubmitPromptWarning)
61
62 # Do not allow code with forbidden patterns to be checked in.
63 def CheckChangeOnCommit(input_api, output_api):
64 return CheckChange(input_api, output_api.PresubmitError)
OLDNEW
« 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