Debian Codegraph @

infra/bots/assets/chromebook_arm64_gles/create.py

raw
1 #!/usr/bin/env python
2 #
3 # Copyright 2016 Google Inc.
4 #
5 # Use of this source code is governed by a BSD-style license that can be
6 # found in the LICENSE file.
7
8
9 """Create the asset."""
10
11
12 from __future__ import print_function
13 import argparse
14 import glob
15 import os
16 import shutil
17 import subprocess
18 import sys
19
20
21 ENV_VAR = 'CHROMEBOOK_ARM64_GLES_LIB_PATH'
22
23
24 def getenv(key):
25 val = os.environ.get(key)
26 if not val:
27 print(('Environment variable %s not set; you should run this via '
28 'create_and_upload.py.' % key), file=sys.stderr)
29 sys.exit(1)
30 return val
31
32
33 def create_asset(target_dir, gl_path):
34 """Create the asset."""
35
36 cmd = [
37 'sudo','apt-get','install','-y',
38 'libgles2-mesa-dev',
39 'libegl1-mesa-dev'
40 ]
41 subprocess.check_call(cmd)
42
43
44 lib_dir = os.path.join(target_dir, 'lib')
45 os.mkdir(lib_dir)
46
47 # Copy GLES and EGL libs from /usr/lib64.
48 to_copy = glob.glob(os.path.join(gl_path,'usr/lib64/libGLES*'))
49 to_copy.extend(glob.glob(os.path.join(gl_path,'usr/lib64/libEGL*')))
50 for f in to_copy:
51 shutil.copy(f, lib_dir)
52
53 # Copy GL libs from /usr/local/lib64.
54 prefix = 'apitrace/wrappers'
55 to_copy = glob.glob(os.path.join(gl_path,'usr/local/lib64', prefix, '*'))
56 dest = os.path.join(lib_dir, prefix)
57 os.makedirs(dest)
58 for f in to_copy:
59 shutil.copy(f, dest)
60
61 # Add a symlink to the lib dir for libGL.so.
62 subprocess.check_call(['ln', '-s', prefix+'/libGL.so', 'libGL.so'], cwd=lib_dir)
63
64 # Copy the include dirs.
65 include_dir = os.path.join(target_dir, 'include')
66 os.mkdir(include_dir)
67 shutil.copytree('/usr/include/EGL', os.path.join(include_dir, 'EGL'))
68 shutil.copytree('/usr/include/KHR', os.path.join(include_dir, 'KHR'))
69 shutil.copytree('/usr/include/GLES2', os.path.join(include_dir, 'GLES2'))
70 shutil.copytree('/usr/include/GLES3', os.path.join(include_dir, 'GLES3'))
71
72
73 def main():
74 if 'linux' not in sys.platform:
75 print('This script only runs on Linux.', file=sys.stderr)
76 sys.exit(1)
77 parser = argparse.ArgumentParser()
78 parser.add_argument('--target_dir', '-t', required=True)
79 args = parser.parse_args()
80
81 # Obtain lib_path from create_and_upload via an environment variable, since
82 # this script is called via `sk` and not directly.
83 lib_path = getenv(ENV_VAR)
84
85 create_asset(args.target_dir, lib_path)
86
87
88 if __name__ == '__main__':
89 main()