1#!/usr/bin/python3 2# Copyright 2023 The ANGLE Project Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6import os 7import subprocess 8import sys 9import argparse 10 11template_header_boilerplate = """// GENERATED FILE - DO NOT EDIT. 12// Generated by {script_name} 13// 14// Copyright 2020 The ANGLE Project Authors. All rights reserved. 15// Use of this source code is governed by a BSD-style license that can be 16// found in the LICENSE file. 17// 18""" 19 20 21def embed_in_header(source_file, variable_name, dest_header_file): 22 boilerplate_code = template_header_boilerplate.format( 23 script_name=os.path.basename(sys.argv[0])) 24 25 with open(source_file, 'rb') as f: 26 source_data = f.read() 27 28 with open(dest_header_file, 'wt') as out_file: 29 out_file.write(boilerplate_code) 30 out_file.write('\n') 31 out_file.write('// C++ string version of default shaders mtllib.\n\n') 32 out_file.write('\n\nstatic constexpr uint8_t ' + variable_name + '[] = {\n') 33 for byte in source_data: 34 out_file.write(f"{byte}, ") 35 out_file.write('\n') 36 out_file.write('};\n') 37 out_file.close() 38 39 40def main(): 41 parser = argparse.ArgumentParser() 42 parser.add_argument('--source') 43 parser.add_argument('--variable-name') 44 parser.add_argument('--header') 45 args = parser.parse_args() 46 47 embed_in_header(args.source, args.variable_name, args.header) 48 49 50if __name__ == '__main__': 51 sys.exit(main()) 52