Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / PRESUBMIT.py
blob143ff1c09d4c2afa15f49928a9084cb084195e75
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
3 # found in the LICENSE file.
5 """Presubmit script for Chromium browser code.
7 This script currently checks HTML/CSS/JS files in resources/ and ui/webui/.
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 http://www.chromium.org/developers/web-development-style-guide for the rules
12 checked for here.
13 """
16 def CheckChangeOnUpload(input_api, output_api):
17 return _CommonChecks(input_api, output_api)
20 def CheckChangeOnCommit(input_api, output_api):
21 return _CommonChecks(input_api, output_api)
24 def _CommonChecks(input_api, output_api):
25 """Checks common to both upload and commit."""
26 results = []
28 path = input_api.os_path
29 cwd = input_api.PresubmitLocalPath()
30 resources = path.join(cwd, 'resources')
31 webui = path.join(cwd, 'ui', 'webui')
33 affected_files = (f.AbsoluteLocalPath() for f in input_api.AffectedFiles())
35 would_affect_tests = [
36 path.join(cwd, 'PRESUBMIT.py'),
37 path.join(cwd, 'test_presubmit.py'),
39 would_affect_tests += input_api.glob(path.join(cwd, 'web_dev_style', '*.py'))
41 if any(f for f in affected_files if f in would_affect_tests):
42 tests = [path.join(cwd, 'test_presubmit.py')]
43 results.extend(
44 input_api.canned_checks.RunUnitTests(input_api, output_api, tests))
46 import sys
47 old_path = sys.path
49 try:
50 sys.path = [cwd] + old_path
51 from web_dev_style import (resource_checker, css_checker, html_checker,
52 js_checker)
54 search_dirs = (resources, webui)
55 def _html_css_js_resource(p):
56 return p.endswith(('.html', '.css', '.js')) and p.startswith(search_dirs)
58 BLACKLIST = ['chrome/browser/resources/pdf/index.html',
59 'chrome/browser/resources/pdf/index.js']
60 def is_resource(maybe_resource):
61 return (maybe_resource.LocalPath() not in BLACKLIST and
62 _html_css_js_resource(maybe_resource.AbsoluteLocalPath()))
64 results.extend(resource_checker.ResourceChecker(
65 input_api, output_api, file_filter=is_resource).RunChecks())
66 results.extend(css_checker.CSSChecker(
67 input_api, output_api, file_filter=is_resource).RunChecks())
68 results.extend(html_checker.HtmlChecker(
69 input_api, output_api, file_filter=is_resource).RunChecks())
70 results.extend(js_checker.JSChecker(
71 input_api, output_api, file_filter=is_resource).RunChecks())
72 finally:
73 sys.path = old_path
75 return results