Chromium Code Reviews| Index: third_party/WebKit/Source/core/frame/PRESUBMIT.py |
| diff --git a/third_party/WebKit/Source/core/frame/PRESUBMIT.py b/third_party/WebKit/Source/core/frame/PRESUBMIT.py |
| index f4541a133a55a9cce6075d335be3b23e02b714ba..6aa6c44e0f8090e944952fe2c351f9f273a98165 100644 |
| --- a/third_party/WebKit/Source/core/frame/PRESUBMIT.py |
| +++ b/third_party/WebKit/Source/core/frame/PRESUBMIT.py |
| @@ -12,29 +12,32 @@ for more details about the presubmit API built into gcl. |
| def _RunUseCounterChecks(input_api, output_api): |
| for f in input_api.AffectedFiles(): |
| if f.LocalPath().endswith('UseCounter.cpp'): |
| - useCounterCpp = f |
| + use_counter_cpp_file = f |
| break |
| else: |
| return [] |
| - largestFoundBucket = 0 |
| - maximumBucket = 0 |
| + largest_found_bucket = 0 |
| + expected_max_bucket = 0 |
| + |
| # Looking for a line like "case CSSPropertyGrid: return 453;" |
| - bucketFinder = input_api.re.compile(r'.*CSSProperty.*return\s*([0-9]+).*') |
| + bucket_finder = input_api.re.compile( |
| + 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*` ?
|
| + input_api.re.MULTILINE) |
| # 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.
|
| - maximumFinder = input_api.re.compile( |
| - r'constexpr int kMaximumCSSSampleId = ([0-9]+);') |
| - for line in useCounterCpp.NewContents(): |
| - bucketMatch = bucketFinder.match(line) |
| - if bucketMatch: |
| - bucket = int(bucketMatch.group(1)) |
| - largestFoundBucket = max(largestFoundBucket, bucket) |
| - else: |
| - maximumMatch = maximumFinder.match(line) |
| - if maximumMatch: |
| - maximumBucket = int(maximumMatch.group(1)) |
| + expected_max_finder = input_api.re.compile( |
| + r'constexpr int kMaximumCSSSampleId = (\d+);') |
| + joined_contents = '\n'.join(use_counter_cpp_file.NewContents()) |
| + |
| + expected_max_match = expected_max_finder.search(joined_contents) |
| + if expected_max_match: |
| + expected_max_bucket = int(expected_max_match.group(1)) |
| + |
| + for bucket_match in bucket_finder.finditer(joined_contents): |
| + bucket = int(bucket_match.group(1)) |
| + largest_found_bucket = max(largest_found_bucket, bucket) |
| - if largestFoundBucket != maximumBucket: |
| + if largest_found_bucket != expected_max_bucket: |
| if input_api.is_committing: |
| message_type = output_api.PresubmitError |
| else: |
| @@ -42,9 +45,9 @@ def _RunUseCounterChecks(input_api, output_api): |
| return [message_type( |
| 'Largest found CSSProperty bucket Id (%d) does not match ' |
| - 'maximumCSSSampleId (%d)' % |
| - (largestFoundBucket, maximumBucket), |
| - items=[useCounterCpp.LocalPath()])] |
| + 'maximumCSSSampleId (%d)' % ( |
| + largest_found_bucket, expected_max_bucket), |
| + items=[use_counter_cpp_file.LocalPath()])] |
| return [] |