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 # A service's name is defined as the name of its subdirectory in the directory |
| 16 # containing this file. | 16 # containing this file. |
| 17 SERVICES = [ "network", "html_viewer" ] | 17 SERVICES = [ "html_viewer", "network" ] |
|
blundell
2015/02/05 10:53:56
I suggest changing this to the binary name (i.e.,
ppi
2015/02/05 12:35:06
Done.
| |
| 18 | 18 |
| 19 SERVICE_BINARY_NAMES = { | 19 SERVICE_BINARY_NAMES = { |
| 20 "network" : "network_service.mojo", | 20 "html_viewer" : [ "html_viewer.mojo" ], |
| 21 "html_viewer" : "html_viewer.mojo" | 21 "network" : [ "network_service.mojo", "network_service_apptests.mojo" ] |
| 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" ] |
| 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" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 with tempfile.NamedTemporaryFile() as mojom_zip_file: | 70 with tempfile.NamedTemporaryFile() as mojom_zip_file: |
| 71 with zipfile.ZipFile(mojom_zip_file, 'w') as z: | 71 with zipfile.ZipFile(mojom_zip_file, 'w') as z: |
| 72 for root, _, files in os.walk(absolute_mojom_directory_path): | 72 for root, _, files in os.walk(absolute_mojom_directory_path): |
| 73 for filename in files: | 73 for filename in files: |
| 74 absolute_file_path = os.path.join(root, filename) | 74 absolute_file_path = os.path.join(root, filename) |
| 75 relative_file_path = os.path.relpath(absolute_file_path, root) | 75 relative_file_path = os.path.relpath(absolute_file_path, root) |
| 76 z.write(absolute_file_path, relative_file_path) | 76 z.write(absolute_file_path, relative_file_path) |
| 77 gsutil_cp(mojom_zip_file.name, dest, dry_run) | 77 gsutil_cp(mojom_zip_file.name, dest, dry_run) |
| 78 | 78 |
| 79 | 79 |
| 80 def upload_binary(service, binary_dir, platform, dry_run): | 80 def upload_binaries(service, binary_dir, platform, dry_run): |
| 81 binary_name = SERVICE_BINARY_NAMES[service] | 81 should_zip = service in SERVICES_WITH_ZIPPED_BINARIES |
| 82 absolute_binary_path = os.path.join(root_path, binary_dir, binary_name) | 82 dest_dir = "gs://mojo/" + service + "/" + version + "/" + platform + "/" |
| 83 binary_dest_prefix = "gs://mojo/" + service + "/" + version + "/" + platform | 83 for binary_name in SERVICE_BINARY_NAMES[service]: |
| 84 absolute_binary_path = os.path.join(root_path, binary_dir, binary_name) | |
| 85 upload_binary(absolute_binary_path, binary_name, dest_dir, should_zip, | |
| 86 dry_run) | |
| 84 | 87 |
| 85 if service not in SERVICES_WITH_ZIPPED_BINARIES: | 88 def upload_binary(absolute_binary_path, binary_name, dest_dir, should_zip, |
| 86 binary_dest = binary_dest_prefix + "/" + binary_name | 89 dry_run): |
| 87 gsutil_cp(absolute_binary_path, binary_dest, dry_run) | 90 if not should_zip: |
| 91 dest = dest_dir + binary_name | |
| 92 gsutil_cp(absolute_binary_path, dest, dry_run) | |
| 88 return | 93 return |
| 89 | 94 |
| 90 # Zip the binary before uploading it to the cloud. | 95 # Zip the binary before uploading it to the cloud. |
| 91 binary_dest = binary_dest_prefix + ".zip" | 96 dest = dest_dir + binary_name + ".zip" |
| 92 with tempfile.NamedTemporaryFile() as binary_zip_file: | 97 with tempfile.NamedTemporaryFile() as binary_zip_file: |
| 93 with zipfile.ZipFile(binary_zip_file, 'w') as z: | 98 with zipfile.ZipFile(binary_zip_file, 'w') as z: |
| 94 with open(absolute_binary_path) as service_binary: | 99 with open(absolute_binary_path) as service_binary: |
| 95 zipinfo = zipfile.ZipInfo(binary_name) | 100 zipinfo = zipfile.ZipInfo(binary_name) |
| 96 zipinfo.external_attr = 0o777 << 16 | 101 zipinfo.external_attr = 0o777 << 16 |
| 97 zipinfo.compress_type = zipfile.ZIP_DEFLATED | 102 zipinfo.compress_type = zipfile.ZIP_DEFLATED |
| 98 zipinfo.date_time = time.gmtime(os.path.getmtime(absolute_binary_path)) | 103 zipinfo.date_time = time.gmtime(os.path.getmtime(absolute_binary_path)) |
| 99 z.writestr(zipinfo, service_binary.read()) | 104 z.writestr(zipinfo, service_binary.read()) |
| 100 gsutil_cp(binary_zip_file.name, binary_dest, dry_run) | 105 gsutil_cp(binary_zip_file.name, dest, dry_run) |
| 101 | 106 |
| 102 | 107 |
| 103 def main(): | 108 def main(): |
| 104 parser = argparse.ArgumentParser( | 109 parser = argparse.ArgumentParser( |
| 105 description="Upload service mojoms and binaries to Google storage") | 110 description="Upload service mojoms and binaries to Google storage") |
| 106 parser.add_argument("-n", "--dry-run", action="store_true", help="Dry run") | 111 parser.add_argument("-n", "--dry-run", action="store_true", help="Dry run") |
| 107 parser.add_argument( | 112 parser.add_argument( |
| 108 "--linux-x64-binary-dir", | 113 "--linux-x64-binary-dir", |
| 109 help="Path to the dir containing the linux-x64 service binary relative " | 114 help="Path to the dir containing the linux-x64 service binary relative " |
| 110 "to the repo root, e.g. out/Release") | 115 "to the repo root, e.g. out/Release") |
| 111 parser.add_argument( | 116 parser.add_argument( |
| 112 "--android-arm-binary-dir", | 117 "--android-arm-binary-dir", |
| 113 help="Path to the dir containing the android-arm service binary relative " | 118 help="Path to the dir containing the android-arm service binary relative " |
| 114 "to the repo root, e.g. out/android_Release") | 119 "to the repo root, e.g. out/android_Release") |
| 115 parser.add_argument("service", | 120 parser.add_argument("service", |
| 116 help="The service to be uploaded (one of %s)" % SERVICES) | 121 help="The service to be uploaded (one of %s)" % SERVICES) |
| 117 | 122 |
| 118 args = parser.parse_args() | 123 args = parser.parse_args() |
| 119 | 124 |
| 120 if args.service not in SERVICES: | 125 if args.service not in SERVICES: |
| 121 print args.service + " is not one of the recognized services:" | 126 print args.service + " is not one of the recognized services:" |
| 122 print SERVICES | 127 print SERVICES |
| 123 return 1 | 128 return 1 |
| 124 | 129 |
| 125 upload_mojoms(args.service, args.dry_run) | 130 upload_mojoms(args.service, args.dry_run) |
| 126 if args.linux_x64_binary_dir: | 131 if args.linux_x64_binary_dir: |
| 127 upload_binary(args.service, args.linux_x64_binary_dir, | 132 upload_binaries(args.service, args.linux_x64_binary_dir, |
| 128 "linux-x64", args.dry_run) | 133 "linux-x64", args.dry_run) |
| 129 if args.android_arm_binary_dir: | 134 if args.android_arm_binary_dir: |
| 130 upload_binary(args.service, args.android_arm_binary_dir, | 135 upload_binaries(args.service, args.android_arm_binary_dir, |
| 131 "android-arm", args.dry_run) | 136 "android-arm", args.dry_run) |
| 132 | 137 |
| 133 if not args.dry_run: | 138 if not args.dry_run: |
| 134 print "Uploaded artifacts for version %s" % (version, ) | 139 print "Uploaded artifacts for version %s" % (version, ) |
| 135 else: | 140 else: |
| 136 print "No artifacts uploaded (dry run)" | 141 print "No artifacts uploaded (dry run)" |
| 137 return 0 | 142 return 0 |
| 138 | 143 |
| 139 if __name__ == '__main__': | 144 if __name__ == '__main__': |
| 140 sys.exit(main()) | 145 sys.exit(main()) |
| OLD | NEW |