blob: 39c089da5c399e63b8cd7fa498ea80aab00fea78 [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,
bsalomon795390b2016-11-04 10:54:54 -070028 help='path to copy the command buffer shared library to. Typically this '
29 'is out/Debug or out/Release in a Skia repository')
bsalomonc43f2af2016-02-17 10:42:46 -080030 parser.add_argument('--make-output-dir', default=False, action='store_true',
31 help='Makes the output directory if it does not already exist.')
bsalomon795390b2016-11-04 10:54:54 -070032 parser.add_argument('--chrome-out-dir', default='CommandBufferForSkia',
33 help='Type of name of the gn output directory (e.g. Debug or Release). '
34 'This is relative to the Chromium src/out directory. Note that this '
35 'script will reset the gn args in this directory on each run.')
36 parser.add_argument('--extra-gn-args', default='',
37 help=('Extra GN arguments to use for the output directory used to build'
38 'the command buffer'))
bsalomonc43f2af2016-02-17 10:42:46 -080039 parser.add_argument('--extra-ninja-args', default='',
40 help=('Extra arguments to pass to ninja when building the command '
41 'buffer shared library'))
42 parser.add_argument('--chrome-revision', default='origin/lkgr',
43 help='Revision (hash, branch, tag) of Chromium to use.')
44 parser.add_argument('--no-sync', action='store_true', default=False,
45 help='Don\'t run git fetch or gclient sync in the Chromium tree')
bsalomon90b5cc32016-08-11 08:25:41 -070046 parser.add_argument('--no-hooks', action='store_true', default=False,
47 help='Don\'t run gclient runhooks in the Chromium tree. Implies '
48 '--no-sync')
bsalomonc43f2af2016-02-17 10:42:46 -080049 args = parser.parse_args()
50
51 args.chrome_dir = os.path.abspath(args.chrome_dir)
52 args.output_dir = os.path.abspath(args.output_dir)
53
bsalomon90b5cc32016-08-11 08:25:41 -070054 if args.no_hooks:
55 args.no_sync = True
56
bsalomonc43f2af2016-02-17 10:42:46 -080057 if os.path.isfile(args.chrome_dir):
58 sys.exit(args.chrome_dir + ' exists but is a file.')
59
60 if os.path.isfile(args.output_dir):
61 sys.exit(args.output_dir + ' exists but is a file.')
62
63 chrome_src_dir = os.path.join(args.chrome_dir, 'src')
64
bsalomonc43f2af2016-02-17 10:42:46 -080065 if not os.path.isdir(chrome_src_dir):
66 sys.exit(chrome_src_dir + ' is not a directory.')
67
68 if os.path.isfile(args.output_dir):
69 sys.exit(args.output_dir + ' exists but is a file.')
70 elif not os.path.isdir(args.output_dir):
71 if args.make_output_dir:
72 os.makedirs(args.output_dir)
73 else:
74 sys.exit(args.output_dir + ' does not exist (specify --make-output-dir '
75 'to create).')
76
bsalomon795390b2016-11-04 10:54:54 -070077 chrome_target_dir_rel = os.path.join('out', args.chrome_out_dir)
bsalomonc43f2af2016-02-17 10:42:46 -080078
bsalomon1526e0a2016-02-18 10:01:11 -080079 # The command buffer shared library will have a different name on Linux,
bsalomon795390b2016-11-04 10:54:54 -070080 # Mac, and Windows. Also, the name of the gclient executable we call out to
81 # has a .bat file extension on Windows.
bsalomon1526e0a2016-02-18 10:01:11 -080082 platform = sys.platform
83 if platform == 'cygwin':
84 platform = 'win32'
85
86 shared_lib_name = 'libcommand_buffer_gles2.so'
bsalomon1526e0a2016-02-18 10:01:11 -080087 gclient = 'gclient'
88 if platform == 'darwin':
89 shared_lib_name = 'libcommand_buffer_gles2.dylib'
bsalomon1526e0a2016-02-18 10:01:11 -080090 elif platform == 'win32':
91 shared_lib_name = 'command_buffer_gles2.dll'
bsalomon1526e0a2016-02-18 10:01:11 -080092 gclient = 'gclient.bat'
93
bsalomonc43f2af2016-02-17 10:42:46 -080094 if not args.no_sync:
95 try:
96 subprocess.check_call(['git', 'fetch'], cwd=chrome_src_dir)
97 except subprocess.CalledProcessError as error:
borenet48b88cc2016-04-11 10:16:01 -070098 sys.exit('Error (ret code: %s) calling "%s" in %s' % (error.returncode,
99 error.cmd, chrome_src_dir))
bsalomonc43f2af2016-02-17 10:42:46 -0800100
borenet7bedaf52016-04-25 11:22:41 -0700101 try:
102 subprocess.check_call(['git', 'checkout', args.chrome_revision],
103 cwd=chrome_src_dir)
104 except subprocess.CalledProcessError as error:
105 sys.exit('Error (ret code: %s) calling "%s" in %s' % (error.returncode,
106 error.cmd, chrome_src_dir))
bsalomonc43f2af2016-02-17 10:42:46 -0800107
bsalomonc43f2af2016-02-17 10:42:46 -0800108 try:
bsalomonc969bfc2016-02-18 06:40:55 -0800109 os.environ['GYP_GENERATORS'] = 'ninja'
bsalomon90b5cc32016-08-11 08:25:41 -0700110 subprocess.check_call([gclient, 'sync', '--reset', '--force',
111 '--nohooks'],
bsalomonc969bfc2016-02-18 06:40:55 -0800112 cwd=chrome_src_dir)
bsalomonc43f2af2016-02-17 10:42:46 -0800113 except subprocess.CalledProcessError as error:
borenet48b88cc2016-04-11 10:16:01 -0700114 sys.exit('Error (ret code: %s) calling "%s" in %s' % (error.returncode,
115 error.cmd, chrome_src_dir))
bsalomonc43f2af2016-02-17 10:42:46 -0800116
bsalomon90b5cc32016-08-11 08:25:41 -0700117 if not args.no_hooks:
118 try:
119 subprocess.check_call([gclient, 'runhooks'], cwd=chrome_src_dir)
120 except subprocess.CalledProcessError as error:
121 sys.exit('Error (ret code: %s) calling "%s" in %s' % (
122 error.returncode, error.cmd, chrome_src_dir))
borenetb6aafe62016-08-02 07:02:52 -0700123
borenet86baf3d2016-08-02 08:37:50 -0700124 gn = 'gn'
borenetb6aafe62016-08-02 07:02:52 -0700125 platform = 'linux64'
126 if sys.platform == 'darwin':
127 platform = 'mac'
128 elif sys.platform == 'win32':
129 platform = 'win'
borenet86baf3d2016-08-02 08:37:50 -0700130 gn = 'gn.exe'
131 gn = os.path.join(chrome_src_dir, 'buildtools', platform, gn)
borenetb6aafe62016-08-02 07:02:52 -0700132 try:
bsalomon795390b2016-11-04 10:54:54 -0700133 gnargs = 'is_component_build=false is_debug=false ' + args.extra_gn_args
134 subprocess.check_call([gn, 'gen', chrome_target_dir_rel, '--args='+gnargs],
borenetb6aafe62016-08-02 07:02:52 -0700135 cwd=chrome_src_dir)
136 except subprocess.CalledProcessError as error:
137 sys.exit('Error (ret code: %s) calling "%s" in %s' % (
138 error.returncode, error.cmd, chrome_src_dir))
139
140 try:
bsalomonc43f2af2016-02-17 10:42:46 -0800141 subprocess.check_call(['ninja'] + shlex.split(args.extra_ninja_args) +
142 ['-C', chrome_target_dir_rel, 'command_buffer_gles2'],
143 cwd=chrome_src_dir)
144 except subprocess.CalledProcessError as error:
borenet48b88cc2016-04-11 10:16:01 -0700145 sys.exit('Error (ret code: %s) calling "%s" in %s' % (error.returncode,
146 error.cmd, chrome_src_dir))
bsalomonc43f2af2016-02-17 10:42:46 -0800147
bsalomon9f071d12016-07-21 08:05:01 -0700148 shared_lib_src_dir = os.path.join(chrome_src_dir, chrome_target_dir_rel)
bsalomonc969bfc2016-02-18 06:40:55 -0800149
bsalomonc969bfc2016-02-18 06:40:55 -0800150 shared_lib_src = os.path.join(shared_lib_src_dir, shared_lib_name)
bsalomon795390b2016-11-04 10:54:54 -0700151 shared_lib_dst = os.path.join(args.output_dir, shared_lib_name)
bsalomonc43f2af2016-02-17 10:42:46 -0800152
153 if not os.path.isfile(shared_lib_src):
154 sys.exit('Command buffer shared library not at expected location: ' +
155 shared_lib_src)
156
157 shutil.copy2(shared_lib_src, shared_lib_dst)
158
159 if not os.path.isfile(shared_lib_dst):
160 sys.exit('Command buffer library not copied to ' + shared_lib_dst)
161
162 print('Command buffer library copied to ' + shared_lib_dst)
163
164
165if __name__ == '__main__':
166 main()
167