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 Chromium. | 5 """Top-level presubmit script for Chromium. |
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 depot_tools. | 8 for more details about the presubmit API built into depot_tools. |
9 """ | 9 """ |
10 | 10 |
(...skipping 1294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1305 import checkstyle | 1305 import checkstyle |
1306 finally: | 1306 finally: |
1307 # Restore sys.path to what it was before. | 1307 # Restore sys.path to what it was before. |
1308 sys.path = original_sys_path | 1308 sys.path = original_sys_path |
1309 | 1309 |
1310 return checkstyle.RunCheckstyle( | 1310 return checkstyle.RunCheckstyle( |
1311 input_api, output_api, 'tools/android/checkstyle/chromium-style-5.0.xml', | 1311 input_api, output_api, 'tools/android/checkstyle/chromium-style-5.0.xml', |
1312 black_list=_EXCLUDED_PATHS + input_api.DEFAULT_BLACK_LIST) | 1312 black_list=_EXCLUDED_PATHS + input_api.DEFAULT_BLACK_LIST) |
1313 | 1313 |
1314 | 1314 |
1315 def _CheckAndroidToastUsage(input_api, output_api): | |
1316 """Checks that Chromium code uses org.chromium.ui.widget.Toast | |
1317 instead of android.widget.Toast (Chromium Toast doesn't force hardware | |
1318 acceleration on low-end devices, saving memory). | |
1319 """ | |
1320 toast_import_pattern = input_api.re.compile( | |
1321 r'^import android\.widget\.Toast;$') | |
1322 | |
1323 import_errors = [] | |
1324 | |
1325 sources = lambda x: input_api.FilterSourceFile(x, white_list=(r'.*\.java$',)) | |
1326 for f in input_api.AffectedSourceFiles(sources): | |
1327 for line_num, line in f.ChangedContents(): | |
1328 if toast_import_pattern.search(line): | |
1329 import_errors.append("%s:%d" % (f.LocalPath(), line_num)) | |
1330 | |
1331 results = [] | |
1332 if import_errors: | |
1333 results.append(output_api.PresubmitPromptWarning( | |
1334 '"android.widget.Toast" usage is detected. Android toasts use hardware' | |
Dmitry Skiba
2015/08/11 23:49:50
Example output:
** Presubmit Warnings **
"android
| |
1335 ' acceleration, and can be\ncostly on low-end devices. If your code' | |
1336 ' triggers toasts on low-end devices (especially during\nnormal' | |
1337 ' browsing workflow), you should use "org.chromium.ui.widget.Toast"' | |
1338 ' instead.\n' | |
1339 "You don't need to bother if toast is shown only from an activity that" | |
1340 ' is hardware accelerated\n(e.g. Preferences) or the one that is not' | |
1341 ' visible to the end user (e.g. ChromeShellActivity).\n' | |
1342 'In any case, feel free to contact dskiba@chromium.org if you have any' | |
1343 ' questions or concerns.', | |
1344 import_errors)) | |
1345 | |
1346 return results | |
1347 | |
1348 | |
1315 def _CheckAndroidCrLogUsage(input_api, output_api): | 1349 def _CheckAndroidCrLogUsage(input_api, output_api): |
1316 """Checks that new logs using org.chromium.base.Log: | 1350 """Checks that new logs using org.chromium.base.Log: |
1317 - Are using 'TAG' as variable name for the tags (warn) | 1351 - Are using 'TAG' as variable name for the tags (warn) |
1318 - Are using the suggested name format for the tags: "cr.<PackageTag>" (warn) | 1352 - Are using the suggested name format for the tags: "cr.<PackageTag>" (warn) |
1319 - Are using a tag that is shorter than 23 characters (error) | 1353 - Are using a tag that is shorter than 23 characters (error) |
1320 """ | 1354 """ |
1321 cr_log_import_pattern = input_api.re.compile( | 1355 cr_log_import_pattern = input_api.re.compile( |
1322 r'^import org\.chromium\.base\.Log;$', input_api.re.MULTILINE) | 1356 r'^import org\.chromium\.base\.Log;$', input_api.re.MULTILINE) |
1323 class_in_base_pattern = input_api.re.compile( | 1357 class_in_base_pattern = input_api.re.compile( |
1324 r'^package org\.chromium\.base;$', input_api.re.MULTILINE) | 1358 r'^package org\.chromium\.base;$', input_api.re.MULTILINE) |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1523 results.append(output_api.PresubmitError( | 1557 results.append(output_api.PresubmitError( |
1524 "%s:%d: Use of deprecated JS %s, use %s instead" % | 1558 "%s:%d: Use of deprecated JS %s, use %s instead" % |
1525 (fpath.LocalPath(), lnum, deprecated, replacement))) | 1559 (fpath.LocalPath(), lnum, deprecated, replacement))) |
1526 return results | 1560 return results |
1527 | 1561 |
1528 | 1562 |
1529 def _AndroidSpecificOnUploadChecks(input_api, output_api): | 1563 def _AndroidSpecificOnUploadChecks(input_api, output_api): |
1530 """Groups checks that target android code.""" | 1564 """Groups checks that target android code.""" |
1531 results = [] | 1565 results = [] |
1532 results.extend(_CheckAndroidCrLogUsage(input_api, output_api)) | 1566 results.extend(_CheckAndroidCrLogUsage(input_api, output_api)) |
1567 results.extend(_CheckAndroidToastUsage(input_api, output_api)) | |
1533 return results | 1568 return results |
1534 | 1569 |
1535 | 1570 |
1536 def _CommonChecks(input_api, output_api): | 1571 def _CommonChecks(input_api, output_api): |
1537 """Checks common to both upload and commit.""" | 1572 """Checks common to both upload and commit.""" |
1538 results = [] | 1573 results = [] |
1539 results.extend(input_api.canned_checks.PanProjectChecks( | 1574 results.extend(input_api.canned_checks.PanProjectChecks( |
1540 input_api, output_api, | 1575 input_api, output_api, |
1541 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS)) | 1576 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS)) |
1542 results.extend(_CheckAuthorizedAuthor(input_api, output_api)) | 1577 results.extend(_CheckAuthorizedAuthor(input_api, output_api)) |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1882 for master in masters: | 1917 for master in masters: |
1883 try_config.setdefault(master, {}) | 1918 try_config.setdefault(master, {}) |
1884 for builder in masters[master]: | 1919 for builder in masters[master]: |
1885 # Do not trigger presubmit builders, since they're likely to fail | 1920 # Do not trigger presubmit builders, since they're likely to fail |
1886 # (e.g. OWNERS checks before finished code review), and we're | 1921 # (e.g. OWNERS checks before finished code review), and we're |
1887 # running local presubmit anyway. | 1922 # running local presubmit anyway. |
1888 if 'presubmit' not in builder: | 1923 if 'presubmit' not in builder: |
1889 try_config[master][builder] = ['defaulttests'] | 1924 try_config[master][builder] = ['defaulttests'] |
1890 | 1925 |
1891 return try_config | 1926 return try_config |
OLD | NEW |