Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: mojo/public/tools/download_shell_binary.py

Issue 892903003: Download and copy shell binary on Android as well as Linux. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Response to review Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/public/tools/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 os 7 import os
8 import subprocess 8 import subprocess
9 import sys 9 import sys
10 import tempfile 10 import tempfile
11 import zipfile 11 import zipfile
12 12
13 BINARY_FOR_PLATFORM = {
14 "linux-x64" : "mojo_shell",
15 "android-arm" : "MojoShell.apk"
16 }
17
13 if not sys.platform.startswith("linux"): 18 if not sys.platform.startswith("linux"):
14 print "Not supported for your platform" 19 print "Not supported for your platform"
15 sys.exit(0) 20 sys.exit(0)
16 21
17 22
18 def download(tools_directory): 23 def download(tools_directory):
19 current_path = os.path.dirname(os.path.realpath(__file__)) 24 current_path = os.path.dirname(os.path.realpath(__file__))
20 find_depot_tools_path = os.path.join(current_path, tools_directory)
21 sys.path.insert(0, find_depot_tools_path)
22 # pylint: disable=F0401
23 import find_depot_tools
24
25 prebuilt_file_path = os.path.join(current_path, "prebuilt") 25 prebuilt_file_path = os.path.join(current_path, "prebuilt")
qsr 2015/02/06 14:48:12 Maybe create a method for this, as you use it in m
blundell 2015/02/06 15:01:04 Made global vars, as both current_path and prebuil
26 stamp_path = os.path.join(prebuilt_file_path, "VERSION") 26 stamp_path = os.path.join(prebuilt_file_path, "VERSION")
27 27
28 depot_tools_path = find_depot_tools.add_depot_tools_to_path()
29 gsutil_exe = os.path.join(depot_tools_path, "third_party", "gsutil", "gsutil")
30
31 version_path = os.path.join(current_path, "../VERSION") 28 version_path = os.path.join(current_path, "../VERSION")
32 with open(version_path) as version_file: 29 with open(version_path) as version_file:
33 version = version_file.read().strip() 30 version = version_file.read().strip()
34 31
35 try: 32 try:
36 with open(stamp_path) as stamp_file: 33 with open(stamp_path) as stamp_file:
37 current_version = stamp_file.read().strip() 34 current_version = stamp_file.read().strip()
38 if current_version == version: 35 if current_version == version:
39 return 0 # Already have the right version. 36 return 0 # Already have the right version.
40 except IOError: 37 except IOError:
41 pass # If the stamp file does not exist we need to download a new binary. 38 pass # If the stamp file does not exist we need to download new binaries.
42 39
43 platform = "linux-x64" # TODO: configurate 40 for platform in ["linux-x64", "android-arm"]:
41 download_version_for_platform(version, platform, tools_directory)
42
43 with open(stamp_path, 'w') as stamp_file:
44 stamp_file.write(version)
45 return 0
46
47 def download_version_for_platform(version, platform, tools_directory):
48 current_path = os.path.dirname(os.path.realpath(__file__))
49 prebuilt_file_path = os.path.join(current_path, "prebuilt")
50 find_depot_tools_path = os.path.join(current_path, tools_directory)
51 sys.path.insert(0, find_depot_tools_path)
52 # pylint: disable=F0401
53 import find_depot_tools
54
44 basename = platform + ".zip" 55 basename = platform + ".zip"
56 gs_path = "gs://mojo/shell/" + version + "/" + basename
45 57
46 gs_path = "gs://mojo/shell/" + version + "/" + basename 58 depot_tools_path = find_depot_tools.add_depot_tools_to_path()
59 gsutil_exe = os.path.join(depot_tools_path, "third_party", "gsutil", "gsutil")
47 60
48 with tempfile.NamedTemporaryFile() as temp_zip_file: 61 with tempfile.NamedTemporaryFile() as temp_zip_file:
49 # We're downloading from a public bucket which does not need authentication, 62 # We're downloading from a public bucket which does not need authentication,
50 # but the user might have busted credential files somewhere such as ~/.boto 63 # but the user might have busted credential files somewhere such as ~/.boto
51 # that the gsutil script will try (and fail) to use. Setting these 64 # that the gsutil script will try (and fail) to use. Setting these
52 # environment variables convinces gsutil not to attempt to use these, but 65 # environment variables convinces gsutil not to attempt to use these, but
53 # also generates a useless warning about failing to load the file. We want 66 # also generates a useless warning about failing to load the file. We want
54 # to discard this warning but still preserve all output in the case of an 67 # to discard this warning but still preserve all output in the case of an
55 # actual failure. So, we run the script and capture all output and then 68 # actual failure. So, we run the script and capture all output and then
56 # throw the output away if the script succeeds (return code 0). 69 # throw the output away if the script succeeds (return code 0).
57 env = os.environ.copy() 70 env = os.environ.copy()
58 env["AWS_CREDENTIAL_FILE"] = "" 71 env["AWS_CREDENTIAL_FILE"] = ""
59 env["BOTO_CONFIG"] = "" 72 env["BOTO_CONFIG"] = ""
60 try: 73 try:
61 subprocess.check_output( 74 subprocess.check_output(
62 [gsutil_exe, 75 [gsutil_exe,
63 "--bypass_prodaccess", 76 "--bypass_prodaccess",
64 "cp", 77 "cp",
65 gs_path, 78 gs_path,
66 temp_zip_file.name], 79 temp_zip_file.name],
67 stderr=subprocess.STDOUT, 80 stderr=subprocess.STDOUT,
68 env=env) 81 env=env)
69 except subprocess.CalledProcessError as e: 82 except subprocess.CalledProcessError as e:
70 print e.output 83 print e.output
71 sys.exit(1) 84 sys.exit(1)
72 85
86 binary_name = BINARY_FOR_PLATFORM[platform]
73 with zipfile.ZipFile(temp_zip_file.name) as z: 87 with zipfile.ZipFile(temp_zip_file.name) as z:
74 zi = z.getinfo("mojo_shell") 88 zi = z.getinfo(binary_name)
75 mode = zi.external_attr >> 16 89 mode = zi.external_attr >> 16
76 z.extract(zi, prebuilt_file_path) 90 z.extract(zi, prebuilt_file_path)
77 os.chmod(os.path.join(prebuilt_file_path, "mojo_shell"), mode) 91 os.chmod(os.path.join(prebuilt_file_path, binary_name), mode)
78
79 with open(stamp_path, 'w') as stamp_file:
80 stamp_file.write(version)
81 return 0
82 92
83 93
84 def main(): 94 def main():
85 parser = argparse.ArgumentParser(description="Download mojo_shell binary " 95 parser = argparse.ArgumentParser(description="Download mojo_shell binaries "
86 "from google storage") 96 "from google storage")
87 parser.add_argument("--tools-directory", 97 parser.add_argument("--tools-directory",
88 dest="tools_directory", 98 dest="tools_directory",
89 metavar="<tools-directory>", 99 metavar="<tools-directory>",
90 type=str, 100 type=str,
91 help="Path to the directory containing" 101 help="Path to the directory containing"
92 " find_depot_tools.py, specified as a relative path" 102 " find_depot_tools.py, specified as a relative path"
93 " from the location of this file.") 103 " from the location of this file.")
94 args = parser.parse_args() 104 args = parser.parse_args()
95 if not args.tools_directory: 105 if not args.tools_directory:
96 print "Must specify --tools_directory; please see help message." 106 print "Must specify --tools_directory; please see help message."
97 sys.exit(1) 107 sys.exit(1)
98 return download(args.tools_directory) 108 return download(args.tools_directory)
99 109
100 if __name__ == "__main__": 110 if __name__ == "__main__":
101 sys.exit(main()) 111 sys.exit(main())
OLDNEW
« no previous file with comments | « mojo/public/tools/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698