blob: 08f76dba73d014b6374a4f2d7e9da7bc7cc66ddd [file] [log] [blame]
bsalomonc43f2af2016-02-17 10:42:46 -08001#!/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"""
10Script to build the command buffer shared library and copy it to Skia tree
11"""
12
13
14import argparse
15import os
16import shlex
17import shutil
18import subprocess
19import sys
20
21
22def main():
23 parser = argparse.ArgumentParser(description=('Builds command_buffer_gles2 '
24 'library and copies it'))
25 parser.add_argument('-c', '--chrome-dir', required=True, help=
26 'path to Chromium checkout (directory containing .gclient)')
27 parser.add_argument('-o', '--output-dir', required=True,
28 help='path to copy the command buffer shared library to')
29 parser.add_argument('--make-output-dir', default=False, action='store_true',
30 help='Makes the output directory if it does not already exist.')
bsalomon90b5cc32016-08-11 08:25:41 -070031 parser.add_argument('-t', '--chrome-build-type', default='Release',
32 help='Type of build for the command buffer (e.g. Debug or Release). The '
33 'output dir to build will be <chrome-dir>/out/<chrome-build-type> '
34 'and must already be initialized by gn.')
bsalomonc43f2af2016-02-17 10:42:46 -080035 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')
bsalomon90b5cc32016-08-11 08:25:41 -070042 parser.add_argument('--no-hooks', action='store_true', default=False,
43 help='Don\'t run gclient runhooks in the Chromium tree. Implies '
44 '--no-sync')
bsalomonc43f2af2016-02-17 10:42:46 -080045 args = parser.parse_args()
46
47 args.chrome_dir = os.path.abspath(args.chrome_dir)
48 args.output_dir = os.path.abspath(args.output_dir)
49
bsalomon90b5cc32016-08-11 08:25:41 -070050 if args.no_hooks:
51 args.no_sync = True
52
bsalomonc43f2af2016-02-17 10:42:46 -080053 if os.path.isfile(args.chrome_dir):
54 sys.exit(args.chrome_dir + ' exists but is a file.')
55
56 if os.path.isfile(args.output_dir):
57 sys.exit(args.output_dir + ' exists but is a file.')
58
59 chrome_src_dir = os.path.join(args.chrome_dir, 'src')
60
bsalomonc43f2af2016-02-17 10:42:46 -080061 if not os.path.isdir(chrome_src_dir):
62 sys.exit(chrome_src_dir + ' is not a directory.')
63
64 if os.path.isfile(args.output_dir):
65 sys.exit(args.output_dir + ' exists but is a file.')
66 elif not os.path.isdir(args.output_dir):
67 if args.make_output_dir:
68 os.makedirs(args.output_dir)
69 else:
70 sys.exit(args.output_dir + ' does not exist (specify --make-output-dir '
71 'to create).')
72
73 chrome_target_dir_rel = os.path.join('out', args.chrome_build_type)
bsalomonc43f2af2016-02-17 10:42:46 -080074
bsalomon1526e0a2016-02-18 10:01:11 -080075 # The command buffer shared library will have a different name on Linux,
76 # Mac, and Windows. Also, on Linux it will be in a 'lib' subdirectory and
77 # needs to be placed in a 'lib' subdirectory of the directory containing the
78 # Skia executable. Also, the name of the gclient executable we call out to has
79 # a .bat file extension on Windows.
80 platform = sys.platform
81 if platform == 'cygwin':
82 platform = 'win32'
83
84 shared_lib_name = 'libcommand_buffer_gles2.so'
85 shared_lib_subdir = 'lib'
86 gclient = 'gclient'
87 if platform == 'darwin':
88 shared_lib_name = 'libcommand_buffer_gles2.dylib'
89 shared_lib_subdir = ''
90 elif platform == 'win32':
91 shared_lib_name = 'command_buffer_gles2.dll'
92 shared_lib_subdir = ''
93 gclient = 'gclient.bat'
94
bsalomonc43f2af2016-02-17 10:42:46 -080095 if not args.no_sync:
96 try:
97 subprocess.check_call(['git', 'fetch'], cwd=chrome_src_dir)
98 except subprocess.CalledProcessError as error:
borenet48b88cc2016-04-11 10:16:01 -070099 sys.exit('Error (ret code: %s) calling "%s" in %s' % (error.returncode,
100 error.cmd, chrome_src_dir))
bsalomonc43f2af2016-02-17 10:42:46 -0800101
borenet7bedaf52016-04-25 11:22:41 -0700102 try:
103 subprocess.check_call(['git', 'checkout', args.chrome_revision],
104 cwd=chrome_src_dir)
105 except subprocess.CalledProcessError as error:
106 sys.exit('Error (ret code: %s) calling "%s" in %s' % (error.returncode,
107 error.cmd, chrome_src_dir))
bsalomonc43f2af2016-02-17 10:42:46 -0800108
bsalomonc43f2af2016-02-17 10:42:46 -0800109 try:
bsalomonc969bfc2016-02-18 06:40:55 -0800110 os.environ['GYP_GENERATORS'] = 'ninja'
bsalomon90b5cc32016-08-11 08:25:41 -0700111 subprocess.check_call([gclient, 'sync', '--reset', '--force',
112 '--nohooks'],
bsalomonc969bfc2016-02-18 06:40:55 -0800113 cwd=chrome_src_dir)
bsalomonc43f2af2016-02-17 10:42:46 -0800114 except subprocess.CalledProcessError as error:
borenet48b88cc2016-04-11 10:16:01 -0700115 sys.exit('Error (ret code: %s) calling "%s" in %s' % (error.returncode,
116 error.cmd, chrome_src_dir))
bsalomonc43f2af2016-02-17 10:42:46 -0800117
bsalomon90b5cc32016-08-11 08:25:41 -0700118 if not args.no_hooks:
119 try:
120 subprocess.check_call([gclient, 'runhooks'], cwd=chrome_src_dir)
121 except subprocess.CalledProcessError as error:
122 sys.exit('Error (ret code: %s) calling "%s" in %s' % (
123 error.returncode, error.cmd, chrome_src_dir))
borenetb6aafe62016-08-02 07:02:52 -0700124
borenet86baf3d2016-08-02 08:37:50 -0700125 gn = 'gn'
borenetb6aafe62016-08-02 07:02:52 -0700126 platform = 'linux64'
127 if sys.platform == 'darwin':
128 platform = 'mac'
129 elif sys.platform == 'win32':
130 platform = 'win'
borenet86baf3d2016-08-02 08:37:50 -0700131 gn = 'gn.exe'
132 gn = os.path.join(chrome_src_dir, 'buildtools', platform, gn)
borenetb6aafe62016-08-02 07:02:52 -0700133 try:
boreneta6291662016-08-22 07:31:43 -0700134 subprocess.check_call([gn, 'gen', chrome_target_dir_rel,
135 '--args=is_component_build=false'],
borenetb6aafe62016-08-02 07:02:52 -0700136 cwd=chrome_src_dir)
137 except subprocess.CalledProcessError as error:
138 sys.exit('Error (ret code: %s) calling "%s" in %s' % (
139 error.returncode, error.cmd, chrome_src_dir))
140
141 try:
bsalomonc43f2af2016-02-17 10:42:46 -0800142 subprocess.check_call(['ninja'] + shlex.split(args.extra_ninja_args) +
143 ['-C', chrome_target_dir_rel, 'command_buffer_gles2'],
144 cwd=chrome_src_dir)
145 except subprocess.CalledProcessError as error:
borenet48b88cc2016-04-11 10:16:01 -0700146 sys.exit('Error (ret code: %s) calling "%s" in %s' % (error.returncode,
147 error.cmd, chrome_src_dir))
bsalomonc43f2af2016-02-17 10:42:46 -0800148
bsalomon9f071d12016-07-21 08:05:01 -0700149 shared_lib_src_dir = os.path.join(chrome_src_dir, chrome_target_dir_rel)
bsalomonc969bfc2016-02-18 06:40:55 -0800150 shared_lib_dst_dir = os.path.join(args.output_dir, shared_lib_subdir)
151 # Make the subdir for the dst if does not exist
152 if shared_lib_subdir and not os.path.isdir(shared_lib_dst_dir):
153 os.mkdir(shared_lib_dst_dir)
154
bsalomonc969bfc2016-02-18 06:40:55 -0800155 shared_lib_src = os.path.join(shared_lib_src_dir, shared_lib_name)
156 shared_lib_dst = os.path.join(shared_lib_dst_dir, shared_lib_name)
bsalomonc43f2af2016-02-17 10:42:46 -0800157
158 if not os.path.isfile(shared_lib_src):
159 sys.exit('Command buffer shared library not at expected location: ' +
160 shared_lib_src)
161
162 shutil.copy2(shared_lib_src, shared_lib_dst)
163
164 if not os.path.isfile(shared_lib_dst):
165 sys.exit('Command buffer library not copied to ' + shared_lib_dst)
166
167 print('Command buffer library copied to ' + shared_lib_dst)
168
169
170if __name__ == '__main__':
171 main()
172