Cort Stratton | a81851c | 2017-11-06 19:13:53 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # Copyright (c) 2015-2016 The Khronos Group Inc. |
| 4 | # Copyright (c) 2015-2016 Valve Corporation |
| 5 | # Copyright (c) 2015-2016 LunarG, Inc. |
| 6 | # Copyright (c) 2015-2016 Google Inc. |
| 7 | # |
| 8 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | # you may not use this file except in compliance with the License. |
| 10 | # You may obtain a copy of the License at |
| 11 | # |
| 12 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | # |
| 14 | # Unless required by applicable law or agreed to in writing, software |
| 15 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | # See the License for the specific language governing permissions and |
| 18 | # limitations under the License. |
| 19 | # |
| 20 | # Author: Cort Stratton <cort@google.com> |
| 21 | |
| 22 | import os |
| 23 | import subprocess |
| 24 | import sys |
| 25 | |
| 26 | |
| 27 | |
| 28 | if __name__ == '__main__': |
| 29 | if (len(sys.argv) != 4): |
| 30 | print("Usage: %s <SPIRV_TOOLS_SOURCE_DIR> <SPIRV_TOOLS_REVISION_FILE> <OUTPUT_HEADER_FILE>" % sys.argv[0]) |
| 31 | sys.exit(os.EX_USAGE) |
| 32 | |
| 33 | spirv_tools_source_dir = sys.argv[1] |
| 34 | spirv_tools_revision_file = sys.argv[2] |
| 35 | output_header_file = sys.argv[3] |
| 36 | |
| 37 | # Load SPIRV-Tools revision |
| 38 | with open(spirv_tools_revision_file, "r") as rev_file: |
| 39 | revision = rev_file.read().replace('\n', '') |
| 40 | |
| 41 | # The revision listed in the file may be symbolic; use "git rev-parse" to |
| 42 | # convert it to a commit hash |
| 43 | spirv_tools_commit_id = subprocess.check_output(["git", "rev-parse", revision], cwd=spirv_tools_source_dir).decode('utf-8').strip() |
| 44 | |
| 45 | # Write commit ID to output header file |
| 46 | with open(output_header_file, "w") as header_file: |
| 47 | # File Comment |
| 48 | file_comment = '// *** THIS FILE IS GENERATED - DO NOT EDIT ***\n' |
| 49 | file_comment += '// See external_revision_generator.py for modifications\n' |
| 50 | header_file.write(file_comment) |
| 51 | # Copyright Notice |
| 52 | copyright = '' |
| 53 | copyright += '\n' |
| 54 | copyright += '/***************************************************************************\n' |
| 55 | copyright += ' *\n' |
| 56 | copyright += ' * Copyright (c) 2015-2017 The Khronos Group Inc.\n' |
| 57 | copyright += ' * Copyright (c) 2015-2017 Valve Corporation\n' |
| 58 | copyright += ' * Copyright (c) 2015-2017 LunarG, Inc.\n' |
| 59 | copyright += ' * Copyright (c) 2015-2017 Google Inc.\n' |
| 60 | copyright += ' *\n' |
| 61 | copyright += ' * Licensed under the Apache License, Version 2.0 (the "License");\n' |
| 62 | copyright += ' * you may not use this file except in compliance with the License.\n' |
| 63 | copyright += ' * You may obtain a copy of the License at\n' |
| 64 | copyright += ' *\n' |
| 65 | copyright += ' * http://www.apache.org/licenses/LICENSE-2.0\n' |
| 66 | copyright += ' *\n' |
| 67 | copyright += ' * Unless required by applicable law or agreed to in writing, software\n' |
| 68 | copyright += ' * distributed under the License is distributed on an "AS IS" BASIS,\n' |
| 69 | copyright += ' * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n' |
| 70 | copyright += ' * See the License for the specific language governing permissions and\n' |
| 71 | copyright += ' * limitations under the License.\n' |
| 72 | copyright += ' *\n' |
| 73 | copyright += ' * Author: Chris Forbes <chrisforbes@google.com>\n' |
| 74 | copyright += ' * Author: Cort Stratton <cort@google.com>\n' |
| 75 | copyright += ' *\n' |
| 76 | copyright += ' ****************************************************************************/\n' |
| 77 | header_file.write(copyright) |
| 78 | # Contents |
| 79 | contents = '#pragma once\n\n' |
| 80 | contents += '#define SPIRV_TOOLS_COMMIT_ID "' + spirv_tools_commit_id + '"\n' |
| 81 | header_file.write(contents) |
| 82 | |