blob: 88748d678921885d923f4ef3b4725ccb1c3fc000 [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
117 try:
118 subprocess.check_call(['git', 'checkout', args.chrome_revision],
119 cwd=chrome_src_dir)
120 except subprocess.CalledProcessError as error:
borenet48b88cc2016-04-11 10:16:01 -0700121 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
124 if not args.no_sync:
125 try:
bsalomonc969bfc2016-02-18 06:40:55 -0800126 os.environ['GYP_GENERATORS'] = 'ninja'
bsalomon1526e0a2016-02-18 10:01:11 -0800127 subprocess.check_call([gclient, 'sync', '--reset', '--force'],
bsalomonc969bfc2016-02-18 06:40:55 -0800128 cwd=chrome_src_dir)
bsalomonc43f2af2016-02-17 10:42:46 -0800129 except subprocess.CalledProcessError as error:
borenet48b88cc2016-04-11 10:16:01 -0700130 sys.exit('Error (ret code: %s) calling "%s" in %s' % (error.returncode,
131 error.cmd, chrome_src_dir))
bsalomonc43f2af2016-02-17 10:42:46 -0800132
133 try:
134 subprocess.check_call(['ninja'] + shlex.split(args.extra_ninja_args) +
135 ['-C', chrome_target_dir_rel, 'command_buffer_gles2'],
136 cwd=chrome_src_dir)
137 except subprocess.CalledProcessError as error:
borenet48b88cc2016-04-11 10:16:01 -0700138 sys.exit('Error (ret code: %s) calling "%s" in %s' % (error.returncode,
139 error.cmd, chrome_src_dir))
bsalomonc43f2af2016-02-17 10:42:46 -0800140
bsalomonc969bfc2016-02-18 06:40:55 -0800141 shared_lib_src_dir = os.path.join(chrome_src_dir, chrome_target_dir_rel,
142 shared_lib_subdir)
143 shared_lib_dst_dir = os.path.join(args.output_dir, shared_lib_subdir)
144 # Make the subdir for the dst if does not exist
145 if shared_lib_subdir and not os.path.isdir(shared_lib_dst_dir):
146 os.mkdir(shared_lib_dst_dir)
147
bsalomonc969bfc2016-02-18 06:40:55 -0800148 shared_lib_src = os.path.join(shared_lib_src_dir, shared_lib_name)
149 shared_lib_dst = os.path.join(shared_lib_dst_dir, shared_lib_name)
bsalomonc43f2af2016-02-17 10:42:46 -0800150
151 if not os.path.isfile(shared_lib_src):
152 sys.exit('Command buffer shared library not at expected location: ' +
153 shared_lib_src)
154
155 shutil.copy2(shared_lib_src, shared_lib_dst)
156
157 if not os.path.isfile(shared_lib_dst):
158 sys.exit('Command buffer library not copied to ' + shared_lib_dst)
159
160 print('Command buffer library copied to ' + shared_lib_dst)
161
162
163if __name__ == '__main__':
164 main()
165