Debian Codegraph @

scripts/gn/gn.py

raw
1 #!/usr/bin/env python3
2 # Copyright 2023 The Khronos Group Inc.
3 # Copyright 2023 Valve Corporation
4 # Copyright 2023 LunarG, Inc.
5 #
6 # SPDX-License-Identifier: Apache-2.0
7
8 import os
9 import subprocess
10 import sys
11
12 # helper to define paths relative to the repo root
13 def RepoRelative(path):
14 return os.path.abspath(os.path.join(os.path.dirname(__file__), '../../', path))
15
16 def BuildGn():
17 if not os.path.exists(RepoRelative("depot_tools")):
18 print("Cloning Chromium depot_tools\n", flush=True)
19 clone_cmd = 'git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git depot_tools'.split(" ")
20 subprocess.call(clone_cmd)
21
22 os.environ['PATH'] = os.environ.get('PATH') + ":" + RepoRelative("depot_tools")
23
24 print("Updating Repo Dependencies and GN Toolchain\n", flush=True)
25 update_cmd = './scripts/gn/update_deps.sh'
26 subprocess.call(update_cmd)
27
28 print("Checking Header Dependencies\n", flush=True)
29 gn_check_cmd = 'gn gen --check out/Debug'.split(" ")
30 subprocess.call(gn_check_cmd)
31
32 print("Generating Ninja Files\n", flush=True)
33 gn_gen_cmd = 'gn gen out/Debug'.split(" ")
34 subprocess.call(gn_gen_cmd)
35
36 print("Running Ninja Build\n", flush=True)
37 ninja_build_cmd = 'ninja -C out/Debug'.split(" ")
38 subprocess.call(ninja_build_cmd)
39
40 #
41 # Module Entrypoint
42 def main():
43 try:
44 BuildGn()
45
46 except subprocess.CalledProcessError as proc_error:
47 print('Command "%s" failed with return code %s' % (' '.join(proc_error.cmd), proc_error.returncode))
48 sys.exit(proc_error.returncode)
49 except Exception as unknown_error:
50 print('An unkown error occured: %s', unknown_error)
51 sys.exit(1)
52
53 sys.exit(0)
54
55 if __name__ == '__main__':
56 main()