| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Top-level presubmit script for cc. | 5 """Top-level presubmit script for cc. |
| 6 | 6 |
| 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for | 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for |
| 8 details on the presubmit API built into gcl. | 8 details on the presubmit API built into gcl. |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 using_std_abs_files = [] | 67 using_std_abs_files = [] |
| 68 found_fabs_files = [] | 68 found_fabs_files = [] |
| 69 missing_std_prefix_files = [] | 69 missing_std_prefix_files = [] |
| 70 | 70 |
| 71 for f in input_api.AffectedSourceFiles(source_file_filter): | 71 for f in input_api.AffectedSourceFiles(source_file_filter): |
| 72 contents = input_api.ReadFile(f, 'rb') | 72 contents = input_api.ReadFile(f, 'rb') |
| 73 if re.search(r"using std::f?abs;", contents): | 73 if re.search(r"using std::f?abs;", contents): |
| 74 using_std_abs_files.append(f.LocalPath()) | 74 using_std_abs_files.append(f.LocalPath()) |
| 75 if re.search(r"\bfabsf?\(", contents): | 75 if re.search(r"\bfabsf?\(", contents): |
| 76 found_fabs_files.append(f.LocalPath()); | 76 found_fabs_files.append(f.LocalPath()); |
| 77 # The following regular expression in words says: | 77 |
| 78 # "if there is no 'std::' behind an 'abs(' or 'absf(', | 78 no_std_prefix = r"(?<!std::)" |
| 79 # or if there is no 'std::' behind a 'fabs(' or 'fabsf(', | 79 # Matches occurrences of abs/absf/fabs/fabsf without a "std::" prefix. |
| 80 # then it's a match." | 80 abs_without_prefix = r"%s(\babsf?\()" % no_std_prefix |
| 81 if re.search(r"((?<!std::)(\babsf?\()|(?<!std::)(\bfabsf?\())", contents): | 81 fabs_without_prefix = r"%s(\bfabsf?\()" % no_std_prefix |
| 82 # Skips matching any lines that have "// NOLINT". |
| 83 no_nolint = r"(?![^\n]*//\s+NOLINT)" |
| 84 |
| 85 expression = re.compile("(%s|%s)%s" % |
| 86 (abs_without_prefix, fabs_without_prefix, no_nolint)) |
| 87 if expression.search(contents): |
| 82 missing_std_prefix_files.append(f.LocalPath()) | 88 missing_std_prefix_files.append(f.LocalPath()) |
| 83 | 89 |
| 84 result = [] | 90 result = [] |
| 85 if using_std_abs_files: | 91 if using_std_abs_files: |
| 86 result.append(output_api.PresubmitError( | 92 result.append(output_api.PresubmitError( |
| 87 'These files have "using std::abs" which is not permitted.', | 93 'These files have "using std::abs" which is not permitted.', |
| 88 items=using_std_abs_files)) | 94 items=using_std_abs_files)) |
| 89 if found_fabs_files: | 95 if found_fabs_files: |
| 90 result.append(output_api.PresubmitError( | 96 result.append(output_api.PresubmitError( |
| 91 'std::abs() should be used instead of std::fabs() for consistency.', | 97 'std::abs() should be used instead of std::fabs() for consistency.', |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 results += CheckSpamLogging(input_api, output_api, black_list=CC_PERF_TEST) | 190 results += CheckSpamLogging(input_api, output_api, black_list=CC_PERF_TEST) |
| 185 results += CheckPassByValue(input_api, output_api) | 191 results += CheckPassByValue(input_api, output_api) |
| 186 results += CheckChangeLintsClean(input_api, output_api) | 192 results += CheckChangeLintsClean(input_api, output_api) |
| 187 results += CheckTodos(input_api, output_api) | 193 results += CheckTodos(input_api, output_api) |
| 188 return results | 194 return results |
| 189 | 195 |
| 190 def GetPreferredTrySlaves(project, change): | 196 def GetPreferredTrySlaves(project, change): |
| 191 return [ | 197 return [ |
| 192 'linux_layout_rel', | 198 'linux_layout_rel', |
| 193 ] | 199 ] |
| OLD | NEW |