blob: 34f71025767230e8e979a1fffa5287deced16f2d [file] [log] [blame]
Cort Strattona81851c2017-11-06 19:13:53 -08001#!/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
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
36 commit_id = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=source_dir).decode('utf-8').strip()
Cort Strattona81851c2017-11-06 19:13:53 -080037
38 # Write commit ID to output header file
39 with open(output_header_file, "w") as header_file:
40 # File Comment
41 file_comment = '// *** THIS FILE IS GENERATED - DO NOT EDIT ***\n'
42 file_comment += '// See external_revision_generator.py for modifications\n'
43 header_file.write(file_comment)
44 # Copyright Notice
45 copyright = ''
46 copyright += '\n'
47 copyright += '/***************************************************************************\n'
48 copyright += ' *\n'
49 copyright += ' * Copyright (c) 2015-2017 The Khronos Group Inc.\n'
50 copyright += ' * Copyright (c) 2015-2017 Valve Corporation\n'
51 copyright += ' * Copyright (c) 2015-2017 LunarG, Inc.\n'
52 copyright += ' * Copyright (c) 2015-2017 Google Inc.\n'
53 copyright += ' *\n'
54 copyright += ' * Licensed under the Apache License, Version 2.0 (the "License");\n'
55 copyright += ' * you may not use this file except in compliance with the License.\n'
56 copyright += ' * You may obtain a copy of the License at\n'
57 copyright += ' *\n'
58 copyright += ' * http://www.apache.org/licenses/LICENSE-2.0\n'
59 copyright += ' *\n'
60 copyright += ' * Unless required by applicable law or agreed to in writing, software\n'
61 copyright += ' * distributed under the License is distributed on an "AS IS" BASIS,\n'
62 copyright += ' * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n'
63 copyright += ' * See the License for the specific language governing permissions and\n'
64 copyright += ' * limitations under the License.\n'
65 copyright += ' *\n'
66 copyright += ' * Author: Chris Forbes <chrisforbes@google.com>\n'
67 copyright += ' * Author: Cort Stratton <cort@google.com>\n'
68 copyright += ' *\n'
69 copyright += ' ****************************************************************************/\n'
70 header_file.write(copyright)
71 # Contents
72 contents = '#pragma once\n\n'
Cort Stratton04443a62017-11-22 16:04:23 -080073 contents += '#define %s "%s"\n' % (symbol_name, commit_id)
Cort Strattona81851c2017-11-06 19:13:53 -080074 header_file.write(contents)
75