1#!/usr/bin/python 2# -*- coding: utf-8 -*- 3 4#------------------------------------------------------------------------- 5# Vulkan CTS 6# ---------- 7# 8# Copyright (c) 2015 Google Inc. 9# 10# Licensed under the Apache License, Version 2.0 (the "License"); 11# you may not use this file except in compliance with the License. 12# You may obtain a copy of the License at 13# 14# http://www.apache.org/licenses/LICENSE-2.0 15# 16# Unless required by applicable law or agreed to in writing, software 17# distributed under the License is distributed on an "AS IS" BASIS, 18# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19# See the License for the specific language governing permissions and 20# limitations under the License. 21# 22#------------------------------------------------------------------------- 23 24import os 25import sys 26import re 27 28sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..", "..", "scripts")) 29 30from build.common import DEQP_DIR 31from khr_util.format import writeInlFile 32 33VULKAN_H = [ 34 os.path.join(os.path.dirname(__file__), "..", "..", "vulkan-docs", "src", "include", "vk_video", "vulkan_video_codecs_common.h"), 35 os.path.join(os.path.dirname(__file__), "..", "..", "vulkan-docs", "src", "include", "vk_video", "vulkan_video_codec_h264std.h"), 36 os.path.join(os.path.dirname(__file__), "..", "..", "vulkan-docs", "src", "include", "vk_video", "vulkan_video_codec_h264std_encode.h"), 37 os.path.join(os.path.dirname(__file__), "..", "..", "vulkan-docs", "src", "include", "vk_video", "vulkan_video_codec_h265std.h"), 38 os.path.join(os.path.dirname(__file__), "..", "..", "vulkan-docs", "src", "include", "vk_video", "vulkan_video_codec_h264std_decode.h"), 39 os.path.join(os.path.dirname(__file__), "..", "..", "vulkan-docs", "src", "include", "vk_video", "vulkan_video_codec_h265std_decode.h"), 40 os.path.join(os.path.dirname(__file__), "..", "..", "vulkan-docs", "src", "include", "vulkan", "vulkan_core.h"), 41 ] 42 43INL_HEADER = """\ 44/* WARNING: This is auto-generated file. Do not modify, since changes will 45 * be lost! Modify the generating script instead. 46 */\ 47""" 48 49TYPE_SUBSTITUTIONS = [ 50 ("uint8_t", "deUint8"), 51 ("uint16_t", "deUint16"), 52 ("uint32_t", "deUint32"), 53 ("uint64_t", "deUint64"), 54 ("int8_t", "deInt8"), 55 ("int16_t", "deInt16"), 56 ("int32_t", "deInt32"), 57 ("int64_t", "deInt64"), 58 ("bool32_t", "deUint32"), 59 ("size_t", "deUintptr"), 60] 61 62def readFile (filename): 63 with open(filename, 'rt') as f: 64 return f.read() 65 66def writeVulkanCHeader (src, filename): 67 def gen (): 68 dst = re.sub(r'(#include "[^\s,\n}]+")', '', src) 69 70 for old_type, new_type in TYPE_SUBSTITUTIONS: 71 dst = dst.replace(old_type, new_type) 72 yield dst 73 writeInlFile(filename, INL_HEADER, gen()) 74 75if __name__ == "__main__": 76 77 # script requires output path to which .inl files will be written 78 if len(sys.argv) == 1: 79 sys.exit("Error - output path wasn't specified in argument") 80 outputPath = str(sys.argv[1]) 81 if not os.path.isabs(outputPath): 82 outputPath = os.path.abspath(outputPath) 83 84 if not os.path.exists(outputPath): 85 os.makedirs(outputPath) 86 87 src = "" 88 for file in VULKAN_H: 89 src += readFile(file) 90 91 writeVulkanCHeader (src, os.path.join(outputPath, "vkVulkan_c.inl")) 92