blob: 30701174dc8c703b28d69314e8ce212593af7d39 [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
Jamie Madill5ccfd6e2017-12-28 12:39:51 -050026def generate(git_binary):
Jamie Madillc66b22c2017-12-15 16:25:16 -050027 commit_id = subprocess.check_output([git_binary, "rev-parse", "HEAD"], cwd=source_dir).decode('utf-8').strip()
Jamie Madill5ccfd6e2017-12-28 12:39:51 -050028
Cort Strattona81851c2017-11-06 19:13:53 -080029 # 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 Stratton04443a62017-11-22 16:04:23 -080064 contents += '#define %s "%s"\n' % (symbol_name, commit_id)
Cort Strattona81851c2017-11-06 19:13:53 -080065 header_file.write(contents)
Jamie Madill5ccfd6e2017-12-28 12:39:51 -050066
67if __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')