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, |
bsalomon | 795390b | 2016-11-04 10:54:54 -0700 | [diff] [blame] | 28 | help='path to copy the command buffer shared library to. Typically this ' |
| 29 | 'is out/Debug or out/Release in a Skia repository') |
bsalomon | c43f2af | 2016-02-17 10:42:46 -0800 | [diff] [blame] | 30 | parser.add_argument('--make-output-dir', default=False, action='store_true', |
| 31 | help='Makes the output directory if it does not already exist.') |
bsalomon | 795390b | 2016-11-04 10:54:54 -0700 | [diff] [blame] | 32 | 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')) |
bsalomon | c43f2af | 2016-02-17 10:42:46 -0800 | [diff] [blame] | 39 | 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') |
bsalomon | 90b5cc3 | 2016-08-11 08:25:41 -0700 | [diff] [blame] | 46 | 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') |
bsalomon | c43f2af | 2016-02-17 10:42:46 -0800 | [diff] [blame] | 49 | 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 | |
bsalomon | 90b5cc3 | 2016-08-11 08:25:41 -0700 | [diff] [blame] | 54 | if args.no_hooks: |
| 55 | args.no_sync = True |
| 56 | |
bsalomon | c43f2af | 2016-02-17 10:42:46 -0800 | [diff] [blame] | 57 | 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 | |
bsalomon | c43f2af | 2016-02-17 10:42:46 -0800 | [diff] [blame] | 65 | 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 | |
bsalomon | 795390b | 2016-11-04 10:54:54 -0700 | [diff] [blame] | 77 | chrome_target_dir_rel = os.path.join('out', args.chrome_out_dir) |
bsalomon | c43f2af | 2016-02-17 10:42:46 -0800 | [diff] [blame] | 78 | |
bsalomon | 1526e0a | 2016-02-18 10:01:11 -0800 | [diff] [blame] | 79 | # The command buffer shared library will have a different name on Linux, |
bsalomon | 795390b | 2016-11-04 10:54:54 -0700 | [diff] [blame] | 80 | # Mac, and Windows. Also, the name of the gclient executable we call out to |
| 81 | # has a .bat file extension on Windows. |
bsalomon | 1526e0a | 2016-02-18 10:01:11 -0800 | [diff] [blame] | 82 | platform = sys.platform |
| 83 | if platform == 'cygwin': |
| 84 | platform = 'win32' |
| 85 | |
| 86 | shared_lib_name = 'libcommand_buffer_gles2.so' |
bsalomon | 1526e0a | 2016-02-18 10:01:11 -0800 | [diff] [blame] | 87 | gclient = 'gclient' |
| 88 | if platform == 'darwin': |
| 89 | shared_lib_name = 'libcommand_buffer_gles2.dylib' |
bsalomon | 1526e0a | 2016-02-18 10:01:11 -0800 | [diff] [blame] | 90 | elif platform == 'win32': |
| 91 | shared_lib_name = 'command_buffer_gles2.dll' |
bsalomon | 1526e0a | 2016-02-18 10:01:11 -0800 | [diff] [blame] | 92 | gclient = 'gclient.bat' |
| 93 | |
bsalomon | c43f2af | 2016-02-17 10:42:46 -0800 | [diff] [blame] | 94 | if not args.no_sync: |
| 95 | try: |
| 96 | subprocess.check_call(['git', 'fetch'], cwd=chrome_src_dir) |
| 97 | except subprocess.CalledProcessError as error: |
borenet | 48b88cc | 2016-04-11 10:16:01 -0700 | [diff] [blame] | 98 | sys.exit('Error (ret code: %s) calling "%s" in %s' % (error.returncode, |
| 99 | error.cmd, chrome_src_dir)) |
bsalomon | c43f2af | 2016-02-17 10:42:46 -0800 | [diff] [blame] | 100 | |
borenet | 7bedaf5 | 2016-04-25 11:22:41 -0700 | [diff] [blame] | 101 | 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)) |
bsalomon | c43f2af | 2016-02-17 10:42:46 -0800 | [diff] [blame] | 107 | |
bsalomon | c43f2af | 2016-02-17 10:42:46 -0800 | [diff] [blame] | 108 | try: |
bsalomon | c969bfc | 2016-02-18 06:40:55 -0800 | [diff] [blame] | 109 | os.environ['GYP_GENERATORS'] = 'ninja' |
bsalomon | 90b5cc3 | 2016-08-11 08:25:41 -0700 | [diff] [blame] | 110 | subprocess.check_call([gclient, 'sync', '--reset', '--force', |
| 111 | '--nohooks'], |
bsalomon | c969bfc | 2016-02-18 06:40:55 -0800 | [diff] [blame] | 112 | cwd=chrome_src_dir) |
bsalomon | c43f2af | 2016-02-17 10:42:46 -0800 | [diff] [blame] | 113 | except subprocess.CalledProcessError as error: |
borenet | 48b88cc | 2016-04-11 10:16:01 -0700 | [diff] [blame] | 114 | sys.exit('Error (ret code: %s) calling "%s" in %s' % (error.returncode, |
| 115 | error.cmd, chrome_src_dir)) |
bsalomon | c43f2af | 2016-02-17 10:42:46 -0800 | [diff] [blame] | 116 | |
bsalomon | 90b5cc3 | 2016-08-11 08:25:41 -0700 | [diff] [blame] | 117 | 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)) |
borenet | b6aafe6 | 2016-08-02 07:02:52 -0700 | [diff] [blame] | 123 | |
borenet | 86baf3d | 2016-08-02 08:37:50 -0700 | [diff] [blame] | 124 | gn = 'gn' |
borenet | b6aafe6 | 2016-08-02 07:02:52 -0700 | [diff] [blame] | 125 | platform = 'linux64' |
| 126 | if sys.platform == 'darwin': |
| 127 | platform = 'mac' |
| 128 | elif sys.platform == 'win32': |
| 129 | platform = 'win' |
borenet | 86baf3d | 2016-08-02 08:37:50 -0700 | [diff] [blame] | 130 | gn = 'gn.exe' |
| 131 | gn = os.path.join(chrome_src_dir, 'buildtools', platform, gn) |
borenet | b6aafe6 | 2016-08-02 07:02:52 -0700 | [diff] [blame] | 132 | try: |
bsalomon | 795390b | 2016-11-04 10:54:54 -0700 | [diff] [blame] | 133 | gnargs = 'is_component_build=false is_debug=false ' + args.extra_gn_args |
| 134 | subprocess.check_call([gn, 'gen', chrome_target_dir_rel, '--args='+gnargs], |
borenet | b6aafe6 | 2016-08-02 07:02:52 -0700 | [diff] [blame] | 135 | 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: |
bsalomon | c43f2af | 2016-02-17 10:42:46 -0800 | [diff] [blame] | 141 | 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: |
borenet | 48b88cc | 2016-04-11 10:16:01 -0700 | [diff] [blame] | 145 | sys.exit('Error (ret code: %s) calling "%s" in %s' % (error.returncode, |
| 146 | error.cmd, chrome_src_dir)) |
bsalomon | c43f2af | 2016-02-17 10:42:46 -0800 | [diff] [blame] | 147 | |
bsalomon | 9f071d1 | 2016-07-21 08:05:01 -0700 | [diff] [blame] | 148 | 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] | 149 | |
bsalomon | c969bfc | 2016-02-18 06:40:55 -0800 | [diff] [blame] | 150 | shared_lib_src = os.path.join(shared_lib_src_dir, shared_lib_name) |
bsalomon | 795390b | 2016-11-04 10:54:54 -0700 | [diff] [blame] | 151 | shared_lib_dst = os.path.join(args.output_dir, shared_lib_name) |
bsalomon | c43f2af | 2016-02-17 10:42:46 -0800 | [diff] [blame] | 152 | |
| 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 | |
| 165 | if __name__ == '__main__': |
| 166 | main() |
| 167 | |