| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import argparse | 6 import argparse |
| 7 import glob | 7 import glob |
| 8 import os | 8 import os |
| 9 import subprocess | 9 import subprocess |
| 10 import sys | 10 import sys |
| 11 import tempfile | 11 import tempfile |
| 12 import time | 12 import time |
| 13 import zipfile | 13 import zipfile |
| 14 | 14 |
| 15 import mopy.gn as gn | 15 import mopy.gn as gn |
| 16 from mopy.config import Config | 16 from mopy.config import Config |
| 17 from mopy.paths import Paths | 17 from mopy.paths import Paths |
| 18 from mopy.version import Version | 18 from mopy.version import Version |
| 19 | 19 |
| 20 BLACKLISTED_APPS = [ | 20 BLACKLISTED_APPS = [ |
| 21 # The network service apps are not produced out of the Mojo repo, but may | 21 # The network service apps are not produced out of the Mojo repo, but may |
| 22 # be present in the build dir. | 22 # be present in the build dir. |
| 23 "network_service.mojo", | 23 "network_service.mojo", |
| 24 "network_service_apptests.mojo", | 24 "network_service_apptests.mojo", |
| 25 ] | 25 ] |
| 26 | 26 |
| 27 def target(config): |
| 28 return config.target_os + "-" + config.target_arch |
| 29 |
| 27 def find_apps_to_upload(build_dir): | 30 def find_apps_to_upload(build_dir): |
| 28 apps = [] | 31 apps = [] |
| 29 for path in glob.glob(build_dir + "/*"): | 32 for path in glob.glob(build_dir + "/*"): |
| 30 if not os.path.isfile(path): | 33 if not os.path.isfile(path): |
| 31 continue | 34 continue |
| 32 _, ext = os.path.splitext(path) | 35 _, ext = os.path.splitext(path) |
| 33 if ext != '.mojo': | 36 if ext != '.mojo': |
| 34 continue | 37 continue |
| 35 if os.path.basename(path) in BLACKLISTED_APPS: | 38 if os.path.basename(path) in BLACKLISTED_APPS: |
| 36 continue | 39 continue |
| 37 apps.append(path) | 40 apps.append(path) |
| 38 return apps | 41 return apps |
| 39 | 42 |
| 40 def upload(config, source, dest, dry_run): | 43 def upload(config, source, dest, dry_run): |
| 41 paths = Paths(config) | 44 paths = Paths(config) |
| 42 sys.path.insert(0, os.path.join(paths.src_root, "tools")) | 45 sys.path.insert(0, os.path.join(paths.src_root, "tools")) |
| 43 # pylint: disable=F0401 | 46 # pylint: disable=F0401 |
| 44 import find_depot_tools | 47 import find_depot_tools |
| 45 | 48 |
| 46 depot_tools_path = find_depot_tools.add_depot_tools_to_path() | 49 depot_tools_path = find_depot_tools.add_depot_tools_to_path() |
| 47 gsutil_exe = os.path.join(depot_tools_path, "third_party", "gsutil", "gsutil") | 50 gsutil_exe = os.path.join(depot_tools_path, "third_party", "gsutil", "gsutil") |
| 48 | 51 |
| 49 if dry_run: | 52 if dry_run: |
| 50 print str([gsutil_exe, "cp", source, dest]) | 53 print str([gsutil_exe, "cp", source, dest]) |
| 51 else: | 54 else: |
| 52 subprocess.check_call([gsutil_exe, "cp", source, dest]) | 55 subprocess.check_call([gsutil_exe, "cp", source, dest]) |
| 53 | 56 |
| 54 def upload_shell(config, dry_run, verbose): | 57 def upload_shell(config, dry_run, verbose): |
| 55 paths = Paths(config) | 58 paths = Paths(config) |
| 56 zipfile_name = "%s-%s" % (config.target_os, config.target_arch) | 59 zipfile_name = target(config) |
| 60 # TODO(blundell): Change this to be in the same structure as the LATEST files, |
| 61 # e.g., gs://mojo/shell/linux-x64/<version>/shell.zip. |
| 57 dest = "gs://mojo/shell/" + Version().version + "/" + zipfile_name + ".zip" | 62 dest = "gs://mojo/shell/" + Version().version + "/" + zipfile_name + ".zip" |
| 58 with tempfile.NamedTemporaryFile() as zip_file: | 63 with tempfile.NamedTemporaryFile() as zip_file: |
| 59 with zipfile.ZipFile(zip_file, 'w') as z: | 64 with zipfile.ZipFile(zip_file, 'w') as z: |
| 60 shell_path = paths.target_mojo_shell_path | 65 shell_path = paths.target_mojo_shell_path |
| 61 with open(shell_path) as shell_binary: | 66 with open(shell_path) as shell_binary: |
| 62 shell_filename = os.path.basename(shell_path) | 67 shell_filename = os.path.basename(shell_path) |
| 63 zipinfo = zipfile.ZipInfo(shell_filename) | 68 zipinfo = zipfile.ZipInfo(shell_filename) |
| 64 zipinfo.external_attr = 0777 << 16L | 69 zipinfo.external_attr = 0777 << 16L |
| 65 compress_type = zipfile.ZIP_DEFLATED | 70 compress_type = zipfile.ZIP_DEFLATED |
| 66 if config.target_os == Config.OS_ANDROID: | 71 if config.target_os == Config.OS_ANDROID: |
| 67 # The APK is already compressed. | 72 # The APK is already compressed. |
| 68 compress_type = zipfile.ZIP_STORED | 73 compress_type = zipfile.ZIP_STORED |
| 69 zipinfo.compress_type = compress_type | 74 zipinfo.compress_type = compress_type |
| 70 zipinfo.date_time = time.gmtime(os.path.getmtime(shell_path)) | 75 zipinfo.date_time = time.gmtime(os.path.getmtime(shell_path)) |
| 71 if verbose: | 76 if verbose: |
| 72 print "zipping %s" % shell_path | 77 print "zipping %s" % shell_path |
| 73 z.writestr(zipinfo, shell_binary.read()) | 78 z.writestr(zipinfo, shell_binary.read()) |
| 74 upload(config, zip_file.name, dest, dry_run) | 79 upload(config, zip_file.name, dest, dry_run) |
| 75 | 80 |
| 76 def upload_app(app_binary_path, config, dry_run): | 81 def upload_app(app_binary_path, config, dry_run): |
| 77 app_binary_name = os.path.basename(app_binary_path) | 82 app_binary_name = os.path.basename(app_binary_path) |
| 78 target = config.target_os + "-" + config.target_arch | |
| 79 version = Version().version | 83 version = Version().version |
| 80 dest = "gs://mojo/services/" + target + "/" + version + "/" + app_binary_name | 84 dest = ("gs://mojo/services/" + target(config) + "/" + version + "/" + |
| 85 app_binary_name) |
| 81 upload(config, app_binary_path, dest, dry_run) | 86 upload(config, app_binary_path, dest, dry_run) |
| 82 | 87 |
| 83 def update_version(config, subdir, dry_run): | 88 def update_version(config, subdir, dry_run): |
| 84 with tempfile.NamedTemporaryFile() as temp_version_file: | 89 with tempfile.NamedTemporaryFile() as temp_version_file: |
| 85 version = Version().version | 90 version = Version().version |
| 86 temp_version_file.write(version) | 91 temp_version_file.write(version) |
| 87 temp_version_file.flush() | 92 temp_version_file.flush() |
| 88 dest = "gs://mojo/%s/LATEST" % subdir | 93 dest = "gs://mojo/%s/%s/LATEST" % (subdir, target(config)) |
| 89 upload(config, temp_version_file.name, dest, dry_run) | 94 upload(config, temp_version_file.name, dest, dry_run) |
| 90 | 95 |
| 91 def main(): | 96 def main(): |
| 92 parser = argparse.ArgumentParser(description="Upload binaries for apps and " | 97 parser = argparse.ArgumentParser(description="Upload binaries for apps and " |
| 93 "the Mojo shell to google storage (by default on Linux, but this can be " | 98 "the Mojo shell to google storage (by default on Linux, but this can be " |
| 94 "changed via options).") | 99 "changed via options).") |
| 95 parser.add_argument("-n", "--dry_run", help="Dry run, do not actually "+ | 100 parser.add_argument("-n", "--dry_run", help="Dry run, do not actually "+ |
| 96 "upload", action="store_true") | 101 "upload", action="store_true") |
| 97 parser.add_argument("-v", "--verbose", help="Verbose mode", | 102 parser.add_argument("-v", "--verbose", help="Verbose mode", |
| 98 action="store_true") | 103 action="store_true") |
| (...skipping 12 matching lines...) Expand all Loading... |
| 111 apps_to_upload = find_apps_to_upload( | 116 apps_to_upload = find_apps_to_upload( |
| 112 gn.BuildDirectoryForConfig(config, Paths(config).src_root)) | 117 gn.BuildDirectoryForConfig(config, Paths(config).src_root)) |
| 113 for app in apps_to_upload: | 118 for app in apps_to_upload: |
| 114 upload_app(app, config, args.dry_run) | 119 upload_app(app, config, args.dry_run) |
| 115 update_version(config, "services", args.dry_run) | 120 update_version(config, "services", args.dry_run) |
| 116 | 121 |
| 117 return 0 | 122 return 0 |
| 118 | 123 |
| 119 if __name__ == "__main__": | 124 if __name__ == "__main__": |
| 120 sys.exit(main()) | 125 sys.exit(main()) |
| OLD | NEW |