PRESUBMIT.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Copyright 2019 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. """Enforces Vulkan function pointer autogen matches script output.
  5. See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
  6. for more details on the presubmit API built into depot_tools.
  7. """
  8. import os.path
  9. USE_PYTHON3 = True
  10. def CommonChecks(input_api, output_api):
  11. generating_files = input_api.AffectedFiles(
  12. file_filter=lambda x: os.path.basename(x.LocalPath()) in [
  13. 'generate_bindings.py'])
  14. generated_files = input_api.AffectedFiles(
  15. file_filter=lambda x: os.path.basename(x.LocalPath()) in [
  16. 'vulkan_function_pointers.cc', 'vulkan_function_pointers.h'])
  17. messages = []
  18. if generated_files and not generating_files:
  19. long_text = 'Changed files:\n'
  20. for generated_file in generated_files:
  21. long_text += generated_file.LocalPath() + '\n'
  22. long_text += '\n'
  23. messages.append(output_api.PresubmitError(
  24. 'Vulkan function pointer generated files changed but the generator '
  25. 'did not.', long_text=long_text))
  26. with input_api.temporary_directory() as temp_dir:
  27. commands = []
  28. if generating_files:
  29. python_executable = input_api.python3_executable
  30. commands.append(input_api.Command(name='generate_bindings',
  31. cmd=[python_executable,
  32. 'generate_bindings.py',
  33. '--check',
  34. '--output-dir=' + temp_dir],
  35. kwargs={},
  36. message=output_api.PresubmitError))
  37. if commands:
  38. messages.extend(input_api.RunTests(commands))
  39. return messages
  40. def CheckChangeOnUpload(input_api, output_api):
  41. return CommonChecks(input_api, output_api)
  42. def CheckChangeOnCommit(input_api, output_api):
  43. return CommonChecks(input_api, output_api)