OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/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 """ | |
10 Script to build the command buffer shared library and copy it to Skia tree | |
11 """ | |
12 | |
13 | |
14 import argparse | |
15 import os | |
16 import shutil | |
17 import subprocess | |
18 import sys | |
19 | |
20 | |
21 def main(): | |
22 parser = argparse.ArgumentParser(description=('Builds command_buffer_gles2 ' | |
23 'library and copies it')) | |
24 parser.add_argument('-c', '--chrome-dir', required=True, help= | |
25 'path to Chromium checkout (directory containing .gclient)') | |
26 parser.add_argument('-o', '--output-dir', required=True, | |
27 help='path to copy the command buffer shared library to') | |
28 parser.add_argument('--make-output-dir', default=False, action='store_true', | |
29 help='Makes the output directory if it does not already exist.') | |
30 parser.add_argument('-f', '--fetch', action='store_true', | |
31 help=('Create Chromium src directory and fetch chromium checkout (if ' | |
32 'directory does not already exist)')) | |
33 parser.add_argument('--chrome-build-type', default='Release', | |
34 help='Type of build for the command buffer (e.g. Debug or Release)') | |
35 parser.add_argument('--extra-ninja-args', default='', | |
36 help=('Extra arguments to pass to ninja when building the command ' | |
37 'buffer shared library')) | |
38 parser.add_argument('--chrome-revision', default='origin/lkgr', | |
39 help='Revision (hash, branch, tag) of Chromium to use.') | |
40 parser.add_argument('--no-sync', action='store_true', default=False, | |
41 help='Don\'t run git fetch or gclient sync in the Chromium tree') | |
42 args = parser.parse_args() | |
43 | |
44 args.chrome_dir = os.path.abspath(args.chrome_dir) | |
45 args.output_dir = os.path.abspath(args.output_dir) | |
46 | |
47 if os.path.isfile(args.chrome_dir): | |
48 sys.exit(args.chrome_dir + ' exists but is a file.') | |
49 | |
50 if not os.path.isdir(args.output_dir): | |
borenet
2016/02/17 16:31:17
Not sure it's really necessary to check, but this
bsalomon
2016/02/17 16:56:48
yep
| |
51 sys.exit(args.output_dir + ' exists but is a file.') | |
52 | |
53 chrome_src_dir = os.path.join(args.chrome_dir, 'src') | |
54 | |
55 if os.path.isfile(chrome_src_dir): | |
56 sys.exit(chrome_src_dir + ' exists but is a file.') | |
57 elif not os.path.isdir(chrome_src_dir): | |
58 if args.fetch: | |
59 if os.path.isdir(args.chrome_dir): | |
60 # If chrome_dir is a dir but chrome_src_dir does not exist we will only | |
61 # fetch into chrome_dir if it is empty. | |
62 if os.listdir(args.chrome_dir): | |
63 sys.exit(args.chrome_dir + ' is not a chromium checkout and is not ' | |
64 'empty.') | |
65 else: | |
66 os.makedirs(args.chrome_dir) | |
67 if not os.path.isdir(args.chrome_dir): | |
68 sys.exit('Could not create ' + args.chrome_dir) | |
69 try: | |
70 subprocess.check_call(['fetch', 'chromium'], cwd=args.chrome_dir) | |
71 except subprocess.CalledProcessError as error: | |
72 sys.exit('Error (ret code: ' + error.returncode + ') calling "' + | |
73 error.cmd + '" in ' + args.chrome_dir) | |
borenet
2016/02/17 16:31:16
Format strings would be better here:
sys.exit('Er
bsalomon
2016/02/17 16:56:48
Done.
| |
74 | |
75 | |
76 if not os.path.isdir(chrome_src_dir): | |
77 sys.exit(chrome_src_dir + ' is not a directory.') | |
78 | |
79 if os.path.isfile(args.output_dir): | |
80 sys.exit(args.output_dir + ' exists but is a file.') | |
81 elif not os.path.isdir(args.output_dir): | |
82 if args.make_output_dir: | |
83 os.makedirs(args.output_dir) | |
84 | |
85 chrome_target_dir_rel = os.path.join('out', args.chrome_build_type) | |
86 chrome_target_dir = os.path.join(chrome_src_dir, chrome_target_dir_rel) | |
87 | |
88 if not args.no_sync: | |
89 try: | |
90 subprocess.check_call(['git', 'fetch'], cwd=chrome_src_dir) | |
91 except subprocess.CalledProcessError as error: | |
92 sys.exit('Error (ret code: ' + error.returncode + ') calling "' + | |
93 error.cmd + '" in ' + chrome_src_dir) | |
94 | |
95 try: | |
96 subprocess.check_call(['git', 'checkout', args.chrome_revision], | |
97 cwd=chrome_src_dir) | |
98 except subprocess.CalledProcessError as error: | |
99 sys.exit('Error (ret code: ' + error.returncode + ') calling "' + error.cmd + | |
100 '" in ' + chrome_src_dir) | |
101 | |
102 if not args.no_sync: | |
103 try: | |
104 subprocess.check_call(['gclient', 'sync'], cwd=chrome_src_dir) | |
105 except subprocess.CalledProcessError as error: | |
106 sys.exit('Error (ret code: ' + error.returncode + ') calling "' + | |
107 error.cmd + '" in ' + chrome_src_dir) | |
108 | |
109 try: | |
110 subprocess.check_call(['ninja', args.extra_ninja_args, '-C', | |
borenet
2016/02/17 16:31:17
You might need to do (['ninja'] + shlex.split(args
bsalomon
2016/02/17 16:56:48
Done.
| |
111 chrome_target_dir_rel, 'command_buffer_gles2'], cwd=chrome_src_dir) | |
112 except subprocess.CalledProcessError as error: | |
113 sys.exit('Error (ret code: ' + error.returncode + ') calling "' + | |
114 error.cmd + '" in ' + chrome_src_dir) | |
115 | |
116 shared_lib_src = os.path.join(chrome_target_dir, 'lib', | |
117 'libcommand_buffer_gles2.so') | |
118 shared_lib_dst = os.path.join(args.output_dir, 'libcommand_buffer_gles2.so') | |
119 | |
120 if not os.path.isfile(shared_lib_src): | |
121 sys.exit('Command buffer shared library not at expected location: ' + | |
122 shared_lib_src) | |
123 | |
124 shutil.copy2(shared_lib_src, shared_lib_dst) | |
125 | |
126 if not os.path.isfile(shared_lib_dst): | |
127 sys.exit('Command buffer library not copied to ' + shared_lib_dst) | |
128 | |
129 print('Command buffer library copied to ' + shared_lib_dst) | |
130 | |
131 | |
132 if __name__ == '__main__': | |
133 main() | |
borenet
2016/02/17 16:31:17
Nit: indent
bsalomon
2016/02/17 16:56:48
Done.
| |
134 | |
OLD | NEW |