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

Unified Diff: chrome/android/webapk/shell_apk/PRESUBMIT.py

Issue 2830343002: Add PRESUBMIT script to enforce WebAPK shell apk version update (Closed)
Patch Set: New rules :) Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/webapk/shell_apk/PRESUBMIT.py
diff --git a/chrome/android/webapk/shell_apk/PRESUBMIT.py b/chrome/android/webapk/shell_apk/PRESUBMIT.py
new file mode 100644
index 0000000000000000000000000000000000000000..83dcc80aad0ccdaebca890868a39e4d4e38b74b1
--- /dev/null
+++ b/chrome/android/webapk/shell_apk/PRESUBMIT.py
@@ -0,0 +1,94 @@
+# Copyright (c) 2017 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Presubmit script for changes affecting chrome/android/webapk/shell_apk
+
+See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
+for more details about the presubmit API built into depot_tools.
+
+This presubmit checks for two rules:
+1. If anything in $ANDROID_MANIFEST_LOCAL_PATH, $RES_LOCAL_PATH, or
+$SRC_LOCAL_PATH changes, $WAM_MINT_TRIGGER_VARIABLE in
+$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.
+2. If $CHROME_UPDATE_TIRGGER_VARIABLE is changed in
+$SHELL_APK_VERSION_LOCAL_PATH, $SHELL_APK_VERSION_LOCAL_PATH should be the
+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
+the only change.
+"""
+
+WAM_MINT_TRIGGER_VARIABLE = r'template_shell_apk_version'
+CHROME_UPDATE_TRIGGER_VARIABLE = r'expected_shell_apk_version'
+
+ANDROID_MANIFEST_LOCAL_PATH = r'AndroidManifest.xml'
+RES_LOCAL_PATH = r'res/'
+SHELL_APK_VERSION_LOCAL_PATH = r'shell_apk_version.gni'
+SRC_LOCAL_PATH = r'src/org/chromium/webapk/shell_apk/'
+
+
+def _CheckChromeUpdateTriggerRule(input_api, output_api):
+ problems = []
pkotwicz 2017/04/27 15:54:30 This variable is unused
F 2017/04/27 18:31:56 Done.
+
+ 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.
+ for f in input_api.AffectedFiles():
+ local_path = input_api.os_path.relpath(f.AbsoluteLocalPath(),
+ input_api.PresubmitLocalPath())
+
+ if local_path == SHELL_APK_VERSION_LOCAL_PATH:
+ 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.
+ if CHROME_UPDATE_TRIGGER_VARIABLE in line:
+ if (len(f.ChangedContents) != 1 or
+ len(input_api.AffectedFiles() != 1)):
+ return [
+ output_api.PresubmitError(
+ '{} in {} must be updated in a standalone CL.'.format(
+ CHROME_UPDATE_TRIGGER_VARIABLE,
+ SHELL_APK_VERSION_LOCAL_PATH))
+ ]
+
+ return []
+
+
+def _CheckWamMintTriggerRule(input_api, output_api):
+ problems = []
+
+ 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.
+ wam_mint_trigger_is_updated = False
+ for f in input_api.AffectedFiles():
+ local_path = input_api.os_path.relpath(f.AbsoluteLocalPath(),
+ input_api.PresubmitLocalPath())
+
+ if (local_path == ANDROID_MANIFEST_LOCAL_PATH or
+ local_path.startswith(RES_LOCAL_PATH) or
+ local_path.startswith(SRC_LOCAL_PATH)):
+ wam_mint_trigger_updated_needed = True
+ problems.append(local_path)
+ elif local_path == SHELL_APK_VERSION_LOCAL_PATH:
+ for line_num, line in f.ChangedContents():
+ if WAM_MINT_TRIGGER_VARIABLE in line:
+ wam_mint_trigger_is_updated = True
+
+ if wam_mint_trigger_updated_needed and not wam_mint_trigger_is_updated:
+ return [output_api.PresubmitError(
+ '{} in {} needs to updated due to changes in:'.format(
+ WAM_MINT_TRIGGER_VARIABLE, SHELL_APK_VERSION_LOCAL_PATH),
+ items=problems)]
+
+ return []
+
+
+def _CommonChecks(input_api, output_api):
+ """Checks common to both upload and commit."""
+ result = []
+ result.extend(_CheckChromeUpdateTriggerRule(input_api, output_api))
+ result.extend(_CheckWamMintTriggerRule(input_api, output_api))
+
+ return result
+
+
+def CheckChangeOnUpload(input_api, output_api):
+ return _CommonChecks(input_api, output_api)
+
+
+def CheckChangeOnCommit(input_api, output_api):
+ return _CommonChecks(input_api, output_api)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698