OLD | NEW |
---|---|
(Empty) | |
1 # Copyright (c) 2017 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 """Presubmit script for changes affecting chrome/android/webapk/shell_apk | |
6 | |
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts | |
8 for more details about the presubmit API built into depot_tools. | |
9 | |
10 This presubmit checks for two rules: | |
11 1. If anything in $ANDROID_MANIFEST_LOCAL_PATH, $RES_LOCAL_PATH, or | |
12 $SRC_LOCAL_PATH changes, $WAM_MINT_TRIGGER_VARIABLE in | |
13 $SHELL_APK_VERSION_LOCAL_PATH should be changed. | |
pkotwicz
2017/04/27 15:54:30
How about: "If anything in shell_apk/ directory ha
F
2017/04/27 18:31:56
Done.
| |
14 2. If $CHROME_UPDATE_TIRGGER_VARIABLE is changed in | |
15 $SHELL_APK_VERSION_LOCAL_PATH, $SHELL_APK_VERSION_LOCAL_PATH should be the | |
16 only changed file and changing $CHROME_UPDATE_TIRGGER_VARIABLE should be | |
hartmanng
2017/04/27 15:05:54
request: it might be good to go a step further her
F
2017/04/27 15:58:05
Presubmit needs to use lots of regexp to do this w
| |
17 the only change. | |
18 """ | |
19 | |
20 WAM_MINT_TRIGGER_VARIABLE = r'template_shell_apk_version' | |
21 CHROME_UPDATE_TRIGGER_VARIABLE = r'expected_shell_apk_version' | |
22 | |
23 ANDROID_MANIFEST_LOCAL_PATH = r'AndroidManifest.xml' | |
24 RES_LOCAL_PATH = r'res/' | |
25 SHELL_APK_VERSION_LOCAL_PATH = r'shell_apk_version.gni' | |
26 SRC_LOCAL_PATH = r'src/org/chromium/webapk/shell_apk/' | |
27 | |
28 | |
29 def _CheckChromeUpdateTriggerRule(input_api, output_api): | |
30 problems = [] | |
pkotwicz
2017/04/27 15:54:30
This variable is unused
F
2017/04/27 18:31:56
Done.
| |
31 | |
32 chrome_update_trigger_is_updated = False | |
pkotwicz
2017/04/27 15:54:30
This variable is unused
F
2017/04/27 18:31:56
Done.
| |
33 for f in input_api.AffectedFiles(): | |
34 local_path = input_api.os_path.relpath(f.AbsoluteLocalPath(), | |
35 input_api.PresubmitLocalPath()) | |
36 | |
37 if local_path == SHELL_APK_VERSION_LOCAL_PATH: | |
38 for line_num, line in f.ChangedContents(): | |
pkotwicz
2017/04/27 15:54:30
Can you move iterating through the changed content
F
2017/04/27 18:31:56
Done.
| |
39 if CHROME_UPDATE_TRIGGER_VARIABLE in line: | |
40 if (len(f.ChangedContents) != 1 or | |
41 len(input_api.AffectedFiles() != 1)): | |
42 return [ | |
43 output_api.PresubmitError( | |
44 '{} in {} must be updated in a standalone CL.'.format( | |
45 CHROME_UPDATE_TRIGGER_VARIABLE, | |
46 SHELL_APK_VERSION_LOCAL_PATH)) | |
47 ] | |
48 | |
49 return [] | |
50 | |
51 | |
52 def _CheckWamMintTriggerRule(input_api, output_api): | |
53 problems = [] | |
54 | |
55 wam_mint_trigger_updated_needed = False | |
hartmanng
2017/04/27 15:05:54
nit: s/updated_needed/update_needed/ (and elsewher
F
2017/04/27 15:58:05
Done.
| |
56 wam_mint_trigger_is_updated = False | |
57 for f in input_api.AffectedFiles(): | |
58 local_path = input_api.os_path.relpath(f.AbsoluteLocalPath(), | |
59 input_api.PresubmitLocalPath()) | |
60 | |
61 if (local_path == ANDROID_MANIFEST_LOCAL_PATH or | |
62 local_path.startswith(RES_LOCAL_PATH) or | |
63 local_path.startswith(SRC_LOCAL_PATH)): | |
64 wam_mint_trigger_updated_needed = True | |
65 problems.append(local_path) | |
66 elif local_path == SHELL_APK_VERSION_LOCAL_PATH: | |
67 for line_num, line in f.ChangedContents(): | |
68 if WAM_MINT_TRIGGER_VARIABLE in line: | |
69 wam_mint_trigger_is_updated = True | |
70 | |
71 if wam_mint_trigger_updated_needed and not wam_mint_trigger_is_updated: | |
72 return [output_api.PresubmitError( | |
73 '{} in {} needs to updated due to changes in:'.format( | |
74 WAM_MINT_TRIGGER_VARIABLE, SHELL_APK_VERSION_LOCAL_PATH), | |
75 items=problems)] | |
76 | |
77 return [] | |
78 | |
79 | |
80 def _CommonChecks(input_api, output_api): | |
81 """Checks common to both upload and commit.""" | |
82 result = [] | |
83 result.extend(_CheckChromeUpdateTriggerRule(input_api, output_api)) | |
84 result.extend(_CheckWamMintTriggerRule(input_api, output_api)) | |
85 | |
86 return result | |
87 | |
88 | |
89 def CheckChangeOnUpload(input_api, output_api): | |
90 return _CommonChecks(input_api, output_api) | |
91 | |
92 | |
93 def CheckChangeOnCommit(input_api, output_api): | |
94 return _CommonChecks(input_api, output_api) | |
OLD | NEW |