Cort Stratton | a81851c | 2017-11-06 19:13:53 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
Cort Stratton | b9aa8f1 | 2017-11-27 16:43:14 -0800 | [diff] [blame] | 3 | # Copyright (c) 2015-2017 The Khronos Group Inc. |
| 4 | # Copyright (c) 2015-2017 Valve Corporation |
| 5 | # Copyright (c) 2015-2017 LunarG, Inc. |
| 6 | # Copyright (c) 2015-2017 Google Inc. |
Cort Stratton | a81851c | 2017-11-06 19:13:53 -0800 | [diff] [blame] | 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 | |
Jamie Madill | 5ccfd6e | 2017-12-28 12:39:51 -0500 | [diff] [blame] | 26 | def generate(git_binary): |
Jamie Madill | c66b22c | 2017-12-15 16:25:16 -0500 | [diff] [blame] | 27 | commit_id = subprocess.check_output([git_binary, "rev-parse", "HEAD"], cwd=source_dir).decode('utf-8').strip() |
Jamie Madill | 5ccfd6e | 2017-12-28 12:39:51 -0500 | [diff] [blame] | 28 | |
Cort Stratton | a81851c | 2017-11-06 19:13:53 -0800 | [diff] [blame] | 29 | # Write commit ID to output header file |
| 30 | with open(output_header_file, "w") as header_file: |
| 31 | # File Comment |
| 32 | file_comment = '// *** THIS FILE IS GENERATED - DO NOT EDIT ***\n' |
| 33 | file_comment += '// See external_revision_generator.py for modifications\n' |
| 34 | header_file.write(file_comment) |
| 35 | # Copyright Notice |
| 36 | copyright = '' |
| 37 | copyright += '\n' |
| 38 | copyright += '/***************************************************************************\n' |
| 39 | copyright += ' *\n' |
| 40 | copyright += ' * Copyright (c) 2015-2017 The Khronos Group Inc.\n' |
| 41 | copyright += ' * Copyright (c) 2015-2017 Valve Corporation\n' |
| 42 | copyright += ' * Copyright (c) 2015-2017 LunarG, Inc.\n' |
| 43 | copyright += ' * Copyright (c) 2015-2017 Google Inc.\n' |
| 44 | copyright += ' *\n' |
| 45 | copyright += ' * Licensed under the Apache License, Version 2.0 (the "License");\n' |
| 46 | copyright += ' * you may not use this file except in compliance with the License.\n' |
| 47 | copyright += ' * You may obtain a copy of the License at\n' |
| 48 | copyright += ' *\n' |
| 49 | copyright += ' * http://www.apache.org/licenses/LICENSE-2.0\n' |
| 50 | copyright += ' *\n' |
| 51 | copyright += ' * Unless required by applicable law or agreed to in writing, software\n' |
| 52 | copyright += ' * distributed under the License is distributed on an "AS IS" BASIS,\n' |
| 53 | copyright += ' * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n' |
| 54 | copyright += ' * See the License for the specific language governing permissions and\n' |
| 55 | copyright += ' * limitations under the License.\n' |
| 56 | copyright += ' *\n' |
| 57 | copyright += ' * Author: Chris Forbes <chrisforbes@google.com>\n' |
| 58 | copyright += ' * Author: Cort Stratton <cort@google.com>\n' |
| 59 | copyright += ' *\n' |
| 60 | copyright += ' ****************************************************************************/\n' |
| 61 | header_file.write(copyright) |
| 62 | # Contents |
| 63 | contents = '#pragma once\n\n' |
Cort Stratton | 04443a6 | 2017-11-22 16:04:23 -0800 | [diff] [blame] | 64 | contents += '#define %s "%s"\n' % (symbol_name, commit_id) |
Cort Stratton | a81851c | 2017-11-06 19:13:53 -0800 | [diff] [blame] | 65 | header_file.write(contents) |
Jamie Madill | 5ccfd6e | 2017-12-28 12:39:51 -0500 | [diff] [blame] | 66 | |
| 67 | if __name__ == '__main__': |
| 68 | if (len(sys.argv) != 4): |
| 69 | print("Usage: %s <SOURCE_DIR> <SYMBOL_NAME> <OUTPUT_HEADER_FILE>" % sys.argv[0]) |
| 70 | sys.exit(os.EX_USAGE) |
| 71 | |
| 72 | source_dir = sys.argv[1] |
| 73 | symbol_name = sys.argv[2] |
| 74 | output_header_file = sys.argv[3] |
| 75 | |
| 76 | # Extract commit ID from the specified source directory |
| 77 | try: |
| 78 | generate('git') |
| 79 | except WindowsError: |
| 80 | # Call git.bat on Windows for compatiblity. |
| 81 | generate('git.bat') |