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.
15 SERVICES
= ["html_viewer", "network_service", "network_service_apptests"]
17 # A service does not need to expose interfaces. Those that do expose interfaces
18 # have their mojoms located in the directories listed below, in paths relative
19 # to the directory of this script.
21 "network_service": os
.path
.join("network", "public", "interfaces")
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
26 # to be downloaded dynamically by the shell, which doesn't currently understand
28 SERVICES_WITH_ZIPPED_BINARIES
= ["network_service", "network_service_apptests"]
30 if not sys
.platform
.startswith("linux"):
31 print "Only support linux for now"
34 root_path
= os
.path
.realpath(
37 os
.path
.realpath(__file__
)),
40 version
= subprocess
.check_output(["git", "rev-parse", "HEAD"], cwd
=root_path
)
41 version
= version
.strip()
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
)
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")
50 def gsutil_cp(source
, dest
, dry_run
):
52 print "gsutil cp %s %s" % (source
, dest
)
54 subprocess
.check_call([gsutil_exe
, "cp", source
, dest
])
57 def upload_mojoms(service
, absolute_mojom_directory_path
, dry_run
):
58 dest
= "gs://mojo/" + service
+ "/" + version
+ "/" + "mojoms.zip"
60 with tempfile
.NamedTemporaryFile() as mojom_zip_file
:
61 with zipfile
.ZipFile(mojom_zip_file
, 'w') as z
:
62 for root
, _
, files
in os
.walk(absolute_mojom_directory_path
):
63 for filename
in files
:
64 absolute_file_path
= os
.path
.join(root
, filename
)
65 relative_file_path
= os
.path
.relpath(absolute_file_path
, root
)
66 z
.write(absolute_file_path
, relative_file_path
)
67 gsutil_cp(mojom_zip_file
.name
, dest
, dry_run
)
70 def upload_binary(service
, binary_dir
, platform
, dry_run
):
71 dest_dir
= "gs://mojo/" + service
+ "/" + version
+ "/" + platform
+ "/"
72 should_zip
= service
in SERVICES_WITH_ZIPPED_BINARIES
73 binary_name
= service
+ ".mojo"
74 absolute_binary_path
= os
.path
.join(root_path
, binary_dir
, binary_name
)
78 dest
= dest_dir
+ binary_name
79 gsutil_cp(absolute_binary_path
, dest
, dry_run
)
81 # Update the pointer to the service's location to point to the
82 # newly-uploaded binary.
83 service_location
= dest
.replace("gs://", "https://storage.googleapis.com/")
84 location_file
= ("gs://mojo/services/" + platform
+ "/" + service
+
86 with tempfile
.NamedTemporaryFile() as tmp
:
87 tmp
.write(service_location
)
89 gsutil_cp(tmp
.name
, location_file
, dry_run
)
92 # Zip the binary before uploading it to the cloud.
93 dest
= dest_dir
+ binary_name
+ ".zip"
94 with tempfile
.NamedTemporaryFile() as binary_zip_file
:
95 with zipfile
.ZipFile(binary_zip_file
, 'w') as z
:
96 with
open(absolute_binary_path
) as service_binary
:
97 zipinfo
= zipfile
.ZipInfo(binary_name
)
98 zipinfo
.external_attr
= 0o777 << 16
99 zipinfo
.compress_type
= zipfile
.ZIP_DEFLATED
100 zipinfo
.date_time
= time
.gmtime(os
.path
.getmtime(absolute_binary_path
))
101 z
.writestr(zipinfo
, service_binary
.read())
102 gsutil_cp(binary_zip_file
.name
, dest
, dry_run
)
106 parser
= argparse
.ArgumentParser(
107 description
="Upload service mojoms and binaries to Google storage")
108 parser
.add_argument("-n", "--dry-run", action
="store_true", help="Dry run")
110 "--linux-x64-binary-dir",
111 help="Path to the dir containing the linux-x64 service binary relative "
112 "to the repo root, e.g. out/Release")
114 "--android-arm-binary-dir",
115 help="Path to the dir containing the android-arm service binary relative "
116 "to the repo root, e.g. out/android_Release")
117 parser
.add_argument("service",
118 help="The service to be uploaded (one of %s)" % SERVICES
)
120 args
= parser
.parse_args()
122 if args
.service
not in SERVICES
:
123 print args
.service
+ " is not one of the recognized services:"
127 if args
.service
in MOJOMS_IN_DIR
:
128 script_dir
= os
.path
.dirname(os
.path
.realpath(__file__
))
129 absolute_mojom_directory_path
= os
.path
.join(script_dir
,
130 MOJOMS_IN_DIR
[args
.service
])
131 upload_mojoms(args
.service
, absolute_mojom_directory_path
, args
.dry_run
)
133 if args
.linux_x64_binary_dir
:
134 upload_binary(args
.service
, args
.linux_x64_binary_dir
,
135 "linux-x64", args
.dry_run
)
137 if args
.android_arm_binary_dir
:
138 upload_binary(args
.service
, args
.android_arm_binary_dir
,
139 "android-arm", args
.dry_run
)
142 print "Uploaded artifacts for version %s" % (version
, )
144 print "No artifacts uploaded (dry run)"
147 if __name__
== '__main__':