1 # Copyright 2015 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 5 """Top-level presubmit script for catapult. 6 7 See https://www.chromium.org/developers/how-tos/depottools/presubmit-scripts 8 for more details about the presubmit API built into depot_tools. 9 """ 10 import re 11 import sys 12 13 _EXCLUDED_PATHS = ( 14 r'(.*[\\/])?\.git[\\/].*', 15 r'.+\.png$', 16 r'.+\.svg$', 17 r'.+\.skp$', 18 r'.+\.gypi$', 19 r'.+\.gyp$', 20 r'.+\.gn$', 21 r'.*\.gitignore$', 22 r'.*codereview.settings$', 23 r'.*AUTHOR$', 24 r'^CONTRIBUTORS\.md$', 25 r'.*LICENSE$', 26 r'.*OWNERS$', 27 r'.*README\.md$', 28 r'^dashboard[\\/]dashboard[\\/]templates[\\/].*', 29 r'^experimental[\\/]heatmap[\\/].*', 30 r'^perf_insights[\\/]test_data[\\/].*', 31 r'^perf_insights[\\/]third_party[\\/].*', 32 r'^third_party[\\/].*', 33 r'^tracing[\\/]\.allow-devtools-save$', 34 r'^tracing[\\/]bower\.json$', 35 r'^tracing[\\/]\.bowerrc$', 36 r'^tracing[\\/]tracing_examples[\\/]string_convert\.js$', 37 r'^tracing[\\/]test_data[\\/].*', 38 r'^tracing[\\/]third_party[\\/].*', 39 r'^telemetry[\\/]support[\\/]html_output[\\/]results-template.html', 40 ) 41 42 43 def GetPreferredTryMasters(project, change): 44 return { 45 'tryserver.client.catapult': { 46 'Catapult Linux Tryserver': {'defaulttests'}, 47 'Catapult Mac Tryserver': {'defaulttests'}, 48 'Catapult Windows Tryserver': {'defaulttests'}, 49 } 50 } 51 52 53 def CheckChangeLogBug(input_api, output_api): 54 if input_api.change.BUG is None or re.match( 55 r'((chromium\:|catapult\:\#)\d+)(,\s*(chromium\:|catapult\:\#)\d+)*$', 56 input_api.change.BUG): 57 return [] 58 return [output_api.PresubmitError( 59 ('Invalid bug "%s". Chromium issues should be prefixed with "chromium:" ' 60 'and Catapult issues should be prefixed with "catapult:#".' % 61 input_api.change.BUG))] 62 63 64 def CheckChange(input_api, output_api): 65 results = [] 66 try: 67 sys.path += [input_api.PresubmitLocalPath()] 68 from catapult_build import js_checks 69 from catapult_build import html_checks 70 from catapult_build import repo_checks 71 results += input_api.canned_checks.PanProjectChecks( 72 input_api, output_api, excluded_paths=_EXCLUDED_PATHS) 73 results += CheckChangeLogBug(input_api, output_api) 74 results += js_checks.RunChecks( 75 input_api, output_api, excluded_paths=_EXCLUDED_PATHS) 76 results += html_checks.RunChecks( 77 input_api, output_api, excluded_paths=_EXCLUDED_PATHS) 78 results += repo_checks.RunChecks(input_api, output_api) 79 finally: 80 sys.path.remove(input_api.PresubmitLocalPath()) 81 return results 82 83 84 def CheckChangeOnUpload(input_api, output_api): 85 return CheckChange(input_api, output_api) 86 87 88 def CheckChangeOnCommit(input_api, output_api): 89 return CheckChange(input_api, output_api) 90