bsalomon | c43f2af | 2016-02-17 10:42:46 -0800 | [diff] [blame] | 1 | #!/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 | """ |
| 10 | Script to build the command buffer shared library and copy it to Skia tree |
| 11 | """ |
| 12 | |
| 13 | |
| 14 | import argparse |
| 15 | import os |
| 16 | import shlex |
| 17 | import shutil |
| 18 | import subprocess |
| 19 | import sys |
| 20 | |
| 21 | |
| 22 | def 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.') |
bsalomon | 90b5cc3 | 2016-08-11 08:25:41 -0700 | [diff] [blame] | 31 | 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.') |
bsalomon | c43f2af | 2016-02-17 10:42:46 -0800 | [diff] [blame] | 35 | 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') |
bsalomon | 90b5cc3 | 2016-08-11 08:25:41 -0700 | [diff] [blame] | 42 | 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') |
bsalomon | c43f2af | 2016-02-17 10:42:46 -0800 | [diff] [blame] | 45 | 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 | |
bsalomon | 90b5cc3 | 2016-08-11 08:25:41 -0700 | [diff] [blame] | 50 | if args.no_hooks: |
| 51 | args.no_sync = True |
| 52 | |
bsalomon | c43f2af | 2016-02-17 10:42:46 -0800 | [diff] [blame] | 53 | 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 | |
bsalomon | c43f2af | 2016-02-17 10:42:46 -0800 | [diff] [blame] | 61 | 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) |
bsalomon | c43f2af | 2016-02-17 10:42:46 -0800 | [diff] [blame] | 74 | |
bsalomon | 1526e0a | 2016-02-18 10:01:11 -0800 | [diff] [blame] | 75 | # 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 | |
bsalomon | c43f2af | 2016-02-17 10:42:46 -0800 | [diff] [blame] | 95 | if not args.no_sync: |
| 96 | try: |
| 97 | subprocess.check_call(['git', 'fetch'], cwd=chrome_src_dir) |
| 98 | except subprocess.CalledProcessError as error: |
borenet | 48b88cc | 2016-04-11 10:16:01 -0700 | [diff] [blame] | 99 | sys.exit('Error (ret code: %s) calling "%s" in %s' % (error.returncode, |
| 100 | error.cmd, chrome_src_dir)) |
bsalomon | c43f2af | 2016-02-17 10:42:46 -0800 | [diff] [blame] | 101 | |
borenet | 7bedaf5 | 2016-04-25 11:22:41 -0700 | [diff] [blame] | 102 | 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)) |
bsalomon | c43f2af | 2016-02-17 10:42:46 -0800 | [diff] [blame] | 108 | |
bsalomon | c43f2af | 2016-02-17 10:42:46 -0800 | [diff] [blame] | 109 | try: |
bsalomon | c969bfc | 2016-02-18 06:40:55 -0800 | [diff] [blame] | 110 | os.environ['GYP_GENERATORS'] = 'ninja' |
bsalomon | 90b5cc3 | 2016-08-11 08:25:41 -0700 | [diff] [blame] | 111 | subprocess.check_call([gclient, 'sync', '--reset', '--force', |
| 112 | '--nohooks'], |
bsalomon | c969bfc | 2016-02-18 06:40:55 -0800 | [diff] [blame] | 113 | cwd=chrome_src_dir) |
bsalomon | c43f2af | 2016-02-17 10:42:46 -0800 | [diff] [blame] | 114 | except subprocess.CalledProcessError as error: |
borenet | 48b88cc | 2016-04-11 10:16:01 -0700 | [diff] [blame] | 115 | sys.exit('Error (ret code: %s) calling "%s" in %s' % (error.returncode, |
| 116 | error.cmd, chrome_src_dir)) |
bsalomon | c43f2af | 2016-02-17 10:42:46 -0800 | [diff] [blame] | 117 | |
bsalomon | 90b5cc3 | 2016-08-11 08:25:41 -0700 | [diff] [blame] | 118 | 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)) |
borenet | b6aafe6 | 2016-08-02 07:02:52 -0700 | [diff] [blame] | 124 | |
borenet | 86baf3d | 2016-08-02 08:37:50 -0700 | [diff] [blame] | 125 | gn = 'gn' |
borenet | b6aafe6 | 2016-08-02 07:02:52 -0700 | [diff] [blame] | 126 | platform = 'linux64' |
| 127 | if sys.platform == 'darwin': |
| 128 | platform = 'mac' |
| 129 | elif sys.platform == 'win32': |
| 130 | platform = 'win' |
borenet | 86baf3d | 2016-08-02 08:37:50 -0700 | [diff] [blame] | 131 | gn = 'gn.exe' |
| 132 | gn = os.path.join(chrome_src_dir, 'buildtools', platform, gn) |
borenet | b6aafe6 | 2016-08-02 07:02:52 -0700 | [diff] [blame] | 133 | try: |
borenet | a629166 | 2016-08-22 07:31:43 -0700 | [diff] [blame^] | 134 | subprocess.check_call([gn, 'gen', chrome_target_dir_rel, |
| 135 | '--args=is_component_build=false'], |
borenet | b6aafe6 | 2016-08-02 07:02:52 -0700 | [diff] [blame] | 136 | 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: |
bsalomon | c43f2af | 2016-02-17 10:42:46 -0800 | [diff] [blame] | 142 | 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: |
borenet | 48b88cc | 2016-04-11 10:16:01 -0700 | [diff] [blame] | 146 | sys.exit('Error (ret code: %s) calling "%s" in %s' % (error.returncode, |
| 147 | error.cmd, chrome_src_dir)) |
bsalomon | c43f2af | 2016-02-17 10:42:46 -0800 | [diff] [blame] | 148 | |
bsalomon | 9f071d1 | 2016-07-21 08:05:01 -0700 | [diff] [blame] | 149 | shared_lib_src_dir = os.path.join(chrome_src_dir, chrome_target_dir_rel) |
bsalomon | c969bfc | 2016-02-18 06:40:55 -0800 | [diff] [blame] | 150 | 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 | |
bsalomon | c969bfc | 2016-02-18 06:40:55 -0800 | [diff] [blame] | 155 | 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) |
bsalomon | c43f2af | 2016-02-17 10:42:46 -0800 | [diff] [blame] | 157 | |
| 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 | |
| 170 | if __name__ == '__main__': |
| 171 | main() |
| 172 | |