1#!/usr/bin/env python 2# 3# Copyright 2013 The Flutter Authors. All rights reserved. 4# Use of this source code is governed by a BSD-style license that can be 5# found in the LICENSE file. 6""" Gather all the fuchsia artifacts to a destination directory. 7""" 8 9import argparse 10import errno 11import json 12import os 13import platform 14import shutil 15import subprocess 16import sys 17 18_ARTIFACT_PATH_TO_DST = { 19 'flutter_jit_runner': 'flutter_jit_runner', 20 'icudtl.dat': 'data/icudtl.dat', 21 'dart_runner': 'dart_runner', 22 'flutter_patched_sdk': 'flutter_patched_sdk' 23} 24 25 26def EnsureParentExists(path): 27 dir_name, _ = os.path.split(path) 28 if not os.path.exists(dir_name): 29 os.makedirs(dir_name) 30 31 32def CopyPath(src, dst): 33 try: 34 EnsureParentExists(dst) 35 shutil.copytree(src, dst) 36 except OSError as exc: 37 if exc.errno == errno.ENOTDIR: 38 shutil.copy(src, dst) 39 else: 40 raise 41 42 43def CreateMetaPackage(dst_root, far_name): 44 meta = os.path.join(dst_root, 'meta') 45 if not os.path.isdir(meta): 46 os.makedirs(meta) 47 content = {} 48 content['name'] = far_name 49 content['version'] = '0' 50 package = os.path.join(meta, 'package') 51 with open(package, 'w') as out_file: 52 json.dump(content, out_file) 53 54 55def GatherArtifacts(src_root, dst_root, create_meta_package=True): 56 if not os.path.exists(dst_root): 57 os.makedirs(dst_root) 58 else: 59 shutil.rmtree(dst_root) 60 61 for src_rel, dst_rel in _ARTIFACT_PATH_TO_DST.iteritems(): 62 src_full = os.path.join(src_root, src_rel) 63 dst_full = os.path.join(dst_root, dst_rel) 64 if not os.path.exists(src_full): 65 print 'Unable to find artifact: ', str(src_full) 66 sys.exit(1) 67 CopyPath(src_full, dst_full) 68 69 if create_meta_package: 70 CreateMetaPackage(dst_root, 'flutter_runner') 71 72 73def main(): 74 parser = argparse.ArgumentParser() 75 76 parser.add_argument( 77 '--artifacts-root', dest='artifacts_root', action='store', required=True) 78 parser.add_argument( 79 '--dest-dir', dest='dst_dir', action='store', required=True) 80 81 args = parser.parse_args() 82 83 assert os.path.exists(args.artifacts_root) 84 dst_parent = os.path.abspath(os.path.join(args.dst_dir, os.pardir)) 85 assert os.path.exists(dst_parent) 86 87 GatherArtifacts(args.artifacts_root, args.dst_dir) 88 return 0 89 90 91if __name__ == '__main__': 92 sys.exit(main()) 93