OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
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 | |
4 # found in the LICENSE file. | |
5 | |
6 import argparse | |
7 import imp | |
8 import os | |
9 import subprocess | |
10 import sys | |
11 import tempfile | |
12 import time | |
13 import zipfile | |
14 | |
15 if not sys.platform.startswith("linux"): | |
16 print "Only support linux for now" | |
17 sys.exit(1) | |
18 | |
19 root_path = os.path.realpath( | |
20 os.path.join( | |
21 os.path.dirname( | |
22 os.path.realpath(__file__)), | |
23 os.pardir, | |
24 os.pardir, | |
25 os.pardir)) | |
26 version = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=root_path) | |
27 version = version.strip() | |
28 | |
29 find_depot_tools_path = os.path.join(root_path, "tools", "find_depot_tools.py") | |
30 find_depot_tools = imp.load_source("find_depot_tools", find_depot_tools_path) | |
31 | |
32 depot_tools_path = find_depot_tools.add_depot_tools_to_path() | |
33 gsutil_exe = os.path.join(depot_tools_path, "third_party", "gsutil", "gsutil") | |
34 | |
35 | |
36 def gsutil_cp(source, dest, dry_run): | |
37 if dry_run: | |
38 print "gsutil cp %s %s" % (source, dest) | |
39 else: | |
40 subprocess.check_call([gsutil_exe, "cp", source, dest]) | |
41 | |
42 | |
43 def upload_mojoms(dry_run): | |
44 absolute_mojom_directory_path = os.path.join( | |
45 os.path.dirname(os.path.realpath(__file__)), | |
46 "public", | |
47 "interfaces") | |
48 dest = "gs://mojo/network/" + version + "/" + "mojoms.zip" | |
49 with tempfile.NamedTemporaryFile() as mojom_zip_file: | |
50 with zipfile.ZipFile(mojom_zip_file, 'w') as z: | |
51 for root, _, files in os.walk(absolute_mojom_directory_path): | |
52 for filename in files: | |
53 absolute_file_path = os.path.join(root, filename) | |
54 relative_file_path = os.path.relpath(absolute_file_path, root) | |
55 z.write(absolute_file_path, relative_file_path) | |
56 gsutil_cp(mojom_zip_file.name, dest, dry_run) | |
57 | |
58 | |
59 def upload_binary(binary_path, platform, dry_run): | |
60 absolute_binary_path = os.path.join(root_path, binary_path) | |
61 binary_dest = "gs://mojo/network/" + version + "/" + platform + ".zip" | |
62 with tempfile.NamedTemporaryFile() as binary_zip_file: | |
63 with zipfile.ZipFile(binary_zip_file, 'w') as z: | |
64 with open(absolute_binary_path) as service_binary: | |
65 zipinfo = zipfile.ZipInfo("network_service.mojo") | |
66 zipinfo.external_attr = 0o777 << 16 | |
67 zipinfo.compress_type = zipfile.ZIP_DEFLATED | |
68 zipinfo.date_time = time.gmtime(os.path.getmtime(absolute_binary_path)) | |
69 z.writestr(zipinfo, service_binary.read()) | |
70 gsutil_cp(binary_zip_file.name, binary_dest, dry_run) | |
71 | |
72 | |
73 def main(): | |
74 parser = argparse.ArgumentParser( | |
75 description="Upload network service mojoms and binaries to Google " + | |
76 "storage") | |
77 parser.add_argument("-n", "--dry-run", action="store_true", help="Dry run") | |
78 parser.add_argument( | |
79 "--linux-x64-binary-path", | |
80 help="Path to the linux-x64 network service binary relative to the " + | |
81 "repo root, e.g. out/Release/network_service.mojo") | |
82 parser.add_argument( | |
83 "--android-arm-binary-path", | |
84 help="Path to the android-arm network service binary relative to the " + | |
85 "repo root, e.g. out/android_Release/network_service.mojo") | |
86 | |
87 args = parser.parse_args() | |
88 upload_mojoms(args.dry_run) | |
89 if args.linux_x64_binary_path: | |
90 upload_binary(args.linux_x64_binary_path, "linux-x64", args.dry_run) | |
91 if args.android_arm_binary_path: | |
92 upload_binary(args.android_arm_binary_path, "android-arm", args.dry_run) | |
93 | |
94 if not args.dry_run: | |
95 print "Uploaded artifacts for version %s" % (version, ) | |
96 else: | |
97 print "No artifacts uploaded (dry run)" | |
98 return 0 | |
99 | |
100 if __name__ == '__main__': | |
101 sys.exit(main()) | |
OLD | NEW |