Ryan Tseng | 85ec17e | 2018-09-06 17:10:05 -0700 | [diff] [blame] | 1 | # Copyright (c) 2018 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 | |
btolsch | 9ba2371 | 2019-04-18 16:36:55 -0700 | [diff] [blame] | 6 | def _CheckDeps(input_api, output_api): |
| 7 | results = [] |
| 8 | import sys |
| 9 | original_sys_path = sys.path |
| 10 | try: |
| 11 | sys.path = sys.path + [input_api.os_path.join( |
| 12 | input_api.PresubmitLocalPath(), 'buildtools', 'checkdeps')] |
| 13 | import checkdeps |
| 14 | from cpp_checker import CppChecker |
| 15 | from rules import Rule |
| 16 | finally: |
| 17 | sys.path = original_sys_path |
| 18 | |
btolsch | 9ba2371 | 2019-04-18 16:36:55 -0700 | [diff] [blame] | 19 | deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath()) |
mark a. foltz | 743b620 | 2019-08-29 14:43:43 -0700 | [diff] [blame] | 20 | deps_checker.CheckDirectory(input_api.PresubmitLocalPath()) |
| 21 | deps_results = deps_checker.results_formatter.GetResults() |
| 22 | for violation in deps_results: |
| 23 | results.append(output_api.PresubmitError(violation)) |
btolsch | 9ba2371 | 2019-04-18 16:36:55 -0700 | [diff] [blame] | 24 | return results |
| 25 | |
| 26 | |
btolsch | 333aecd | 2019-04-18 16:21:23 -0700 | [diff] [blame] | 27 | def _CommonChecks(input_api, output_api): |
| 28 | results = [] |
Takumi Fujimoto | ebcffae | 2019-10-21 10:56:21 -0700 | [diff] [blame^] | 29 | # TODO(crbug.com/openscreen/43): Probably convert this to python so we can |
| 30 | # give more detailed errors. |
btolsch | 333aecd | 2019-04-18 16:21:23 -0700 | [diff] [blame] | 31 | presubmit_sh_result = input_api.subprocess.call( |
| 32 | input_api.PresubmitLocalPath() + '/PRESUBMIT.sh') |
| 33 | if presubmit_sh_result != 0: |
| 34 | results.append(output_api.PresubmitError('PRESUBMIT.sh failed')) |
btolsch | 9ba2371 | 2019-04-18 16:36:55 -0700 | [diff] [blame] | 35 | results.extend(_CheckDeps(input_api, output_api)) |
btolsch | 333aecd | 2019-04-18 16:21:23 -0700 | [diff] [blame] | 36 | return results |
| 37 | |
| 38 | |
Ryan Tseng | 85ec17e | 2018-09-06 17:10:05 -0700 | [diff] [blame] | 39 | def CheckChangeOnUpload(input_api, output_api): |
btolsch | 333aecd | 2019-04-18 16:21:23 -0700 | [diff] [blame] | 40 | results = [] |
| 41 | results.extend(_CommonChecks(input_api, output_api)) |
| 42 | results.extend( |
| 43 | input_api.canned_checks.CheckChangedLUCIConfigs(input_api, output_api)) |
| 44 | return results |
| 45 | |
| 46 | |
| 47 | def CheckChangeOnCommit(input_api, output_api): |
| 48 | results = [] |
| 49 | results.extend(_CommonChecks(input_api, output_api)) |
| 50 | return results |