OLD | NEW |
(Empty) | |
| 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 |
| 3 # found in the LICENSE file. |
| 4 |
| 5 """Blink frame presubmit script |
| 6 |
| 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| 8 for more details about the presubmit API built into gcl. |
| 9 """ |
| 10 |
| 11 |
| 12 def _RunUseCounterChecks(input_api, output_api): |
| 13 for f in input_api.AffectedFiles(): |
| 14 if f.LocalPath().endswith('UseCounter.cpp'): |
| 15 useCounterCpp = f |
| 16 break |
| 17 else: |
| 18 return [] |
| 19 |
| 20 largestFoundBucket = 0 |
| 21 maximumBucket = 0 |
| 22 # Looking for a line like "case CSSPropertyGrid: return 453;" |
| 23 bucketFinder = input_api.re.compile(r'.*CSSProperty.*return\s*([0-9]+).*') |
| 24 # Looking for a line like "static int maximumCSSSampleId() { return 452; }" |
| 25 maximumFinder = input_api.re.compile( |
| 26 r'static int maximumCSSSampleId\(\) { return ([0-9]+)') |
| 27 for line in useCounterCpp.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 |
| 37 if largestFoundBucket != maximumBucket: |
| 38 if input_api.is_committing: |
| 39 message_type = output_api.PresubmitError |
| 40 else: |
| 41 message_type = output_api.PresubmitPromptWarning |
| 42 |
| 43 return [message_type( |
| 44 'Largest found CSSProperty bucket Id (%d) does not match ' |
| 45 'maximumCSSSampleId (%d)' % |
| 46 (largestFoundBucket, maximumBucket), |
| 47 items=[useCounterCpp.LocalPath()])] |
| 48 |
| 49 return [] |
| 50 |
| 51 |
| 52 def CheckChangeOnUpload(input_api, output_api): |
| 53 return _RunUseCounterChecks(input_api, output_api) |
| 54 |
| 55 |
| 56 def CheckChangeOnCommit(input_api, output_api): |
| 57 return _RunUseCounterChecks(input_api, output_api) |
OLD | NEW |