OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 # | 5 # |
6 # Wrapper script around Rietveld's upload.py that groups files into | 6 # Wrapper script around Rietveld's upload.py that groups files into |
7 # changelists. | 7 # changelists. |
8 | 8 |
9 import getpass | 9 import getpass |
10 import os | 10 import os |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 | 125 |
126 | 126 |
127 def GetCachedFile(filename, max_age=60*60*24*3, use_root=False): | 127 def GetCachedFile(filename, max_age=60*60*24*3, use_root=False): |
128 """Retrieves a file from the repository and caches it in GetCacheDir() for | 128 """Retrieves a file from the repository and caches it in GetCacheDir() for |
129 max_age seconds. | 129 max_age seconds. |
130 | 130 |
131 use_root: If False, look up the arborescence for the first match, otherwise go | 131 use_root: If False, look up the arborescence for the first match, otherwise go |
132 directory to the root repository. | 132 directory to the root repository. |
133 | 133 |
134 Note: The cache will be inconsistent if the same file is retrieved with both | 134 Note: The cache will be inconsistent if the same file is retrieved with both |
135 use_root=True and use_root=False on the same file. Don't be stupid. | 135 use_root=True and use_root=False. Don't be stupid. |
136 """ | 136 """ |
137 global FILES_CACHE | 137 global FILES_CACHE |
138 if filename not in FILES_CACHE: | 138 if filename not in FILES_CACHE: |
139 # Don't try to look up twice. | 139 # Don't try to look up twice. |
140 FILES_CACHE[filename] = None | 140 FILES_CACHE[filename] = None |
141 # First we check if we have a cached version. | 141 # First we check if we have a cached version. |
142 try: | 142 try: |
143 cached_file = os.path.join(GetCacheDir(), filename) | 143 cached_file = os.path.join(GetCacheDir(), filename) |
144 except gclient_utils.Error: | 144 except gclient_utils.Error: |
145 return None | 145 return None |
146 if (not os.path.exists(cached_file) or | 146 if (not os.path.exists(cached_file) or |
147 os.stat(cached_file).st_mtime > max_age): | 147 os.stat(cached_file).st_mtime > max_age): |
148 dir_info = gclient_scm.CaptureSVNInfo(".") | 148 dir_info = gclient_scm.CaptureSVNInfo(".") |
149 repo_root = dir_info["Repository Root"] | 149 repo_root = dir_info["Repository Root"] |
150 if use_root: | 150 if use_root: |
151 url_path = repo_root | 151 url_path = repo_root |
152 else: | 152 else: |
153 url_path = dir_info["URL"] | 153 url_path = dir_info["URL"] |
154 content = "" | 154 content = "" |
155 while True: | 155 while True: |
156 # Look for the codereview.settings file at the current level. | 156 # First, look for a locally modified version of codereview.settings. |
157 svn_path = url_path + "/" + filename | 157 content, rc = RunShellWithReturnCode(["svn", "status", filename]) |
158 content, rc = RunShellWithReturnCode(["svn", "cat", svn_path]) | 158 if not rc and content.startswith('M'): |
| 159 content = ReadFile(filename) |
| 160 rc = 0 |
| 161 else: |
| 162 # Then look in the repository |
| 163 svn_path = url_path + "/" + filename |
| 164 content, rc = RunShellWithReturnCode(["svn", "cat", svn_path]) |
| 165 |
159 if not rc: | 166 if not rc: |
160 # Exit the loop if the file was found. Override content. | 167 # Exit the loop if the file was found. Override content. |
161 break | 168 break |
162 # Make sure to mark settings as empty if not found. | 169 # Make sure to mark settings as empty if not found. |
163 content = "" | 170 content = "" |
164 if url_path == repo_root: | 171 if url_path == repo_root: |
165 # Reached the root. Abandoning search. | 172 # Reached the root. Abandoning search. |
166 break | 173 break |
167 # Go up one level to try again. | 174 # Go up one level to try again. |
168 url_path = os.path.dirname(url_path) | 175 url_path = os.path.dirname(url_path) |
(...skipping 901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1070 | 1077 |
1071 change_info.Save() | 1078 change_info.Save() |
1072 print change_info.name + " changelist saved." | 1079 print change_info.name + " changelist saved." |
1073 if change_info.MissingTests(): | 1080 if change_info.MissingTests(): |
1074 Warn("WARNING: " + MISSING_TEST_MSG) | 1081 Warn("WARNING: " + MISSING_TEST_MSG) |
1075 | 1082 |
1076 # We don't lint files in these path prefixes. | 1083 # We don't lint files in these path prefixes. |
1077 IGNORE_PATHS = (os.path.join("webkit","api"),) | 1084 IGNORE_PATHS = (os.path.join("webkit","api"),) |
1078 | 1085 |
1079 # Valid extensions for files we want to lint. | 1086 # Valid extensions for files we want to lint. |
1080 CPP_EXTENSIONS = ("cpp", "cc", "h") | 1087 LINT_REGEX = r"(.*\.cpp|.*\.cc|.*\.h)" |
| 1088 LINT_IGNORE_REGEX = r"" |
1081 | 1089 |
1082 def Lint(change_info, args): | 1090 def Lint(change_info, args): |
1083 """Runs cpplint.py on all the files in |change_info|""" | 1091 """Runs cpplint.py on all the files in |change_info|""" |
1084 try: | 1092 try: |
1085 import cpplint | 1093 import cpplint |
1086 except ImportError: | 1094 except ImportError: |
1087 ErrorExit("You need to install cpplint.py to lint C++ files.") | 1095 ErrorExit("You need to install cpplint.py to lint C++ files.") |
1088 | 1096 |
1089 # Change the current working directory before calling lint so that it | 1097 # Change the current working directory before calling lint so that it |
1090 # shows the correct base. | 1098 # shows the correct base. |
1091 previous_cwd = os.getcwd() | 1099 previous_cwd = os.getcwd() |
1092 os.chdir(change_info.GetLocalRoot()) | 1100 os.chdir(change_info.GetLocalRoot()) |
1093 | 1101 |
1094 # Process cpplints arguments if any. | 1102 # Process cpplints arguments if any. |
1095 filenames = cpplint.ParseArguments(args + change_info.GetFileNames()) | 1103 filenames = cpplint.ParseArguments(args + change_info.GetFileNames()) |
1096 | 1104 |
| 1105 white_list = GetCodeReviewSetting("LINT_REGEX") |
| 1106 if not white_list: |
| 1107 white_list = LINT_REGEX |
| 1108 white_regex = re.compile(white_list) |
| 1109 black_list = GetCodeReviewSetting("LINT_IGNORE_REGEX") |
| 1110 if not black_list: |
| 1111 black_list = LINT_IGNORE_REGEX |
| 1112 black_regex = re.compile(black_list) |
1097 for file in filenames: | 1113 for file in filenames: |
1098 if len([file for suffix in CPP_EXTENSIONS if file.endswith(suffix)]): | 1114 if white_regex.match(file): |
1099 if len([file for prefix in IGNORE_PATHS if file.startswith(prefix)]): | 1115 if black_regex.match(file): |
1100 print "Ignoring non-Google styled file %s" % file | 1116 print "Ignoring file %s" % file |
1101 else: | 1117 else: |
1102 cpplint.ProcessFile(file, cpplint._cpplint_state.verbose_level) | 1118 cpplint.ProcessFile(file, cpplint._cpplint_state.verbose_level) |
| 1119 else: |
| 1120 print "Skipping file %s" % file |
1103 | 1121 |
1104 print "Total errors found: %d\n" % cpplint._cpplint_state.error_count | 1122 print "Total errors found: %d\n" % cpplint._cpplint_state.error_count |
1105 os.chdir(previous_cwd) | 1123 os.chdir(previous_cwd) |
1106 | 1124 |
1107 | 1125 |
1108 def DoPresubmitChecks(change_info, committing, may_prompt): | 1126 def DoPresubmitChecks(change_info, committing, may_prompt): |
1109 """Imports presubmit, then calls presubmit.DoPresubmitChecks.""" | 1127 """Imports presubmit, then calls presubmit.DoPresubmitChecks.""" |
1110 # Need to import here to avoid circular dependency. | 1128 # Need to import here to avoid circular dependency. |
1111 import presubmit_support | 1129 import presubmit_support |
1112 root_presubmit = GetCachedFile('PRESUBMIT.py', use_root=True) | 1130 root_presubmit = GetCachedFile('PRESUBMIT.py', use_root=True) |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1251 # the files. This allows commands such as 'gcl diff xxx' to work. | 1269 # the files. This allows commands such as 'gcl diff xxx' to work. |
1252 args =["svn", command] | 1270 args =["svn", command] |
1253 root = GetRepositoryRoot() | 1271 root = GetRepositoryRoot() |
1254 args.extend([os.path.join(root, x) for x in change_info.GetFileNames()]) | 1272 args.extend([os.path.join(root, x) for x in change_info.GetFileNames()]) |
1255 RunShell(args, True) | 1273 RunShell(args, True) |
1256 return 0 | 1274 return 0 |
1257 | 1275 |
1258 | 1276 |
1259 if __name__ == "__main__": | 1277 if __name__ == "__main__": |
1260 sys.exit(main()) | 1278 sys.exit(main()) |
OLD | NEW |