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