Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(454)

Side by Side Diff: PRESUBMIT.py

Issue 1354723004: [android] Change the recommended log tag format to "cr_foo" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix presubmit test broken by another CL Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | PRESUBMIT_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1335 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 ' org.chromium.ui.widget.Toast instead.\n' 1346 ' org.chromium.ui.widget.Toast instead.\n'
1347 'Contact dskiba@chromium.org if you have any questions.', 1347 'Contact dskiba@chromium.org if you have any questions.',
1348 errors)) 1348 errors))
1349 1349
1350 return results 1350 return results
1351 1351
1352 1352
1353 def _CheckAndroidCrLogUsage(input_api, output_api): 1353 def _CheckAndroidCrLogUsage(input_api, output_api):
1354 """Checks that new logs using org.chromium.base.Log: 1354 """Checks that new logs using org.chromium.base.Log:
1355 - Are using 'TAG' as variable name for the tags (warn) 1355 - Are using 'TAG' as variable name for the tags (warn)
1356 - Are using the suggested name format for the tags: "cr.<PackageTag>" (warn) 1356 - Are using a tag that is shorter than 20 characters (error)
1357 - Are using a tag that is shorter than 23 characters (error)
1358 """ 1357 """
1359 cr_log_import_pattern = input_api.re.compile( 1358 cr_log_import_pattern = input_api.re.compile(
1360 r'^import org\.chromium\.base\.Log;$', input_api.re.MULTILINE) 1359 r'^import org\.chromium\.base\.Log;$', input_api.re.MULTILINE)
1361 class_in_base_pattern = input_api.re.compile( 1360 class_in_base_pattern = input_api.re.compile(
1362 r'^package org\.chromium\.base;$', input_api.re.MULTILINE) 1361 r'^package org\.chromium\.base;$', input_api.re.MULTILINE)
1363 has_some_log_import_pattern = input_api.re.compile( 1362 has_some_log_import_pattern = input_api.re.compile(
1364 r'^import .*\.Log;$', input_api.re.MULTILINE) 1363 r'^import .*\.Log;$', input_api.re.MULTILINE)
1365 # Extract the tag from lines like `Log.d(TAG, "*");` or `Log.d("TAG", "*");` 1364 # Extract the tag from lines like `Log.d(TAG, "*");` or `Log.d("TAG", "*");`
1366 log_call_pattern = input_api.re.compile(r'^\s*Log\.\w\((?P<tag>\"?\w+\"?)\,') 1365 log_call_pattern = input_api.re.compile(r'^\s*Log\.\w\((?P<tag>\"?\w+\"?)\,')
1367 log_decl_pattern = input_api.re.compile( 1366 log_decl_pattern = input_api.re.compile(
1368 r'^\s*private static final String TAG = "(?P<name>(.*)")', 1367 r'^\s*private static final String TAG = "(?P<name>(.*))";',
1369 input_api.re.MULTILINE) 1368 input_api.re.MULTILINE)
1370 log_name_pattern = input_api.re.compile(r'^cr[.\w]*')
1371 1369
1372 REF_MSG = ('See docs/android_logging.md ' 1370 REF_MSG = ('See docs/android_logging.md '
1373 'or contact dgn@chromium.org for more info.') 1371 'or contact dgn@chromium.org for more info.')
1374 sources = lambda x: input_api.FilterSourceFile(x, white_list=(r'.*\.java$',)) 1372 sources = lambda x: input_api.FilterSourceFile(x, white_list=(r'.*\.java$',))
1375 1373
1376 tag_decl_errors = [] 1374 tag_decl_errors = []
1377 tag_length_errors = [] 1375 tag_length_errors = []
1378 tag_errors = [] 1376 tag_errors = []
1377 tag_with_dot_errors = []
1379 util_log_errors = [] 1378 util_log_errors = []
1380 1379
1381 for f in input_api.AffectedSourceFiles(sources): 1380 for f in input_api.AffectedSourceFiles(sources):
1382 file_content = input_api.ReadFile(f) 1381 file_content = input_api.ReadFile(f)
1383 has_modified_logs = False 1382 has_modified_logs = False
1384 1383
1385 # Per line checks 1384 # Per line checks
1386 if (cr_log_import_pattern.search(file_content) or 1385 if (cr_log_import_pattern.search(file_content) or
1387 (class_in_base_pattern.search(file_content) and 1386 (class_in_base_pattern.search(file_content) and
1388 not has_some_log_import_pattern.search(file_content))): 1387 not has_some_log_import_pattern.search(file_content))):
(...skipping 11 matching lines...) Expand all
1400 else: 1399 else:
1401 # Report non cr Log function calls in changed lines 1400 # Report non cr Log function calls in changed lines
1402 for line_num, line in f.ChangedContents(): 1401 for line_num, line in f.ChangedContents():
1403 if log_call_pattern.search(line): 1402 if log_call_pattern.search(line):
1404 util_log_errors.append("%s:%d" % (f.LocalPath(), line_num)) 1403 util_log_errors.append("%s:%d" % (f.LocalPath(), line_num))
1405 1404
1406 # Per file checks 1405 # Per file checks
1407 if has_modified_logs: 1406 if has_modified_logs:
1408 # Make sure the tag is using the "cr" prefix and is not too long 1407 # Make sure the tag is using the "cr" prefix and is not too long
1409 match = log_decl_pattern.search(file_content) 1408 match = log_decl_pattern.search(file_content)
1410 tag_name = match.group('name') if match else '' 1409 tag_name = match.group('name') if match else None
1411 if not log_name_pattern.search(tag_name ): 1410 if not tag_name:
1412 tag_decl_errors.append(f.LocalPath()) 1411 tag_decl_errors.append(f.LocalPath())
1413 if len(tag_name) > 23: 1412 elif len(tag_name) > 20:
1414 tag_length_errors.append(f.LocalPath()) 1413 tag_length_errors.append(f.LocalPath())
1414 elif '.' in tag_name:
1415 tag_with_dot_errors.append(f.LocalPath())
1415 1416
1416 results = [] 1417 results = []
1417 if tag_decl_errors: 1418 if tag_decl_errors:
1418 results.append(output_api.PresubmitPromptWarning( 1419 results.append(output_api.PresubmitPromptWarning(
1419 'Please define your tags using the suggested format: .\n' 1420 'Please define your tags using the suggested format: .\n'
1420 '"private static final String TAG = "cr.<package tag>".\n' + REF_MSG, 1421 '"private static final String TAG = "<package tag>".\n'
1422 'They will be prepended with "cr_" automatically.\n' + REF_MSG,
1421 tag_decl_errors)) 1423 tag_decl_errors))
1422 1424
1423 if tag_length_errors: 1425 if tag_length_errors:
1424 results.append(output_api.PresubmitError( 1426 results.append(output_api.PresubmitError(
1425 'The tag length is restricted by the system to be at most ' 1427 'The tag length is restricted by the system to be at most '
1426 '23 characters.\n' + REF_MSG, 1428 '20 characters.\n' + REF_MSG,
1427 tag_length_errors)) 1429 tag_length_errors))
1428 1430
1429 if tag_errors: 1431 if tag_errors:
1430 results.append(output_api.PresubmitPromptWarning( 1432 results.append(output_api.PresubmitPromptWarning(
1431 'Please use a variable named "TAG" for your log tags.\n' + REF_MSG, 1433 'Please use a variable named "TAG" for your log tags.\n' + REF_MSG,
1432 tag_errors)) 1434 tag_errors))
1433 1435
1434 if util_log_errors: 1436 if util_log_errors:
1435 results.append(output_api.PresubmitPromptWarning( 1437 results.append(output_api.PresubmitPromptWarning(
1436 'Please use org.chromium.base.Log for new logs.\n' + REF_MSG, 1438 'Please use org.chromium.base.Log for new logs.\n' + REF_MSG,
1437 util_log_errors)) 1439 util_log_errors))
1438 1440
1441 if tag_with_dot_errors:
1442 results.append(output_api.PresubmitPromptWarning(
1443 'Dot in log tags cause them to be elided in crash reports.\n' + REF_MSG,
1444 tag_with_dot_errors))
1445
1439 return results 1446 return results
1440 1447
1441 1448
1442 def _CheckForCopyrightedCode(input_api, output_api): 1449 def _CheckForCopyrightedCode(input_api, output_api):
1443 """Verifies that newly added code doesn't contain copyrighted material 1450 """Verifies that newly added code doesn't contain copyrighted material
1444 and is properly licensed under the standard Chromium license. 1451 and is properly licensed under the standard Chromium license.
1445 1452
1446 As there can be false positives, we maintain a whitelist file. This check 1453 As there can be false positives, we maintain a whitelist file. This check
1447 also verifies that the whitelist file is up to date. 1454 also verifies that the whitelist file is up to date.
1448 """ 1455 """
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
1921 for master in masters: 1928 for master in masters:
1922 try_config.setdefault(master, {}) 1929 try_config.setdefault(master, {})
1923 for builder in masters[master]: 1930 for builder in masters[master]:
1924 # Do not trigger presubmit builders, since they're likely to fail 1931 # Do not trigger presubmit builders, since they're likely to fail
1925 # (e.g. OWNERS checks before finished code review), and we're 1932 # (e.g. OWNERS checks before finished code review), and we're
1926 # running local presubmit anyway. 1933 # running local presubmit anyway.
1927 if 'presubmit' not in builder: 1934 if 'presubmit' not in builder:
1928 try_config[master][builder] = ['defaulttests'] 1935 try_config[master][builder] = ['defaulttests']
1929 1936
1930 return try_config 1937 return try_config
OLDNEW
« no previous file with comments | « no previous file | PRESUBMIT_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698