Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 """Blink frame presubmit script | 5 """Blink frame presubmit script |
| 6 | 6 |
| 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts | 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| 8 for more details about the presubmit API built into gcl. | 8 for more details about the presubmit API built into gcl. |
| 9 """ | 9 """ |
| 10 | 10 |
| 11 | 11 |
| 12 def _RunUseCounterChecks(input_api, output_api): | 12 def _RunUseCounterChecks(input_api, output_api): |
| 13 for f in input_api.AffectedFiles(): | 13 for f in input_api.AffectedFiles(): |
| 14 if f.LocalPath().endswith('UseCounter.cpp'): | 14 if f.LocalPath().endswith('UseCounter.cpp'): |
| 15 useCounterCpp = f | 15 use_counter_cpp_file = f |
| 16 break | 16 break |
| 17 else: | 17 else: |
| 18 return [] | 18 return [] |
| 19 | 19 |
| 20 largestFoundBucket = 0 | 20 largest_found_bucket = 0 |
| 21 maximumBucket = 0 | 21 expected_max_bucket = 0 |
| 22 | |
| 22 # Looking for a line like "case CSSPropertyGrid: return 453;" | 23 # Looking for a line like "case CSSPropertyGrid: return 453;" |
| 23 bucketFinder = input_api.re.compile(r'.*CSSProperty.*return\s*([0-9]+).*') | 24 bucket_finder = input_api.re.compile( |
| 25 r'case CSSProperty\w*?\:\s*?\n?\s+?return (\d+);', | |
|
Nico
2016/09/30 00:41:18
why \s+ instead of \s* ?
So `return\n43;` doesn't
dcheng
2016/09/30 01:56:38
I think \s will match \n, since we're matching in
Nico
2016/09/30 02:24:52
I mean isn't `\s+?` the same as `\s*` ?
| |
| 26 input_api.re.MULTILINE) | |
| 24 # Looking for a line like "int maximumCSSSampleId() { return 452; }" | 27 # Looking for a line like "int maximumCSSSampleId() { return 452; }" |
|
Nico
2016/09/30 00:41:18
update comment
dcheng
2016/09/30 01:56:38
Done.
| |
| 25 maximumFinder = input_api.re.compile( | 28 expected_max_finder = input_api.re.compile( |
| 26 r'constexpr int kMaximumCSSSampleId = ([0-9]+);') | 29 r'constexpr int kMaximumCSSSampleId = (\d+);') |
| 27 for line in useCounterCpp.NewContents(): | 30 joined_contents = '\n'.join(use_counter_cpp_file.NewContents()) |
| 28 bucketMatch = bucketFinder.match(line) | |
| 29 if bucketMatch: | |
| 30 bucket = int(bucketMatch.group(1)) | |
| 31 largestFoundBucket = max(largestFoundBucket, bucket) | |
| 32 else: | |
| 33 maximumMatch = maximumFinder.match(line) | |
| 34 if maximumMatch: | |
| 35 maximumBucket = int(maximumMatch.group(1)) | |
| 36 | 31 |
| 37 if largestFoundBucket != maximumBucket: | 32 expected_max_match = expected_max_finder.search(joined_contents) |
| 33 if expected_max_match: | |
| 34 expected_max_bucket = int(expected_max_match.group(1)) | |
| 35 | |
| 36 for bucket_match in bucket_finder.finditer(joined_contents): | |
| 37 bucket = int(bucket_match.group(1)) | |
| 38 largest_found_bucket = max(largest_found_bucket, bucket) | |
| 39 | |
| 40 if largest_found_bucket != expected_max_bucket: | |
| 38 if input_api.is_committing: | 41 if input_api.is_committing: |
| 39 message_type = output_api.PresubmitError | 42 message_type = output_api.PresubmitError |
| 40 else: | 43 else: |
| 41 message_type = output_api.PresubmitPromptWarning | 44 message_type = output_api.PresubmitPromptWarning |
| 42 | 45 |
| 43 return [message_type( | 46 return [message_type( |
| 44 'Largest found CSSProperty bucket Id (%d) does not match ' | 47 'Largest found CSSProperty bucket Id (%d) does not match ' |
| 45 'maximumCSSSampleId (%d)' % | 48 'maximumCSSSampleId (%d)' % ( |
| 46 (largestFoundBucket, maximumBucket), | 49 largest_found_bucket, expected_max_bucket), |
| 47 items=[useCounterCpp.LocalPath()])] | 50 items=[use_counter_cpp_file.LocalPath()])] |
| 48 | 51 |
| 49 return [] | 52 return [] |
| 50 | 53 |
| 51 | 54 |
| 52 def _RunUmaHistogramChecks(input_api, output_api): | 55 def _RunUmaHistogramChecks(input_api, output_api): |
| 53 import sys | 56 import sys |
| 54 | 57 |
| 55 original_sys_path = sys.path | 58 original_sys_path = sys.path |
| 56 try: | 59 try: |
| 57 sys.path = sys.path + [input_api.os_path.join( | 60 sys.path = sys.path + [input_api.os_path.join( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 results.extend(_RunUseCounterChecks(input_api, output_api)) | 93 results.extend(_RunUseCounterChecks(input_api, output_api)) |
| 91 results.extend(_RunUmaHistogramChecks(input_api, output_api)) | 94 results.extend(_RunUmaHistogramChecks(input_api, output_api)) |
| 92 return results | 95 return results |
| 93 | 96 |
| 94 | 97 |
| 95 def CheckChangeOnCommit(input_api, output_api): | 98 def CheckChangeOnCommit(input_api, output_api): |
| 96 results = [] | 99 results = [] |
| 97 results.extend(_RunUseCounterChecks(input_api, output_api)) | 100 results.extend(_RunUseCounterChecks(input_api, output_api)) |
| 98 results.extend(_RunUmaHistogramChecks(input_api, output_api)) | 101 results.extend(_RunUmaHistogramChecks(input_api, output_api)) |
| 99 return results | 102 return results |
| OLD | NEW |