Debian Codegraph @

scripts/common_codegen.py

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