blob: 0349419030f56664f508f9619383ed1a967e1132 [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.')
31 parser.add_argument('-f', '--fetch', action='store_true', default=False,
32 help=('Create Chromium src directory and fetch chromium checkout (if '
33 'directory does not already exist)'))
34 parser.add_argument('--chrome-build-type', default='Release',
35 help='Type of build for the command buffer (e.g. Debug or Release)')
36 parser.add_argument('--extra-ninja-args', default='',
37 help=('Extra arguments to pass to ninja when building the command '
38 'buffer shared library'))
39 parser.add_argument('--chrome-revision', default='origin/lkgr',
40 help='Revision (hash, branch, tag) of Chromium to use.')
41 parser.add_argument('--no-sync', action='store_true', default=False,
42 help='Don\'t run git fetch or gclient sync in the Chromium tree')
43 args = parser.parse_args()
44
45 args.chrome_dir = os.path.abspath(args.chrome_dir)
46 args.output_dir = os.path.abspath(args.output_dir)
47
48 if os.path.isfile(args.chrome_dir):
49 sys.exit(args.chrome_dir + ' exists but is a file.')
50
51 if os.path.isfile(args.output_dir):
52 sys.exit(args.output_dir + ' exists but is a file.')
53
54 chrome_src_dir = os.path.join(args.chrome_dir, 'src')
55
56 if os.path.isfile(chrome_src_dir):
57 sys.exit(chrome_src_dir + ' exists but is a file.')
58 elif not os.path.isdir(chrome_src_dir):
59 if args.fetch:
60 if os.path.isdir(args.chrome_dir):
61 # If chrome_dir is a dir but chrome_src_dir does not exist we will only
62 # fetch into chrome_dir if it is empty.
63 if os.listdir(args.chrome_dir):
64 sys.exit(args.chrome_dir + ' is not a chromium checkout and is not '
65 'empty.')
66 else:
67 os.makedirs(args.chrome_dir)
68 if not os.path.isdir(args.chrome_dir):
69 sys.exit('Could not create ' + args.chrome_dir)
70 try:
71 subprocess.check_call(['fetch', 'chromium'], cwd=args.chrome_dir)
72 except subprocess.CalledProcessError as error:
73 sys.exit('Error (ret code: %s) calling "%s" in %s' % error.returncode,
74 error.cmd, args.chrome_dir)
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 else:
85 sys.exit(args.output_dir + ' does not exist (specify --make-output-dir '
86 'to create).')
87
88 chrome_target_dir_rel = os.path.join('out', args.chrome_build_type)
bsalomonc43f2af2016-02-17 10:42:46 -080089
bsalomon1526e0a2016-02-18 10:01:11 -080090 # The command buffer shared library will have a different name on Linux,
91 # Mac, and Windows. Also, on Linux it will be in a 'lib' subdirectory and
92 # needs to be placed in a 'lib' subdirectory of the directory containing the
93 # Skia executable. Also, the name of the gclient executable we call out to has
94 # a .bat file extension on Windows.
95 platform = sys.platform
96 if platform == 'cygwin':
97 platform = 'win32'
98
99 shared_lib_name = 'libcommand_buffer_gles2.so'
100 shared_lib_subdir = 'lib'
101 gclient = 'gclient'
102 if platform == 'darwin':
103 shared_lib_name = 'libcommand_buffer_gles2.dylib'
104 shared_lib_subdir = ''
105 elif platform == 'win32':
106 shared_lib_name = 'command_buffer_gles2.dll'
107 shared_lib_subdir = ''
108 gclient = 'gclient.bat'
109
bsalomonc43f2af2016-02-17 10:42:46 -0800110 if not args.no_sync:
111 try:
112 subprocess.check_call(['git', 'fetch'], cwd=chrome_src_dir)
113 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
borenet7bedaf52016-04-25 11:22:41 -0700117 try:
118 subprocess.check_call(['git', 'checkout', args.chrome_revision],
119 cwd=chrome_src_dir)
120 except subprocess.CalledProcessError as error:
121 sys.exit('Error (ret code: %s) calling "%s" in %s' % (error.returncode,
122 error.cmd, chrome_src_dir))
bsalomonc43f2af2016-02-17 10:42:46 -0800123
bsalomonc43f2af2016-02-17 10:42:46 -0800124 try:
bsalomonc969bfc2016-02-18 06:40:55 -0800125 os.environ['GYP_GENERATORS'] = 'ninja'
bsalomon1526e0a2016-02-18 10:01:11 -0800126 subprocess.check_call([gclient, 'sync', '--reset', '--force'],
bsalomonc969bfc2016-02-18 06:40:55 -0800127 cwd=chrome_src_dir)
bsalomonc43f2af2016-02-17 10:42:46 -0800128 except subprocess.CalledProcessError as error:
borenet48b88cc2016-04-11 10:16:01 -0700129 sys.exit('Error (ret code: %s) calling "%s" in %s' % (error.returncode,
130 error.cmd, chrome_src_dir))
bsalomonc43f2af2016-02-17 10:42:46 -0800131
132 try:
borenetb6aafe62016-08-02 07:02:52 -0700133 subprocess.check_call([gclient, 'runhooks'], cwd=chrome_src_dir)
134 except subprocess.CalledProcessError as error:
135 sys.exit('Error (ret code: %s) calling "%s" in %s' % (
136 error.returncode, error.cmd, chrome_src_dir))
137
138 platform = 'linux64'
139 if sys.platform == 'darwin':
140 platform = 'mac'
141 elif sys.platform == 'win32':
142 platform = 'win'
143 gn = os.path.join(chrome_src_dir, 'buildtools', platform, 'gn')
144 try:
145 subprocess.check_call([gn, 'gen', chrome_target_dir_rel],
146 cwd=chrome_src_dir)
147 except subprocess.CalledProcessError as error:
148 sys.exit('Error (ret code: %s) calling "%s" in %s' % (
149 error.returncode, error.cmd, chrome_src_dir))
150
151 try:
bsalomonc43f2af2016-02-17 10:42:46 -0800152 subprocess.check_call(['ninja'] + shlex.split(args.extra_ninja_args) +
153 ['-C', chrome_target_dir_rel, 'command_buffer_gles2'],
154 cwd=chrome_src_dir)
155 except subprocess.CalledProcessError as error:
borenet48b88cc2016-04-11 10:16:01 -0700156 sys.exit('Error (ret code: %s) calling "%s" in %s' % (error.returncode,
157 error.cmd, chrome_src_dir))
bsalomonc43f2af2016-02-17 10:42:46 -0800158
bsalomon9f071d12016-07-21 08:05:01 -0700159 shared_lib_src_dir = os.path.join(chrome_src_dir, chrome_target_dir_rel)
bsalomonc969bfc2016-02-18 06:40:55 -0800160 shared_lib_dst_dir = os.path.join(args.output_dir, shared_lib_subdir)
161 # Make the subdir for the dst if does not exist
162 if shared_lib_subdir and not os.path.isdir(shared_lib_dst_dir):
163 os.mkdir(shared_lib_dst_dir)
164
bsalomonc969bfc2016-02-18 06:40:55 -0800165 shared_lib_src = os.path.join(shared_lib_src_dir, shared_lib_name)
166 shared_lib_dst = os.path.join(shared_lib_dst_dir, shared_lib_name)
bsalomonc43f2af2016-02-17 10:42:46 -0800167
168 if not os.path.isfile(shared_lib_src):
169 sys.exit('Command buffer shared library not at expected location: ' +
170 shared_lib_src)
171
172 shutil.copy2(shared_lib_src, shared_lib_dst)
173
174 if not os.path.isfile(shared_lib_dst):
175 sys.exit('Command buffer library not copied to ' + shared_lib_dst)
176
177 print('Command buffer library copied to ' + shared_lib_dst)
178
179
180if __name__ == '__main__':
181 main()
182