blob: 4c8460b7193ec5346ebf8796822f922ca5545469 [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
90 if not args.no_sync:
91 try:
92 subprocess.check_call(['git', 'fetch'], cwd=chrome_src_dir)
93 except subprocess.CalledProcessError as error:
94 sys.exit('Error (ret code: %s) calling "%s" in %s' % error.returncode,
95 error.cmd, chrome_src_dir)
96
97 try:
98 subprocess.check_call(['git', 'checkout', args.chrome_revision],
99 cwd=chrome_src_dir)
100 except subprocess.CalledProcessError as error:
101 sys.exit('Error (ret code: %s) calling "%s" in %s' % error.returncode,
102 error.cmd, chrome_src_dir)
103
104 if not args.no_sync:
105 try:
bsalomonc969bfc2016-02-18 06:40:55 -0800106 os.environ['GYP_GENERATORS'] = 'ninja'
107 subprocess.check_call(['gclient', 'sync', '--reset', '--force'],
108 cwd=chrome_src_dir)
bsalomonc43f2af2016-02-17 10:42:46 -0800109 except subprocess.CalledProcessError as error:
110 sys.exit('Error (ret code: %s) calling "%s" in %s' % error.returncode,
111 error.cmd, chrome_src_dir)
112
113 try:
114 subprocess.check_call(['ninja'] + shlex.split(args.extra_ninja_args) +
115 ['-C', chrome_target_dir_rel, 'command_buffer_gles2'],
116 cwd=chrome_src_dir)
117 except subprocess.CalledProcessError as error:
118 sys.exit('Error (ret code: %s) calling "%s" in %s' % error.returncode,
119 error.cmd, chrome_src_dir)
120
bsalomonc969bfc2016-02-18 06:40:55 -0800121 # The command buffer shared library will have a different extension on Linux,
122 # Mac, and Windows. Also, on Linux it will be in a 'lib' subdirectory and
123 # needs to be placed in a 'lib' subdirectory of the directory containing the
124 # Skia executable.
125 platform = sys.platform
126 if platform == 'cygwin':
127 platform = 'win32'
128
129 shared_lib_ext = '.so'
130 shared_lib_subdir = 'lib'
131 if platform == 'darwin':
132 shared_lib_ext = '.dylib'
133 shared_lib_subdir = ''
134 elif platform == 'win32':
135 shared_lib_ext = '.dll'
136 shared_lib_subdir = ''
137
138 shared_lib_src_dir = os.path.join(chrome_src_dir, chrome_target_dir_rel,
139 shared_lib_subdir)
140 shared_lib_dst_dir = os.path.join(args.output_dir, shared_lib_subdir)
141 # Make the subdir for the dst if does not exist
142 if shared_lib_subdir and not os.path.isdir(shared_lib_dst_dir):
143 os.mkdir(shared_lib_dst_dir)
144
145 shared_lib_name = 'libcommand_buffer_gles2' + shared_lib_ext
146 shared_lib_src = os.path.join(shared_lib_src_dir, shared_lib_name)
147 shared_lib_dst = os.path.join(shared_lib_dst_dir, shared_lib_name)
bsalomonc43f2af2016-02-17 10:42:46 -0800148
149 if not os.path.isfile(shared_lib_src):
150 sys.exit('Command buffer shared library not at expected location: ' +
151 shared_lib_src)
152
153 shutil.copy2(shared_lib_src, shared_lib_dst)
154
155 if not os.path.isfile(shared_lib_dst):
156 sys.exit('Command buffer library not copied to ' + shared_lib_dst)
157
158 print('Command buffer library copied to ' + shared_lib_dst)
159
160
161if __name__ == '__main__':
162 main()
163