blob: 94c146a4c2836f1b7319302a3bf7501f025561ec [file] [log] [blame]
[email protected]516dce22014-05-01 18:31:531# Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]54caefd2012-02-15 06:18:562# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
[email protected]516dce22014-05-01 18:31:535"""Presubmit script for Chromium browser code.
6
daniimms41930202015-04-13 15:59:507This script currently checks HTML/CSS/JS files in resources/ and ui/webui/.
[email protected]54caefd2012-02-15 06:18:568
9See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
tfarina78bb92f42015-01-31 00:20:4810for more details about the presubmit API built into depot_tools, and see
[email protected]54caefd2012-02-15 06:18:5611http://www.chromium.org/developers/web-development-style-guide for the rules
[email protected]516dce22014-05-01 18:31:5312checked for here.
[email protected]54caefd2012-02-15 06:18:5613"""
14
[email protected]54caefd2012-02-15 06:18:5615def CheckChangeOnUpload(input_api, output_api):
16 return _CommonChecks(input_api, output_api)
17
18
19def CheckChangeOnCommit(input_api, output_api):
20 return _CommonChecks(input_api, output_api)
21
dougtb53dc592017-02-01 16:25:0022def _RunHistogramChecks(input_api, output_api, histogram_name):
23 try:
24 # Setup sys.path so that we can call histrogram code
25 import sys
26 original_sys_path = sys.path
27 sys.path = sys.path + [input_api.os_path.join(
28 input_api.change.RepositoryRoot(),
29 'tools', 'metrics', 'histograms')]
30
alexmos7f7bae62017-04-05 21:15:0431 results = []
32
dougtb53dc592017-02-01 16:25:0033 import presubmit_bad_message_reasons
alexmos7f7bae62017-04-05 21:15:0434 results.extend(presubmit_bad_message_reasons.PrecheckBadMessage(input_api,
35 output_api, histogram_name))
36
37 import presubmit_scheme_histograms
38 results.extend(presubmit_scheme_histograms.
39 PrecheckShouldAllowOpenURLEnums(input_api, output_api))
40
41 return results
dougtb53dc592017-02-01 16:25:0042 except:
43 return [output_api.PresubmitError('Could not verify histogram!')]
44 finally:
45 sys.path = original_sys_path
46
[email protected]54caefd2012-02-15 06:18:5647
48def _CommonChecks(input_api, output_api):
49 """Checks common to both upload and commit."""
50 results = []
[email protected]54caefd2012-02-15 06:18:5651
52 path = input_api.os_path
[email protected]516dce22014-05-01 18:31:5353 cwd = input_api.PresubmitLocalPath()
54 resources = path.join(cwd, 'resources')
55 webui = path.join(cwd, 'ui', 'webui')
56
[email protected]b3347132012-03-22 03:36:0057 affected_files = (f.AbsoluteLocalPath() for f in input_api.AffectedFiles())
dbeama7b291292015-07-20 21:53:4858
59 would_affect_tests = [
[email protected]516dce22014-05-01 18:31:5360 path.join(cwd, 'PRESUBMIT.py'),
61 path.join(cwd, 'test_presubmit.py'),
dbeama7b291292015-07-20 21:53:4862 ]
63 would_affect_tests += input_api.glob(path.join(cwd, 'web_dev_style', '*.py'))
64
[email protected]b3347132012-03-22 03:36:0065 if any(f for f in affected_files if f in would_affect_tests):
[email protected]516dce22014-05-01 18:31:5366 tests = [path.join(cwd, 'test_presubmit.py')]
[email protected]54caefd2012-02-15 06:18:5667 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:
[email protected]516dce22014-05-01 18:31:5374 sys.path = [cwd] + old_path
estade422789b62014-09-06 01:33:3275 from web_dev_style import (resource_checker, css_checker, html_checker,
76 js_checker)
[email protected]54caefd2012-02-15 06:18:5677
[email protected]516dce22014-05-01 18:31:5378 search_dirs = (resources, webui)
[email protected]ffbeebf2013-03-21 04:20:3379 def _html_css_js_resource(p):
[email protected]516dce22014-05-01 18:31:5380 return p.endswith(('.html', '.css', '.js')) and p.startswith(search_dirs)
[email protected]a1ce93f2012-04-04 06:14:4981
tsergeantcf585f12016-09-23 02:35:4882 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 ]
[email protected]ffbeebf2013-03-21 04:20:3389 def is_resource(maybe_resource):
[email protected]d2600602014-02-19 00:09:1990 return (maybe_resource.LocalPath() not in BLACKLIST and
tsergeantcf585f12016-09-23 02:35:4891 not _vulcanized_resource(maybe_resource.LocalPath()) and
[email protected]d2600602014-02-19 00:09:1992 _html_css_js_resource(maybe_resource.AbsoluteLocalPath()))
[email protected]ffbeebf2013-03-21 04:20:3393
[email protected]633c60c2014-07-24 03:19:2394 results.extend(resource_checker.ResourceChecker(
95 input_api, output_api, file_filter=is_resource).RunChecks())
[email protected]ffbeebf2013-03-21 04:20:3396 results.extend(css_checker.CSSChecker(
[email protected]92d68042013-04-30 17:49:3497 input_api, output_api, file_filter=is_resource).RunChecks())
estade422789b62014-09-06 01:33:3298 results.extend(html_checker.HtmlChecker(
99 input_api, output_api, file_filter=is_resource).RunChecks())
[email protected]ffbeebf2013-03-21 04:20:33100 results.extend(js_checker.JSChecker(
101 input_api, output_api, file_filter=is_resource).RunChecks())
dougtb53dc592017-02-01 16:25:00102 results.extend(_RunHistogramChecks(input_api, output_api,
103 "BadMessageReasonChrome"))
[email protected]54caefd2012-02-15 06:18:56104 finally:
105 sys.path = old_path
106
107 return results