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 root_path
= os
.path
.realpath(
18 os
.path
.realpath(__file__
)),
22 version
= subprocess
.check_output(["git", "rev-parse", "HEAD"], cwd
=root_path
)
23 version
= version
.strip()
25 if not sys
.platform
.startswith("linux"):
26 print "Only support linux for now"
29 platform
= "linux-x64" # TODO: Parameterize
30 binary_dest
= "gs://mojo/network/" + version
+ "/" + platform
+ ".zip"
32 find_depot_tools_path
= os
.path
.join(root_path
, "tools", "find_depot_tools.py")
33 find_depot_tools
= imp
.load_source("find_depot_tools", find_depot_tools_path
)
35 depot_tools_path
= find_depot_tools
.add_depot_tools_to_path()
36 gsutil_exe
= os
.path
.join(depot_tools_path
, "third_party", "gsutil", "gsutil")
39 def gsutil_cp(source
, dest
, dry_run
):
41 print "gsutil cp %s %s" % (source
, dest
)
43 subprocess
.check_call([gsutil_exe
, "cp", source
, dest
])
46 def upload_binary(binary_path
, dry_run
):
47 absolute_binary_path
= os
.path
.join(root_path
, binary_path
)
48 with tempfile
.NamedTemporaryFile() as binary_zip_file
:
49 with zipfile
.ZipFile(binary_zip_file
, 'w') as z
:
50 with
open(absolute_binary_path
) as service_binary
:
51 zipinfo
= zipfile
.ZipInfo("libnetwork_service.so")
52 zipinfo
.external_attr
= 0o777 << 16
53 zipinfo
.compress_type
= zipfile
.ZIP_DEFLATED
54 zipinfo
.date_time
= time
.gmtime(os
.path
.getmtime(absolute_binary_path
))
55 z
.writestr(zipinfo
, service_binary
.read())
56 gsutil_cp(binary_zip_file
.name
, binary_dest
, dry_run
)
60 parser
= argparse
.ArgumentParser(
61 description
="Upload network service binary to Google storage")
62 parser
.add_argument("-n", "--dry-run", action
="store_true", help="Dry run")
65 help="Path to network service binary relative to the repo root, e.g. " +
66 "out/Release/libnetwork_service.so")
67 args
= parser
.parse_args()
68 upload_binary(args
.binary_path
, args
.dry_run
)
69 print "Uploaded artifacts for %s %s" % (version
, "linux-x64")
72 if __name__
== '__main__':