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