blob: ae10063e7d5a191ff111db30cf7be61c45b065c2 [file] [log] [blame]
Corentin Wallez4c351012018-08-27 10:10:28 +02001# Copyright 2018 The Dawn Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import os
16import platform
17import subprocess
18
19def _DoClangFormat(input_api, output_api):
20 # Our binary clang-format is a linux binary compiled for x64
21 if platform.system() != 'Linux' or platform.architecture()[0] != '64bit':
22 return [output_api.PresubmitNotifyResult('Skipping clang-format')]
23
24 # We need to know which commit to diff against. It doesn't seem to be exposed anywhere
25 # except in that private member of presubmit_support.Change. This is likely to break
26 # but hopefully we have an updated clang-format in CPID/GS before it does.
27 upstream_commit = input_api.change._upstream
28 if upstream_commit == None:
29 return []
30
31 lint_cmd = [
32 'scripts/lint_clang_format.sh',
33 'third_party/clang-format/clang-format',
34 upstream_commit
35 ]
36
37 # Make clang-format use our linux x64 sysroot because it is compiled with a version of
38 # stdlibc++ that's incompatible with the old libraries present on the bots.
39 env = {
40 'LD_LIBRARY_PATH': os.path.join(
41 os.getcwd(),
42 'build',
43 'linux',
44 'debian_sid_amd64-sysroot',
45 'usr',
46 'lib',
47 'x86_64-linux-gnu'
48 )
49 }
50
51 # Call the linting script and forward the output as a notification or as an error
52 try:
53 output = subprocess.check_output(lint_cmd, env=env);
54 return [output_api.PresubmitNotifyResult(output)]
55 except subprocess.CalledProcessError as e:
56 return [output_api.PresubmitError(e.output)]
57
58def _DoCommonChecks(input_api, output_api):
59 results = []
60 results.extend(input_api.canned_checks.CheckChangedLUCIConfigs(input_api, output_api))
61 results.extend(input_api.canned_checks.CheckGNFormatted(input_api, output_api))
62 results.extend(_DoClangFormat(input_api, output_api))
63 return results
Corentin Wallez99612ae2018-08-20 14:54:15 +020064
65def CheckChangeOnUpload(input_api, output_api):
Corentin Wallez4c351012018-08-27 10:10:28 +020066 return _DoCommonChecks(input_api, output_api)
Corentin Wallez99612ae2018-08-20 14:54:15 +020067
68def CheckChangeOnCommit(input_api, output_api):
Corentin Wallez4c351012018-08-27 10:10:28 +020069 return _DoCommonChecks(input_api, output_api)