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 shell_apk/ directory has changed (excluding test files), |
| 12 $WAM_MINT_TRIGGER_VARIABLE should be updated. |
| 13 2. If $CHROME_UPDATE_TIRGGER_VARIABLE is changed in |
| 14 $SHELL_APK_VERSION_LOCAL_PATH, $SHELL_APK_VERSION_LOCAL_PATH should be the |
| 15 only changed file and changing $CHROME_UPDATE_TIRGGER_VARIABLE should be |
| 16 the only change. |
| 17 """ |
| 18 |
| 19 WAM_MINT_TRIGGER_VARIABLE = r'template_shell_apk_version' |
| 20 CHROME_UPDATE_TRIGGER_VARIABLE = r'expected_shell_apk_version' |
| 21 |
| 22 ANDROID_MANIFEST_LOCAL_PATH = r'AndroidManifest.xml' |
| 23 RES_LOCAL_PATH = r'res/' |
| 24 SHELL_APK_VERSION_LOCAL_PATH = r'shell_apk_version.gni' |
| 25 SRC_LOCAL_PATH = r'src/org/chromium/webapk/shell_apk/' |
| 26 |
| 27 |
| 28 def _DoChangedContentsContain(changed_contents, key): |
| 29 for line_num, line in changed_contents: |
| 30 if key in line: |
| 31 return True |
| 32 return False |
| 33 |
| 34 |
| 35 def _CheckChromeUpdateTriggerRule(input_api, output_api): |
| 36 for f in input_api.AffectedFiles(): |
| 37 local_path = input_api.os_path.relpath(f.AbsoluteLocalPath(), |
| 38 input_api.PresubmitLocalPath()) |
| 39 |
| 40 if local_path == SHELL_APK_VERSION_LOCAL_PATH: |
| 41 if _DoChangedContentsContain(f.ChangedContents(), |
| 42 CHROME_UPDATE_TRIGGER_VARIABLE): |
| 43 if (len(f.ChangedContents()) != 1 or |
| 44 len(input_api.AffectedFiles()) != 1): |
| 45 return [ |
| 46 output_api.PresubmitError( |
| 47 '{} in {} must be updated in a standalone CL.'.format( |
| 48 CHROME_UPDATE_TRIGGER_VARIABLE, |
| 49 SHELL_APK_VERSION_LOCAL_PATH)) |
| 50 ] |
| 51 |
| 52 return [] |
| 53 |
| 54 |
| 55 def _CheckWamMintTriggerRule(input_api, output_api): |
| 56 problems = [] |
| 57 |
| 58 wam_mint_trigger_update_needed = False |
| 59 wam_mint_trigger_is_updated = False |
| 60 for f in input_api.AffectedFiles(): |
| 61 local_path = input_api.os_path.relpath(f.AbsoluteLocalPath(), |
| 62 input_api.PresubmitLocalPath()) |
| 63 |
| 64 if (local_path == ANDROID_MANIFEST_LOCAL_PATH or |
| 65 local_path.startswith(RES_LOCAL_PATH) or |
| 66 local_path.startswith(SRC_LOCAL_PATH)): |
| 67 wam_mint_trigger_update_needed = True |
| 68 problems.append(local_path) |
| 69 elif local_path == SHELL_APK_VERSION_LOCAL_PATH: |
| 70 if _DoChangedContentsContain(f.ChangedContents(), |
| 71 WAM_MINT_TRIGGER_VARIABLE): |
| 72 wam_mint_trigger_is_updated = True |
| 73 |
| 74 if wam_mint_trigger_update_needed and not wam_mint_trigger_is_updated: |
| 75 return [output_api.PresubmitError( |
| 76 '{} in {} needs to updated due to changes in:'.format( |
| 77 WAM_MINT_TRIGGER_VARIABLE, SHELL_APK_VERSION_LOCAL_PATH), |
| 78 items=problems)] |
| 79 |
| 80 return [] |
| 81 |
| 82 |
| 83 def _CommonChecks(input_api, output_api): |
| 84 """Checks common to both upload and commit.""" |
| 85 result = [] |
| 86 result.extend(_CheckChromeUpdateTriggerRule(input_api, output_api)) |
| 87 result.extend(_CheckWamMintTriggerRule(input_api, output_api)) |
| 88 |
| 89 return result |
| 90 |
| 91 |
| 92 def CheckChangeOnUpload(input_api, output_api): |
| 93 return _CommonChecks(input_api, output_api) |
| 94 |
| 95 |
| 96 def CheckChangeOnCommit(input_api, output_api): |
| 97 return _CommonChecks(input_api, output_api) |
OLD | NEW |