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

Unified Diff: content/common/PRESUBMIT.py

Issue 2852023002: Add PRESUMIT for accessibility_mode_enums values (Closed)
Patch Set: Address brettw's comments Created 3 years, 6 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 | « content/browser/resources/accessibility/accessibility.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/PRESUBMIT.py
diff --git a/content/common/PRESUBMIT.py b/content/common/PRESUBMIT.py
new file mode 100644
index 0000000000000000000000000000000000000000..5716b45c1a38ebf49f50520655af5b577c9c9f60
--- /dev/null
+++ b/content/common/PRESUBMIT.py
@@ -0,0 +1,89 @@
+# Copyright 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 content/common."""
+
+import os, re
+
+AX_JS_FILE = 'content/browser/resources/accessibility/accessibility.js'
+AX_MODE_HEADER = 'content/common/accessibility_mode.h'
+
+# Given a full path to c++ header, return an array of the first static
+# constexpr defined. (Note there can be more than one defined in a C++
+# header)
+def GetConstexprFromFile(fullpath):
+ values = []
+ for line in open(fullpath).readlines():
+ # Strip out comments
+ line = re.sub('//.*', '', line)
+
+ # Look for lines of the form "static constexpr <type> NAME "
+ m = re.search('static constexpr [\w]+ ([\w]+)', line)
+ if m:
+ values.append(m.group(1))
+
+ return values
+
+# Given a full path to js file, return the AccessibilityMode consts
+# defined
+def GetAccessibilityModesFromFile(fullpath):
+ values = []
+ inside = False
+ for line in open(fullpath).readlines():
+ # Strip out comments
+ line = re.sub('//.*', '', line)
+
+ # Look for the block of code that defines AccessibilityMode
+ m = re.search('const AccessibilityMode = {', line)
+ if m:
+ inside = True
+ continue
+
+ # Look for a "}" character signifying the end of an enum
+ if line.find('};') >= 0:
+ return values
+
+ if not inside:
+ continue
+
+ m = re.search('([\w]+):', line)
+ if m:
+ values.append(m.group(1))
+ continue
+
+ # getters
+ m = re.search('get ([\w]+)\(\)', line)
+ if m:
+ values.append(m.group(1))
+ return values
+
+# Make sure that the modes defined in the C++ header match those defined in
+# the js file. Note that this doesn't guarantee that the values are the same,
+# but does make sure if we add or remove we can signal to the developer that
+# they should be aware that this dependency exists.
+def CheckModesMatch(input_api, output_api):
+ errs = []
+ repo_root = input_api.change.RepositoryRoot()
+
+ ax_modes_in_header = GetConstexprFromFile(
+ os.path.join(repo_root,AX_MODE_HEADER))
+ ax_modes_in_js = GetAccessibilityModesFromFile(
+ os.path.join(repo_root, AX_JS_FILE))
+
+ for value in ax_modes_in_header:
+ if value not in ax_modes_in_js:
+ errs.append(output_api.PresubmitError(
+ 'Found %s in %s, but did not find %s in %s' % (
+ value, AX_MODE_HEADER, value, AX_JS_FILE)))
+ return errs
+
+def CheckChangeOnUpload(input_api, output_api):
+ if AX_MODE_HEADER not in input_api.LocalPaths():
+ return []
+ return CheckModesMatch(input_api, output_api)
+
+def CheckChangeOnCommit(input_api, output_api):
+ if AX_MODE_HEADER not in input_api.LocalPaths():
+ return []
+ return CheckModesMatch(input_api, output_api)
« no previous file with comments | « content/browser/resources/accessibility/accessibility.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698