PRESUBMIT.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # 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. import os
  15. import platform
  16. import subprocess
  17. def _DoClangFormat(input_api, output_api):
  18. # Our binary clang-format is a linux binary compiled for x64
  19. if platform.system() != 'Linux' or platform.architecture()[0] != '64bit':
  20. return [output_api.PresubmitNotifyResult('Skipping clang-format')]
  21. # We need to know which commit to diff against. It doesn't seem to be exposed anywhere
  22. # except in that private member of presubmit_support.Change. This is likely to break
  23. # but hopefully we have an updated clang-format in CPID/GS before it does.
  24. upstream_commit = input_api.change._upstream
  25. if upstream_commit == None:
  26. return []
  27. lint_cmd = [
  28. 'scripts/lint_clang_format.sh',
  29. 'third_party/clang-format/clang-format',
  30. upstream_commit
  31. ]
  32. # Make clang-format use our linux x64 sysroot because it is compiled with a version of
  33. # stdlibc++ that's incompatible with the old libraries present on the bots.
  34. env = {
  35. 'LD_LIBRARY_PATH': os.path.join(
  36. os.getcwd(),
  37. 'build',
  38. 'linux',
  39. 'debian_sid_amd64-sysroot',
  40. 'usr',
  41. 'lib',
  42. 'x86_64-linux-gnu'
  43. )
  44. }
  45. # Call the linting script and forward the output as a notification or as an error
  46. try:
  47. output = subprocess.check_output(lint_cmd, env=env);
  48. return [output_api.PresubmitNotifyResult(output)]
  49. except subprocess.CalledProcessError as e:
  50. return [output_api.PresubmitError(e.output)]
  51. def _DoCommonChecks(input_api, output_api):
  52. results = []
  53. results.extend(input_api.canned_checks.CheckChangedLUCIConfigs(input_api, output_api))
  54. results.extend(input_api.canned_checks.CheckGNFormatted(input_api, output_api))
  55. results.extend(_DoClangFormat(input_api, output_api))
  56. return results
  57. def CheckChangeOnUpload(input_api, output_api):
  58. return _DoCommonChecks(input_api, output_api)
  59. def CheckChangeOnCommit(input_api, output_api):
  60. return _DoCommonChecks(input_api, output_api)