OLD | NEW |
(Empty) | |
| 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.') |
| 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) |
| 89 chrome_target_dir = os.path.join(chrome_src_dir, chrome_target_dir_rel) |
| 90 |
| 91 if not args.no_sync: |
| 92 try: |
| 93 subprocess.check_call(['git', 'fetch'], cwd=chrome_src_dir) |
| 94 except subprocess.CalledProcessError as error: |
| 95 sys.exit('Error (ret code: %s) calling "%s" in %s' % error.returncode, |
| 96 error.cmd, chrome_src_dir) |
| 97 |
| 98 try: |
| 99 subprocess.check_call(['git', 'checkout', args.chrome_revision], |
| 100 cwd=chrome_src_dir) |
| 101 except subprocess.CalledProcessError as error: |
| 102 sys.exit('Error (ret code: %s) calling "%s" in %s' % error.returncode, |
| 103 error.cmd, chrome_src_dir) |
| 104 |
| 105 if not args.no_sync: |
| 106 try: |
| 107 subprocess.check_call(['gclient', 'sync'], cwd=chrome_src_dir) |
| 108 except subprocess.CalledProcessError as error: |
| 109 sys.exit('Error (ret code: %s) calling "%s" in %s' % error.returncode, |
| 110 error.cmd, chrome_src_dir) |
| 111 |
| 112 try: |
| 113 subprocess.check_call(['ninja'] + shlex.split(args.extra_ninja_args) + |
| 114 ['-C', chrome_target_dir_rel, 'command_buffer_gles2'], |
| 115 cwd=chrome_src_dir) |
| 116 except subprocess.CalledProcessError as error: |
| 117 sys.exit('Error (ret code: %s) calling "%s" in %s' % error.returncode, |
| 118 error.cmd, chrome_src_dir) |
| 119 |
| 120 shared_lib_src = os.path.join(chrome_target_dir, 'lib', |
| 121 'libcommand_buffer_gles2.so') |
| 122 shared_lib_dst = os.path.join(args.output_dir, 'libcommand_buffer_gles2.so') |
| 123 |
| 124 if not os.path.isfile(shared_lib_src): |
| 125 sys.exit('Command buffer shared library not at expected location: ' + |
| 126 shared_lib_src) |
| 127 |
| 128 shutil.copy2(shared_lib_src, shared_lib_dst) |
| 129 |
| 130 if not os.path.isfile(shared_lib_dst): |
| 131 sys.exit('Command buffer library not copied to ' + shared_lib_dst) |
| 132 |
| 133 print('Command buffer library copied to ' + shared_lib_dst) |
| 134 |
| 135 |
| 136 if __name__ == '__main__': |
| 137 main() |
| 138 |
OLD | NEW |