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

Side by Side Diff: chrome/browser/PRESUBMIT.py

Issue 2890513003: Move chrome/browser/web_dev_style/ to tools/ to use from more places (Closed)
Patch Set: tsergeant@ review Created 3 years, 7 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/OWNERS ('k') | chrome/browser/resources/PRESUBMIT.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Presubmit script for Chromium browser code. 5 """Presubmit script for Chromium browser code."""
6
7 This script currently checks HTML/CSS/JS files in resources/ and ui/webui/.
8
9 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
10 for more details about the presubmit API built into depot_tools, and see
11 https://chromium.googlesource.com/chromium/src/+/master/styleguide/web/web.md
12 for the rules checked for here.
13 """
14
15 def CheckChangeOnUpload(input_api, output_api):
16 return _CommonChecks(input_api, output_api)
17
18
19 def CheckChangeOnCommit(input_api, output_api):
20 return _CommonChecks(input_api, output_api)
21 6
22 def _RunHistogramChecks(input_api, output_api, histogram_name): 7 def _RunHistogramChecks(input_api, output_api, histogram_name):
23 try: 8 try:
24 # Setup sys.path so that we can call histograms code. 9 # Setup sys.path so that we can call histograms code.
25 import sys 10 import sys
26 original_sys_path = sys.path 11 original_sys_path = sys.path
27 sys.path = sys.path + [input_api.os_path.join( 12 sys.path = sys.path + [input_api.os_path.join(
28 input_api.change.RepositoryRoot(), 13 input_api.change.RepositoryRoot(),
29 'tools', 'metrics', 'histograms')] 14 'tools', 'metrics', 'histograms')]
30 15
31 results = [] 16 results = []
32 17
33 import presubmit_bad_message_reasons 18 import presubmit_bad_message_reasons
34 results.extend(presubmit_bad_message_reasons.PrecheckBadMessage(input_api, 19 results.extend(presubmit_bad_message_reasons.PrecheckBadMessage(input_api,
35 output_api, histogram_name)) 20 output_api, histogram_name))
36 21
37 import presubmit_scheme_histograms 22 import presubmit_scheme_histograms
38 results.extend(presubmit_scheme_histograms. 23 results.extend(presubmit_scheme_histograms.
39 PrecheckShouldAllowOpenURLEnums(input_api, output_api)) 24 PrecheckShouldAllowOpenURLEnums(input_api, output_api))
40 25
41 return results 26 return results
42 except: 27 except:
43 return [output_api.PresubmitError('Could not verify histogram!')] 28 return [output_api.PresubmitError('Could not verify histogram!')]
44 finally: 29 finally:
45 sys.path = original_sys_path 30 sys.path = original_sys_path
46 31
47 32
48 def _CommonChecks(input_api, output_api): 33 def _CommonChecks(input_api, output_api):
49 """Checks common to both upload and commit.""" 34 """Checks common to both upload and commit."""
50 results = [] 35 return _RunHistogramChecks(input_api, output_api, "BadMessageReasonChrome")
51 36
52 path = input_api.os_path
53 cwd = input_api.PresubmitLocalPath()
54 resources = path.join(cwd, 'resources')
55 webui = path.join(cwd, 'ui', 'webui')
56 37
57 affected_files = (f.AbsoluteLocalPath() for f in input_api.AffectedFiles()) 38 def CheckChangeOnUpload(input_api, output_api):
39 return _CommonChecks(input_api, output_api)
58 40
59 would_affect_tests = [
60 path.join(cwd, 'PRESUBMIT.py'),
61 path.join(cwd, 'test_presubmit.py'),
62 ]
63 would_affect_tests += input_api.glob(path.join(cwd, 'web_dev_style', '*.py'))
64 41
65 if any(f for f in affected_files if f in would_affect_tests): 42 def CheckChangeOnCommit(input_api, output_api):
66 tests = [path.join(cwd, 'test_presubmit.py')] 43 return _CommonChecks(input_api, output_api)
67 results.extend(
68 input_api.canned_checks.RunUnitTests(input_api, output_api, tests))
69
70 import sys
71 old_path = sys.path
72
73 try:
74 sys.path = [cwd] + old_path
75 from web_dev_style import (resource_checker, css_checker, html_checker,
76 js_checker)
77
78 search_dirs = (resources, webui)
79 def _html_css_js_resource(p):
80 return p.endswith(('.html', '.css', '.js')) and p.startswith(search_dirs)
81
82 def _vulcanized_resource(p):
83 return p.endswith(('vulcanized.html', 'crisper.js'))
84
85 BLACKLIST = [
86 'chrome/browser/resources/pdf/index.html',
87 'chrome/browser/resources/pdf/index.js'
88 ]
89 def is_resource(maybe_resource):
90 return (maybe_resource.LocalPath() not in BLACKLIST and
91 not _vulcanized_resource(maybe_resource.LocalPath()) and
92 _html_css_js_resource(maybe_resource.AbsoluteLocalPath()))
93
94 results.extend(resource_checker.ResourceChecker(
95 input_api, output_api, file_filter=is_resource).RunChecks())
96 results.extend(css_checker.CSSChecker(
97 input_api, output_api, file_filter=is_resource).RunChecks())
98 results.extend(html_checker.HtmlChecker(
99 input_api, output_api, file_filter=is_resource).RunChecks())
100 results.extend(js_checker.JSChecker(
101 input_api, output_api, file_filter=is_resource).RunChecks())
102 results.extend(_RunHistogramChecks(input_api, output_api,
103 "BadMessageReasonChrome"))
104 finally:
105 sys.path = old_path
106
107 return results
OLDNEW
« no previous file with comments | « chrome/browser/OWNERS ('k') | chrome/browser/resources/PRESUBMIT.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698