PRESUBMIT.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 command buffer 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 _IsGLES2CmdBufferFile(affected_file):
  11. filename = os.path.basename(affected_file.LocalPath())
  12. if filename in [
  13. 'build_cmd_buffer_lib.py', 'build_gles2_cmd_buffer.py',
  14. 'gles2_cmd_buffer_functions.txt', 'gl2.h', 'gl2ext.h', 'gl3.h', 'gl31.h',
  15. 'gl2chromium.h', 'gl2extchromium.h'
  16. ]:
  17. return True
  18. return ((filename.startswith('gles2') or filename.startswith('context_state')
  19. or filename.startswith('client_context_state')) and
  20. filename.endswith('_autogen.h'))
  21. def _IsRasterCmdBufferFile(affected_file):
  22. filename = os.path.basename(affected_file.LocalPath())
  23. if filename in [
  24. 'build_cmd_buffer_lib.py', 'build_raster_cmd_buffer.py',
  25. 'raster_cmd_buffer_functions.txt'
  26. ]:
  27. return True
  28. return filename.startswith('raster') and filename.endswith('_autogen.h')
  29. def _IsWebGPUCmdBufferFile(affected_file):
  30. filename = os.path.basename(affected_file.LocalPath())
  31. if filename in [
  32. 'build_cmd_buffer_lib.py', 'build_webgpu_cmd_buffer.py',
  33. 'webgpu_cmd_buffer_functions.txt'
  34. ]:
  35. return True
  36. return filename.startswith('webgpu') and filename.endswith('_autogen.h')
  37. def CommonChecks(input_api, output_api):
  38. gles2_cmd_buffer_files = input_api.AffectedFiles(
  39. file_filter=_IsGLES2CmdBufferFile)
  40. raster_cmd_buffer_files = input_api.AffectedFiles(
  41. file_filter=_IsRasterCmdBufferFile)
  42. webgpu_cmd_buffer_files = input_api.AffectedFiles(
  43. file_filter=_IsWebGPUCmdBufferFile)
  44. messages = []
  45. with input_api.temporary_directory() as temp_dir:
  46. commands = []
  47. if len(gles2_cmd_buffer_files) > 0:
  48. commands.append(
  49. input_api.Command(
  50. name='build_gles2_cmd_buffer',
  51. cmd=[
  52. input_api.python3_executable, 'build_gles2_cmd_buffer.py',
  53. '--check', '--output-dir=' + temp_dir
  54. ],
  55. kwargs={},
  56. message=output_api.PresubmitError))
  57. if len(raster_cmd_buffer_files) > 0:
  58. commands.append(
  59. input_api.Command(
  60. name='build_raster_cmd_buffer',
  61. cmd=[
  62. input_api.python3_executable, 'build_raster_cmd_buffer.py',
  63. '--check', '--output-dir=' + temp_dir
  64. ],
  65. kwargs={},
  66. message=output_api.PresubmitError))
  67. if len(webgpu_cmd_buffer_files) > 0:
  68. commands.append(
  69. input_api.Command(
  70. name='build_webgpu_cmd_buffer',
  71. cmd=[
  72. input_api.python3_executable, 'build_webgpu_cmd_buffer.py',
  73. '--check', '--output-dir=' + temp_dir
  74. ],
  75. kwargs={},
  76. message=output_api.PresubmitError))
  77. if len(commands) > 0:
  78. messages.extend(input_api.RunTests(commands))
  79. return messages
  80. def CheckChangeOnUpload(input_api, output_api):
  81. return CommonChecks(input_api, output_api)
  82. def CheckChangeOnCommit(input_api, output_api):
  83. return CommonChecks(input_api, output_api)