blob: 6ab05a91f194c922e68ff3ddb19d177f299d19ef [file] [log] [blame]
pauljensenc3a04232015-08-14 17:21:011# Copyright 2015 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"""Top-level presubmit script for src/components/cronet.
6
7See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8for more details about the presubmit API built into depot_tools.
9"""
10
pauljensen6c178be2016-11-18 23:06:5611import re
12
13
pauljensen6a6e7832016-05-05 15:43:0314def _PyLintChecks(input_api, output_api):
15 pylint_checks = input_api.canned_checks.GetPylint(input_api, output_api,
16 extra_paths_list=_GetPathsToPrepend(input_api), pylintrc='pylintrc')
17 return input_api.RunTests(pylint_checks)
18
pauljensen6c178be2016-11-18 23:06:5619
pauljensen6a6e7832016-05-05 15:43:0320def _GetPathsToPrepend(input_api):
21 current_dir = input_api.PresubmitLocalPath()
22 chromium_src_dir = input_api.os_path.join(current_dir, '..', '..')
23 return [
24 input_api.os_path.join(current_dir, 'tools'),
25 input_api.os_path.join(current_dir, 'android', 'test', 'javaperftests'),
26 input_api.os_path.join(chromium_src_dir, 'tools', 'perf'),
27 input_api.os_path.join(chromium_src_dir, 'build', 'android'),
28 input_api.os_path.join(chromium_src_dir, 'build', 'android', 'gyp', 'util'),
29 input_api.os_path.join(chromium_src_dir, 'net', 'tools', 'net_docs'),
30 input_api.os_path.join(chromium_src_dir, 'tools'),
31 input_api.os_path.join(chromium_src_dir, 'third_party'),
32 input_api.os_path.join(chromium_src_dir,
33 'third_party', 'catapult', 'telemetry'),
34 input_api.os_path.join(chromium_src_dir,
35 'third_party', 'catapult', 'devil'),
36 ]
37
pauljensen6c178be2016-11-18 23:06:5638
pauljensen17ebec652016-09-14 18:53:2239def _PackageChecks(input_api, output_api):
40 """Verify API classes are in org.chromium.net package, and implementation
41 classes are not in org.chromium.net package."""
42 api_file_pattern = input_api.re.compile(
43 r'^components/cronet/android/api/.*\.(java|template)$')
44 impl_file_pattern = input_api.re.compile(
45 r'^components/cronet/android/java/.*\.(java|template)$')
46 api_package_pattern = input_api.re.compile(r'^package (?!org.chromium.net;)')
47 impl_package_pattern = input_api.re.compile(r'^package org.chromium.net;')
48
49 source_filter = lambda path: input_api.FilterSourceFile(path,
50 white_list=[r'^components/cronet/android/.*\.(java|template)$'])
51
52 problems = []
53 for f in input_api.AffectedSourceFiles(source_filter):
54 local_path = f.LocalPath()
55 for line_number, line in f.ChangedContents():
56 if (api_file_pattern.search(local_path)):
57 if (api_package_pattern.search(line)):
58 problems.append(
59 '%s:%d\n %s' % (local_path, line_number, line.strip()))
60 elif (impl_file_pattern.search(local_path)):
61 if (impl_package_pattern.search(line)):
62 problems.append(
63 '%s:%d\n %s' % (local_path, line_number, line.strip()))
64
65 if problems:
66 return [output_api.PresubmitError(
67 'API classes must be in org.chromium.net package, and implementation\n'
68 'classes must not be in org.chromium.net package.',
69 problems)]
70 else:
71 return []
72
pauljensen6c178be2016-11-18 23:06:5673
pauljensenc3a04232015-08-14 17:21:0174def CheckChangeOnUpload(input_api, output_api):
pauljensen6a6e7832016-05-05 15:43:0375 results = []
76 results.extend(_PyLintChecks(input_api, output_api))
77 results.extend(
78 input_api.canned_checks.CheckPatchFormatted(input_api, output_api))
pauljensen17ebec652016-09-14 18:53:2279 results.extend(_PackageChecks(input_api, output_api))
pauljensen6a6e7832016-05-05 15:43:0380 return results
pauljensen6c178be2016-11-18 23:06:5681
82
83def _GetTryMasters(project, change):
84 return {
85 'master.tryserver.chromium.android': {
86 'android_cronet_tester': [],
87 },
88 }
89
90
91def GetPreferredTryMasters(project, change):
92 # TODO(nick, dcheng): Using the value of _GetTryMasters() instead of an empty
93 # value here would cause 'git cl try' to include the Cronet trybot,
94 # which would be nice. But it has the side effect of replacing, rather than
95 # augmenting, the default set of try servers. Re-enable this when we figure
96 # out a way to augment the default set.
97 return {}
98
99
100def PostUploadHook(cl, change, output_api):
101 """git cl upload will call this hook after the issue is created/modified.
102
103 This hook adds an extra try bot to the CL description in order to run Cronet
104 tests in addition to CQ try bots.
105 """
106 rietveld_obj = cl.RpcServer()
107 issue = cl.issue
108 description = rietveld_obj.get_description(issue)
109 if re.search(r'^CQ_INCLUDE_TRYBOTS=.*', description, re.M | re.I):
110 return []
111
112 masters = _GetTryMasters(None, change)
113 results = []
114 new_description = description
115 new_description += '\nCQ_INCLUDE_TRYBOTS=%s' % ';'.join(
116 '%s:%s' % (master, ','.join(bots))
117 for master, bots in masters.iteritems())
118 results.append(output_api.PresubmitNotifyResult(
119 'Automatically added Cronet trybot to run tests on CQ.'))
120
121 rietveld_obj.update_description(issue, new_description)
122
123 return results