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