1# Copyright (c) 2012 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. 4 5import os 6_EXCLUDED_PATHS = [] 7 8_LICENSE_HEADER = ( 9 r".*? Copyright \(c\) 20\d\d The Chromium Authors\. All rights reserved\." 10 "\n" 11 r".*? Use of this source code is governed by a BSD-style license that can " 12 "be\n" 13 r".*? found in the LICENSE file\." 14 "\n" 15) 16 17def _CheckIfAboutTracingIsOutOfdate(input_api, output_api): 18 import build.generate_about_tracing_contents as generator1 19 import build.generate_deps_js_contents as generator2 20 import build.parse_deps 21 22 try: 23 out_of_date = (generator1.is_out_of_date() or 24 generator2.is_out_of_date()) 25 except build.parse_deps.DepsException, ex: 26 return [output_api.PresubmitError(str(ex))] 27 28 if out_of_date: 29 return [output_api.PresubmitError( 30 'This change affects module depenencies. You need to run' 31 ' ./build/calcdeps.py')] 32 return [] 33 34def _CommonChecks(input_api, output_api): 35 results = [] 36 results.extend(input_api.canned_checks.PanProjectChecks( 37 input_api, output_api, excluded_paths=_EXCLUDED_PATHS)) 38 results.extend(_CheckIfAboutTracingIsOutOfdate(input_api, output_api)) 39 40 from web_dev_style import css_checker, js_checker 41 42 src_dir = os.path.join(input_api.change.RepositoryRoot(), "src") 43 FILES_TO_NOT_LINT = [ 44 input_api.os_path.join(src_dir, "about_tracing.js"), 45 input_api.os_path.join(src_dir, "deps.js"), 46 ] 47 48 def IsResource(maybe_resource): 49 f = maybe_resource.AbsoluteLocalPath() 50 print f 51 if not f.endswith(('.css', '.html', '.js')): 52 return False 53 for ignored in FILES_TO_NOT_LINT: 54 if input_api.os_path.samefile(f, ignored): 55 return False 56 return True 57 58 59 results.extend(css_checker.CSSChecker(input_api, output_api, 60 file_filter=IsResource).RunChecks()) 61 results.extend(js_checker.JSChecker(input_api, output_api, 62 file_filter=IsResource).RunChecks()) 63 64 black_list = input_api.DEFAULT_BLACK_LIST 65 sources = lambda x: input_api.FilterSourceFile(x, black_list=black_list) 66 results.extend(input_api.canned_checks.CheckLicense( 67 input_api, output_api, _LICENSE_HEADER, 68 source_file_filter=sources)) 69 return results 70 71def GetPathsToPrepend(input_api): 72 web_dev_style_path = input_api.os_path.join( 73 input_api.change.RepositoryRoot(), 74 "third_party", 75 "web_dev_style") 76 return [input_api.PresubmitLocalPath(), web_dev_style_path] 77 78def RunWithPrependedPath(prepended_path, fn, *args): 79 import sys 80 old_path = sys.path 81 82 try: 83 sys.path = prepended_path + old_path 84 return fn(*args) 85 finally: 86 sys.path = old_path 87 88def CheckChangeOnUpload(input_api, output_api): 89 def go(): 90 results = [] 91 results.extend(_CommonChecks(input_api, output_api)) 92 return results 93 return RunWithPrependedPath(GetPathsToPrepend(input_api), go) 94 95def CheckChangeOnCommit(input_api, output_api): 96 def go(): 97 results = [] 98 results.extend(_CommonChecks(input_api, output_api)) 99 return results 100 return RunWithPrependedPath(GetPathsToPrepend(input_api), go) 101