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 # Uploading a service (e.g. network_service) means uploading the app binary for |
16 # containing this file. | 16 # the service (network_service.mojo), possibly binaries for associated apps |
17 SERVICES = [ "network", "html_viewer" ] | 17 # (network_service_apptests.mojo) and a zip with the service mojoms. |
blundell
2015/02/05 13:03:22
mojos if any.
ppi
2015/02/05 13:29:07
Done.
| |
18 SERVICES = [ "html_viewer", "network_service" ] | |
18 | 19 |
19 SERVICE_BINARY_NAMES = { | 20 # The script will look for the mojoms in the subdirectory indicated here. |
20 "network" : "network_service.mojo", | 21 SERVICE_DIRECTORIES = { |
21 "html_viewer" : "html_viewer.mojo" | 22 "html_viewer": "html_viewer", |
23 "network_service": "network" | |
24 } | |
25 | |
26 # Binaries for the associated apps are uploaded in lockstep with the primary | |
27 # service (e.g. network service apptests with network service). TODO(ppi): | |
28 # remove this once we have full apptest platform coverage in Chromium. | |
29 ASSOCIATED_APPS = { | |
30 "network_service" : [ "network_service_apptests" ] | |
22 } | 31 } |
23 | 32 |
24 # The network service is downloaded out-of-band rather than dynamically by the | 33 # 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 | 34 # 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 | 35 # to be downloaded dynamically by the shell, which doesn't currently understand |
27 # zipped binaries. | 36 # zipped binaries. |
28 SERVICES_WITH_ZIPPED_BINARIES = [ "network" ] | 37 SERVICES_WITH_ZIPPED_BINARIES = [ "network_service" ] |
29 | 38 |
30 if not sys.platform.startswith("linux"): | 39 if not sys.platform.startswith("linux"): |
31 print "Only support linux for now" | 40 print "Only support linux for now" |
32 sys.exit(1) | 41 sys.exit(1) |
33 | 42 |
34 root_path = os.path.realpath( | 43 root_path = os.path.realpath( |
35 os.path.join( | 44 os.path.join( |
36 os.path.dirname( | 45 os.path.dirname( |
37 os.path.realpath(__file__)), | 46 os.path.realpath(__file__)), |
38 os.pardir, | 47 os.pardir, |
(...skipping 10 matching lines...) Expand all Loading... | |
49 | 58 |
50 def gsutil_cp(source, dest, dry_run): | 59 def gsutil_cp(source, dest, dry_run): |
51 if dry_run: | 60 if dry_run: |
52 print "gsutil cp %s %s" % (source, dest) | 61 print "gsutil cp %s %s" % (source, dest) |
53 else: | 62 else: |
54 subprocess.check_call([gsutil_exe, "cp", source, dest]) | 63 subprocess.check_call([gsutil_exe, "cp", source, dest]) |
55 | 64 |
56 | 65 |
57 def upload_mojoms(service, dry_run): | 66 def upload_mojoms(service, dry_run): |
58 script_dir = os.path.dirname(os.path.realpath(__file__)) | 67 script_dir = os.path.dirname(os.path.realpath(__file__)) |
59 service_dir = os.path.join(script_dir, service) | 68 service_dir = os.path.join(script_dir, SERVICE_DIRECTORIES[service]) |
60 absolute_mojom_directory_path = os.path.join( | 69 absolute_mojom_directory_path = os.path.join( |
61 service_dir, | 70 service_dir, |
62 "public", | 71 "public", |
63 "interfaces") | 72 "interfaces") |
64 | 73 |
65 if not os.path.exists(absolute_mojom_directory_path): | 74 if not os.path.exists(absolute_mojom_directory_path): |
66 # This service has no interfaces. | 75 # This service has no interfaces. |
67 return | 76 return |
68 | 77 |
69 dest = "gs://mojo/" + service + "/" + version + "/" + "mojoms.zip" | 78 dest = "gs://mojo/" + service + "/" + version + "/" + "mojoms.zip" |
70 with tempfile.NamedTemporaryFile() as mojom_zip_file: | 79 with tempfile.NamedTemporaryFile() as mojom_zip_file: |
71 with zipfile.ZipFile(mojom_zip_file, 'w') as z: | 80 with zipfile.ZipFile(mojom_zip_file, 'w') as z: |
72 for root, _, files in os.walk(absolute_mojom_directory_path): | 81 for root, _, files in os.walk(absolute_mojom_directory_path): |
73 for filename in files: | 82 for filename in files: |
74 absolute_file_path = os.path.join(root, filename) | 83 absolute_file_path = os.path.join(root, filename) |
75 relative_file_path = os.path.relpath(absolute_file_path, root) | 84 relative_file_path = os.path.relpath(absolute_file_path, root) |
76 z.write(absolute_file_path, relative_file_path) | 85 z.write(absolute_file_path, relative_file_path) |
77 gsutil_cp(mojom_zip_file.name, dest, dry_run) | 86 gsutil_cp(mojom_zip_file.name, dest, dry_run) |
78 | 87 |
79 | 88 |
80 def upload_binary(service, binary_dir, platform, dry_run): | 89 def upload_service(service, binary_dir, platform, dry_run): |
blundell
2015/02/05 13:03:22
s/upload_service/upload_apps? I would expect a fun
ppi
2015/02/05 13:29:06
Done.
| |
81 binary_name = SERVICE_BINARY_NAMES[service] | 90 apps = [ service ] + ASSOCIATED_APPS.get(service, []) |
82 absolute_binary_path = os.path.join(root_path, binary_dir, binary_name) | 91 should_zip = service in SERVICES_WITH_ZIPPED_BINARIES |
83 binary_dest_prefix = "gs://mojo/" + service + "/" + version + "/" + platform | |
84 | 92 |
85 if service not in SERVICES_WITH_ZIPPED_BINARIES: | 93 for app in apps: |
86 binary_dest = binary_dest_prefix + "/" + binary_name | 94 dest_dir = "gs://mojo/" + app + "/" + version + "/" + platform + "/" |
87 gsutil_cp(absolute_binary_path, binary_dest, dry_run) | 95 binary_name = app + ".mojo" |
96 absolute_binary_path = os.path.join(root_path, binary_dir, binary_name) | |
97 upload_binary(absolute_binary_path, binary_name, dest_dir, should_zip, | |
98 dry_run) | |
99 | |
100 def upload_binary(absolute_binary_path, binary_name, dest_dir, should_zip, | |
101 dry_run): | |
102 if not should_zip: | |
103 dest = dest_dir + binary_name | |
104 gsutil_cp(absolute_binary_path, dest, dry_run) | |
88 return | 105 return |
89 | 106 |
90 # Zip the binary before uploading it to the cloud. | 107 # Zip the binary before uploading it to the cloud. |
91 binary_dest = binary_dest_prefix + ".zip" | 108 dest = dest_dir + binary_name + ".zip" |
92 with tempfile.NamedTemporaryFile() as binary_zip_file: | 109 with tempfile.NamedTemporaryFile() as binary_zip_file: |
93 with zipfile.ZipFile(binary_zip_file, 'w') as z: | 110 with zipfile.ZipFile(binary_zip_file, 'w') as z: |
94 with open(absolute_binary_path) as service_binary: | 111 with open(absolute_binary_path) as service_binary: |
95 zipinfo = zipfile.ZipInfo(binary_name) | 112 zipinfo = zipfile.ZipInfo(binary_name) |
96 zipinfo.external_attr = 0o777 << 16 | 113 zipinfo.external_attr = 0o777 << 16 |
97 zipinfo.compress_type = zipfile.ZIP_DEFLATED | 114 zipinfo.compress_type = zipfile.ZIP_DEFLATED |
98 zipinfo.date_time = time.gmtime(os.path.getmtime(absolute_binary_path)) | 115 zipinfo.date_time = time.gmtime(os.path.getmtime(absolute_binary_path)) |
99 z.writestr(zipinfo, service_binary.read()) | 116 z.writestr(zipinfo, service_binary.read()) |
100 gsutil_cp(binary_zip_file.name, binary_dest, dry_run) | 117 gsutil_cp(binary_zip_file.name, dest, dry_run) |
101 | 118 |
102 | 119 |
103 def main(): | 120 def main(): |
104 parser = argparse.ArgumentParser( | 121 parser = argparse.ArgumentParser( |
105 description="Upload service mojoms and binaries to Google storage") | 122 description="Upload service mojoms and binaries to Google storage") |
106 parser.add_argument("-n", "--dry-run", action="store_true", help="Dry run") | 123 parser.add_argument("-n", "--dry-run", action="store_true", help="Dry run") |
107 parser.add_argument( | 124 parser.add_argument( |
108 "--linux-x64-binary-dir", | 125 "--linux-x64-binary-dir", |
109 help="Path to the dir containing the linux-x64 service binary relative " | 126 help="Path to the dir containing the linux-x64 service binary relative " |
110 "to the repo root, e.g. out/Release") | 127 "to the repo root, e.g. out/Release") |
111 parser.add_argument( | 128 parser.add_argument( |
112 "--android-arm-binary-dir", | 129 "--android-arm-binary-dir", |
113 help="Path to the dir containing the android-arm service binary relative " | 130 help="Path to the dir containing the android-arm service binary relative " |
114 "to the repo root, e.g. out/android_Release") | 131 "to the repo root, e.g. out/android_Release") |
115 parser.add_argument("service", | 132 parser.add_argument("service", |
116 help="The service to be uploaded (one of %s)" % SERVICES) | 133 help="The service to be uploaded (one of %s)" % SERVICES) |
117 | 134 |
118 args = parser.parse_args() | 135 args = parser.parse_args() |
119 | 136 |
120 if args.service not in SERVICES: | 137 if args.service not in SERVICES: |
121 print args.service + " is not one of the recognized services:" | 138 print args.service + " is not one of the recognized services:" |
122 print SERVICES | 139 print SERVICES |
123 return 1 | 140 return 1 |
124 | 141 |
125 upload_mojoms(args.service, args.dry_run) | 142 upload_mojoms(args.service, args.dry_run) |
126 if args.linux_x64_binary_dir: | 143 if args.linux_x64_binary_dir: |
127 upload_binary(args.service, args.linux_x64_binary_dir, | 144 upload_service(args.service, args.linux_x64_binary_dir, |
128 "linux-x64", args.dry_run) | 145 "linux-x64", args.dry_run) |
blundell
2015/02/05 13:03:22
nit: indentation, here and in the corresponding li
ppi
2015/02/05 13:29:07
Done.
| |
129 if args.android_arm_binary_dir: | 146 if args.android_arm_binary_dir: |
130 upload_binary(args.service, args.android_arm_binary_dir, | 147 upload_service(args.service, args.android_arm_binary_dir, |
131 "android-arm", args.dry_run) | 148 "android-arm", args.dry_run) |
132 | 149 |
133 if not args.dry_run: | 150 if not args.dry_run: |
134 print "Uploaded artifacts for version %s" % (version, ) | 151 print "Uploaded artifacts for version %s" % (version, ) |
135 else: | 152 else: |
136 print "No artifacts uploaded (dry run)" | 153 print "No artifacts uploaded (dry run)" |
137 return 0 | 154 return 0 |
138 | 155 |
139 if __name__ == '__main__': | 156 if __name__ == '__main__': |
140 sys.exit(main()) | 157 sys.exit(main()) |
OLD | NEW |