Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 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 imp | 7 import imp |
| 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 # A service's name is defined as the name of its subdirectory in the directory | 15 SERVICES = ["html_viewer", "network_service", "network_service_apptests"] |
| 16 # containing this file. | |
| 17 SERVICES = [ "network", "html_viewer" ] | |
| 18 | 16 |
| 19 SERVICE_BINARY_NAMES = { | 17 # A service does not need to expose interfaces. Those that do expose interfaces |
| 20 "network" : "network_service.mojo", | 18 # have their mojoms located in the directories listed below, in paths relative |
| 21 "html_viewer" : "html_viewer.mojo" | 19 # to the directory of this script. |
| 20 MOJOMS_IN_DIR = { | |
| 21 "network_service": os.path.join("network", "public", "interfaces") | |
| 22 } | 22 } |
| 23 | 23 |
| 24 # The network service is downloaded out-of-band rather than dynamically by the | 24 # The network service is downloaded out-of-band rather than dynamically by the |
| 25 # shell and thus can be stored zipped in the cloud. Other services are intended | 25 # shell and thus can be stored zipped in the cloud. Other services are intended |
| 26 # to be downloaded dynamically by the shell, which doesn't currently understand | 26 # to be downloaded dynamically by the shell, which doesn't currently understand |
| 27 # zipped binaries. | 27 # zipped binaries. |
| 28 SERVICES_WITH_ZIPPED_BINARIES = [ "network" ] | 28 SERVICES_WITH_ZIPPED_BINARIES = ["network_service", "network_service_apptests"] |
| 29 | 29 |
| 30 if not sys.platform.startswith("linux"): | 30 if not sys.platform.startswith("linux"): |
| 31 print "Only support linux for now" | 31 print "Only support linux for now" |
| 32 sys.exit(1) | 32 sys.exit(1) |
| 33 | 33 |
| 34 root_path = os.path.realpath( | 34 root_path = os.path.realpath( |
| 35 os.path.join( | 35 os.path.join( |
| 36 os.path.dirname( | 36 os.path.dirname( |
| 37 os.path.realpath(__file__)), | 37 os.path.realpath(__file__)), |
| 38 os.pardir, | 38 os.pardir, |
| 39 os.pardir)) | 39 os.pardir)) |
| 40 version = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=root_path) | 40 version = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=root_path) |
| 41 version = version.strip() | 41 version = version.strip() |
| 42 | 42 |
| 43 find_depot_tools_path = os.path.join(root_path, "tools", "find_depot_tools.py") | 43 find_depot_tools_path = os.path.join(root_path, "tools", "find_depot_tools.py") |
| 44 find_depot_tools = imp.load_source("find_depot_tools", find_depot_tools_path) | 44 find_depot_tools = imp.load_source("find_depot_tools", find_depot_tools_path) |
| 45 | 45 |
| 46 depot_tools_path = find_depot_tools.add_depot_tools_to_path() | 46 depot_tools_path = find_depot_tools.add_depot_tools_to_path() |
| 47 gsutil_exe = os.path.join(depot_tools_path, "third_party", "gsutil", "gsutil") | 47 gsutil_exe = os.path.join(depot_tools_path, "third_party", "gsutil", "gsutil") |
| 48 | 48 |
| 49 | 49 |
| 50 def gsutil_cp(source, dest, dry_run): | 50 def gsutil_cp(source, dest, dry_run): |
| 51 if dry_run: | 51 if dry_run: |
| 52 print "gsutil cp %s %s" % (source, dest) | 52 print "gsutil cp %s %s" % (source, dest) |
| 53 else: | 53 else: |
| 54 subprocess.check_call([gsutil_exe, "cp", source, dest]) | 54 subprocess.check_call([gsutil_exe, "cp", source, dest]) |
| 55 | 55 |
| 56 | 56 |
| 57 def upload_mojoms(service, dry_run): | 57 def upload_mojoms(service, absolute_mojom_directory_path, dry_run): |
| 58 script_dir = os.path.dirname(os.path.realpath(__file__)) | 58 dest = "gs://mojo/" + service + "/" + version + "/" + "mojoms.zip" |
| 59 service_dir = os.path.join(script_dir, service) | |
| 60 absolute_mojom_directory_path = os.path.join( | |
| 61 service_dir, | |
| 62 "public", | |
| 63 "interfaces") | |
| 64 | 59 |
| 65 if not os.path.exists(absolute_mojom_directory_path): | |
| 66 # This service has no interfaces. | |
| 67 return | |
| 68 | |
| 69 dest = "gs://mojo/" + service + "/" + version + "/" + "mojoms.zip" | |
| 70 with tempfile.NamedTemporaryFile() as mojom_zip_file: | 60 with tempfile.NamedTemporaryFile() as mojom_zip_file: |
| 71 with zipfile.ZipFile(mojom_zip_file, 'w') as z: | 61 with zipfile.ZipFile(mojom_zip_file, 'w') as z: |
| 72 for root, _, files in os.walk(absolute_mojom_directory_path): | 62 for root, _, files in os.walk(absolute_mojom_directory_path): |
| 73 for filename in files: | 63 for filename in files: |
| 74 absolute_file_path = os.path.join(root, filename) | 64 absolute_file_path = os.path.join(root, filename) |
| 75 relative_file_path = os.path.relpath(absolute_file_path, root) | 65 relative_file_path = os.path.relpath(absolute_file_path, root) |
| 76 z.write(absolute_file_path, relative_file_path) | 66 z.write(absolute_file_path, relative_file_path) |
| 77 gsutil_cp(mojom_zip_file.name, dest, dry_run) | 67 gsutil_cp(mojom_zip_file.name, dest, dry_run) |
| 78 | 68 |
| 79 | 69 |
| 80 def upload_binary(service, binary_dir, platform, dry_run): | 70 def upload_binary(service, binary_dir, platform, dry_run): |
| 81 binary_name = SERVICE_BINARY_NAMES[service] | 71 dest_dir = "gs://mojo/" + service + "/" + version + "/" + platform + "/" |
| 72 should_zip = service in SERVICES_WITH_ZIPPED_BINARIES | |
| 73 binary_name = service + ".mojo" | |
| 82 absolute_binary_path = os.path.join(root_path, binary_dir, binary_name) | 74 absolute_binary_path = os.path.join(root_path, binary_dir, binary_name) |
| 83 binary_dest_prefix = "gs://mojo/" + service + "/" + version + "/" + platform | |
| 84 | 75 |
| 85 if service not in SERVICES_WITH_ZIPPED_BINARIES: | 76 if not should_zip: |
| 86 binary_dest = binary_dest_prefix + "/" + binary_name | 77 dest = dest_dir + binary_name |
| 87 gsutil_cp(absolute_binary_path, binary_dest, dry_run) | 78 gsutil_cp(absolute_binary_path, dest, dry_run) |
| 88 return | 79 return |
| 89 | 80 |
| 90 # Zip the binary before uploading it to the cloud. | 81 # Zip the binary before uploading it to the cloud. |
| 91 binary_dest = binary_dest_prefix + ".zip" | 82 dest = dest_dir + binary_name + ".zip" |
|
blundell
2015/02/06 13:10:44
nit: You can just specify dest with the "+ binary
ppi
2015/02/06 13:16:34
Unless you feel strongly, I'd prefer not to have "
| |
| 92 with tempfile.NamedTemporaryFile() as binary_zip_file: | 83 with tempfile.NamedTemporaryFile() as binary_zip_file: |
| 93 with zipfile.ZipFile(binary_zip_file, 'w') as z: | 84 with zipfile.ZipFile(binary_zip_file, 'w') as z: |
| 94 with open(absolute_binary_path) as service_binary: | 85 with open(absolute_binary_path) as service_binary: |
| 95 zipinfo = zipfile.ZipInfo(binary_name) | 86 zipinfo = zipfile.ZipInfo(binary_name) |
| 96 zipinfo.external_attr = 0o777 << 16 | 87 zipinfo.external_attr = 0o777 << 16 |
| 97 zipinfo.compress_type = zipfile.ZIP_DEFLATED | 88 zipinfo.compress_type = zipfile.ZIP_DEFLATED |
| 98 zipinfo.date_time = time.gmtime(os.path.getmtime(absolute_binary_path)) | 89 zipinfo.date_time = time.gmtime(os.path.getmtime(absolute_binary_path)) |
| 99 z.writestr(zipinfo, service_binary.read()) | 90 z.writestr(zipinfo, service_binary.read()) |
| 100 gsutil_cp(binary_zip_file.name, binary_dest, dry_run) | 91 gsutil_cp(binary_zip_file.name, dest, dry_run) |
| 101 | 92 |
| 102 | 93 |
| 103 def main(): | 94 def main(): |
| 104 parser = argparse.ArgumentParser( | 95 parser = argparse.ArgumentParser( |
| 105 description="Upload service mojoms and binaries to Google storage") | 96 description="Upload service mojoms and binaries to Google storage") |
| 106 parser.add_argument("-n", "--dry-run", action="store_true", help="Dry run") | 97 parser.add_argument("-n", "--dry-run", action="store_true", help="Dry run") |
| 107 parser.add_argument( | 98 parser.add_argument( |
| 108 "--linux-x64-binary-dir", | 99 "--linux-x64-binary-dir", |
| 109 help="Path to the dir containing the linux-x64 service binary relative " | 100 help="Path to the dir containing the linux-x64 service binary relative " |
| 110 "to the repo root, e.g. out/Release") | 101 "to the repo root, e.g. out/Release") |
| 111 parser.add_argument( | 102 parser.add_argument( |
| 112 "--android-arm-binary-dir", | 103 "--android-arm-binary-dir", |
| 113 help="Path to the dir containing the android-arm service binary relative " | 104 help="Path to the dir containing the android-arm service binary relative " |
| 114 "to the repo root, e.g. out/android_Release") | 105 "to the repo root, e.g. out/android_Release") |
| 115 parser.add_argument("service", | 106 parser.add_argument("service", |
| 116 help="The service to be uploaded (one of %s)" % SERVICES) | 107 help="The service to be uploaded (one of %s)" % SERVICES) |
| 117 | 108 |
| 118 args = parser.parse_args() | 109 args = parser.parse_args() |
| 119 | 110 |
| 120 if args.service not in SERVICES: | 111 if args.service not in SERVICES: |
| 121 print args.service + " is not one of the recognized services:" | 112 print args.service + " is not one of the recognized services:" |
| 122 print SERVICES | 113 print SERVICES |
| 123 return 1 | 114 return 1 |
| 124 | 115 |
| 125 upload_mojoms(args.service, args.dry_run) | 116 if args.service in MOJOMS_IN_DIR: |
| 117 script_dir = os.path.dirname(os.path.realpath(__file__)) | |
| 118 absolute_mojom_directory_path = os.path.join(script_dir, | |
| 119 MOJOMS_IN_DIR[args.service]) | |
| 120 upload_mojoms(args.service, absolute_mojom_directory_path, args.dry_run) | |
| 121 | |
| 126 if args.linux_x64_binary_dir: | 122 if args.linux_x64_binary_dir: |
| 127 upload_binary(args.service, args.linux_x64_binary_dir, | 123 upload_binary(args.service, args.linux_x64_binary_dir, |
| 128 "linux-x64", args.dry_run) | 124 "linux-x64", args.dry_run) |
| 125 | |
| 129 if args.android_arm_binary_dir: | 126 if args.android_arm_binary_dir: |
| 130 upload_binary(args.service, args.android_arm_binary_dir, | 127 upload_binary(args.service, args.android_arm_binary_dir, |
| 131 "android-arm", args.dry_run) | 128 "android-arm", args.dry_run) |
| 132 | 129 |
| 133 if not args.dry_run: | 130 if not args.dry_run: |
| 134 print "Uploaded artifacts for version %s" % (version, ) | 131 print "Uploaded artifacts for version %s" % (version, ) |
| 135 else: | 132 else: |
| 136 print "No artifacts uploaded (dry run)" | 133 print "No artifacts uploaded (dry run)" |
| 137 return 0 | 134 return 0 |
| 138 | 135 |
| 139 if __name__ == '__main__': | 136 if __name__ == '__main__': |
| 140 sys.exit(main()) | 137 sys.exit(main()) |
| OLD | NEW |