-
Notifications
You must be signed in to change notification settings - Fork 191
Expand file tree
/
Copy pathcommon_codegen.py
More file actions
114 lines (101 loc) · 4.16 KB
/
common_codegen.py
File metadata and controls
114 lines (101 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/python3 -i
#
# Copyright (c) 2015-2017, 2019-2021 The Khronos Group Inc.
# Copyright (c) 2015-2017, 2019-2021 Valve Corporation
# Copyright (c) 2015-2017, 2019-2021 LunarG, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Author: Mark Lobodzinski <mark@lunarg.com>
import os
import sys
import subprocess
# Copyright text prefixing all headers (list of strings).
prefixStrings = [
'/*',
'** Copyright (c) 2015-2017, 2019-2021 The Khronos Group Inc.',
'** Copyright (c) 2015-2017, 2019-2021 Valve Corporation',
'** Copyright (c) 2015-2017, 2019-2021 LunarG, Inc.',
'** Copyright (c) 2015-2017, 2019-2021 Google Inc.',
'**',
'** Licensed under the Apache License, Version 2.0 (the "License");',
'** you may not use this file except in compliance with the License.',
'** You may obtain a copy of the License at',
'**',
'** http://www.apache.org/licenses/LICENSE-2.0',
'**',
'** Unless required by applicable law or agreed to in writing, software',
'** distributed under the License is distributed on an "AS IS" BASIS,',
'** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.',
'** See the License for the specific language governing permissions and',
'** limitations under the License.',
'*/',
''
]
platform_dict = {
'android' : 'VK_USE_PLATFORM_ANDROID_KHR',
'fuchsia' : 'VK_USE_PLATFORM_FUCHSIA',
'ggp': 'VK_USE_PLATFORM_GGP',
'ios' : 'VK_USE_PLATFORM_IOS_MVK',
'macos' : 'VK_USE_PLATFORM_MACOS_MVK',
'metal' : 'VK_USE_PLATFORM_METAL_EXT',
'vi' : 'VK_USE_PLATFORM_VI_NN',
'wayland' : 'VK_USE_PLATFORM_WAYLAND_KHR',
'win32' : 'VK_USE_PLATFORM_WIN32_KHR',
'xcb' : 'VK_USE_PLATFORM_XCB_KHR',
'xlib' : 'VK_USE_PLATFORM_XLIB_KHR',
'xlib_xrandr' : 'VK_USE_PLATFORM_XLIB_XRANDR_EXT',
'provisional' : 'VK_ENABLE_BETA_EXTENSIONS',
'directfb' : 'VK_USE_PLATFORM_DIRECTFB_EXT',
'screen' : 'VK_USE_PLATFORM_SCREEN_QNX',
'sci' : 'VK_USE_PLATFORM_SCI',
'ohos' : 'VK_USE_PLATFORM_OHOS',
}
#
# Return appropriate feature protect string from 'platform' tag on feature
def GetFeatureProtect(interface):
"""Get platform protection string"""
platform = interface.get('platform')
if platform is not None:
return platform_dict[platform]
provisional = interface.get('provisional')
if provisional == 'true':
return platform_dict['provisional']
# Returns true if we are running in GitHub actions
# https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
def IsGHA():
if 'GITHUB_ACTION' in os.environ:
return True
return False
# Points to the directory containing the top level CMakeLists.txt
PROJECT_SRC_DIR = os.path.abspath(os.path.join(os.path.split(os.path.abspath(__file__))[0], '..'))
if not os.path.isfile(f'{PROJECT_SRC_DIR}/CMakeLists.txt'):
print(f'PROJECT_SRC_DIR invalid! {PROJECT_SRC_DIR}')
sys.exit(1)
# helper to define paths relative to the repo root
def RepoRelative(path):
return os.path.abspath(os.path.join(os.path.dirname(__file__), '..', path))
# Runs a command in a directory and returns its return code.
# Directory is project root by default, or a relative path from project root
def RunShellCmd(command, start_dir = PROJECT_SRC_DIR, env=None, verbose=False):
# Flush stdout here. Helps when debugging on CI.
sys.stdout.flush()
if start_dir != PROJECT_SRC_DIR:
start_dir = RepoRelative(start_dir)
cmd_list = command.split(" ")
# Helps a lot when debugging CI issues
if IsGHA():
verbose = True
if verbose:
print(f'CICMD({cmd_list}, env={env})')
subprocess.check_call(cmd_list, cwd=start_dir, env=env)