OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 import argparse |
| 7 import logging |
| 8 import os |
| 9 import shutil |
| 10 import subprocess |
| 11 |
| 12 from mopy.paths import Paths |
| 13 |
| 14 |
| 15 def git_revision(): |
| 16 return subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip() |
| 17 |
| 18 |
| 19 def mojo_filter(path): |
| 20 if not os.path.isfile(path): |
| 21 return False |
| 22 _, ext = os.path.splitext(path) |
| 23 if ext != '.mojo': |
| 24 return False |
| 25 return 'apptests' not in os.path.basename(path) |
| 26 |
| 27 |
| 28 def sky_filter(path): |
| 29 if os.path.isdir(path): |
| 30 return True |
| 31 _, ext = os.path.splitext(path) |
| 32 return ext == '.sky' |
| 33 |
| 34 |
| 35 def copy(from_root, to_root, filter_func=None): |
| 36 if os.path.exists(to_root): |
| 37 shutil.rmtree(to_root) |
| 38 os.makedirs(to_root) |
| 39 |
| 40 for root, dirs, files in os.walk(from_root): |
| 41 # filter_func expects paths not names, so wrap it to make them absolute. |
| 42 wrapped_filter = None |
| 43 if filter_func: |
| 44 wrapped_filter = lambda name: filter_func(os.path.join(root, name)) |
| 45 |
| 46 for name in filter(wrapped_filter, files): |
| 47 from_path = os.path.join(root, name) |
| 48 root_rel_path = os.path.relpath(from_path, from_root) |
| 49 to_path = os.path.join(to_root, root_rel_path) |
| 50 to_dir = os.path.dirname(to_path) |
| 51 if not os.path.exists(to_dir): |
| 52 os.makedirs(to_dir) |
| 53 shutil.copyfile(from_path, to_path) |
| 54 |
| 55 dirs[:] = filter(wrapped_filter, dirs) |
| 56 |
| 57 def main(): |
| 58 logging.basicConfig(level=logging.WARN) |
| 59 parser = argparse.ArgumentParser(description='Deploy a new build of mojo.') |
| 60 parser.add_argument('deploy_root', type=str) |
| 61 args = parser.parse_args() |
| 62 |
| 63 # Always use android release? |
| 64 rel_build_dir = os.path.join('out', 'android_Release') |
| 65 build_dir = os.path.join(Paths().src_root, rel_build_dir) |
| 66 paths = Paths(build_dir=build_dir) |
| 67 |
| 68 def deploy_path(rel_path): |
| 69 return os.path.join(args.deploy_root, rel_path) |
| 70 |
| 71 def src_path(rel_path): |
| 72 return os.path.join(paths.src_root, rel_path) |
| 73 |
| 74 copy(paths.build_dir, deploy_path('mojo'), mojo_filter) |
| 75 copy(src_path('sky/examples'), deploy_path('sky/examples'), sky_filter) |
| 76 copy(src_path('sky/framework'), deploy_path('sky/framework'), sky_filter) |
| 77 copy(os.path.join(paths.build_dir, 'gen'), deploy_path('gen'), sky_filter) |
| 78 |
| 79 subprocess.check_call(['git', 'add', '.'], cwd=args.deploy_root) |
| 80 subprocess.check_call([ |
| 81 'git', 'commit', |
| 82 '-m', '%s from %s' % (rel_build_dir, git_revision()) |
| 83 ], cwd=args.deploy_root) |
| 84 |
| 85 |
| 86 |
| 87 if __name__ == '__main__': |
| 88 main() |
OLD | NEW |