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 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 = { | 13 BINARY_FOR_PLATFORM = { |
14 "linux-x64" : "mojo_shell", | 14 "linux-x64" : "dart_snapshotter", |
15 "android-arm" : "MojoShell.apk" | 15 "mac-x64": "dart_snapshotter", |
16 } | 16 } |
17 | 17 |
18 CURRENT_PATH = os.path.dirname(os.path.realpath(__file__)) | 18 CURRENT_PATH = os.path.dirname(os.path.realpath(__file__)) |
19 sys.path.insert(0, os.path.join(CURRENT_PATH, "pylib")) | 19 sys.path.insert(0, os.path.join(CURRENT_PATH, "pylib")) |
20 import gs | 20 import gs |
21 | 21 |
22 PREBUILT_FILE_PATH = os.path.join(CURRENT_PATH, "prebuilt", "shell") | 22 PREBUILT_FILE_PATH = os.path.join(CURRENT_PATH, "prebuilt", "dart_snapshotter") |
23 | 23 |
24 | 24 |
25 def download(tools_directory, version_file): | 25 def download(tools_directory, version_file): |
26 stamp_path = os.path.join(PREBUILT_FILE_PATH, "VERSION") | 26 stamp_path = os.path.join(PREBUILT_FILE_PATH, "VERSION") |
27 | 27 |
28 version_path = os.path.join(CURRENT_PATH, version_file) | 28 version_path = os.path.join(CURRENT_PATH, version_file) |
29 with open(version_path) as version_file: | 29 with open(version_path) as version_file: |
30 version = version_file.read().strip() | 30 version = version_file.read().strip() |
31 | 31 |
32 try: | 32 try: |
33 with open(stamp_path) as stamp_file: | 33 with open(stamp_path) as stamp_file: |
34 current_version = stamp_file.read().strip() | 34 current_version = stamp_file.read().strip() |
35 if current_version == version: | 35 if current_version == version: |
36 return 0 # Already have the right version. | 36 return 0 # Already have the right version. |
37 except IOError: | 37 except IOError: |
38 pass # If the stamp file does not exist we need to download new binaries. | 38 pass # If the stamp file does not exist we need to download new binaries. |
39 | 39 |
40 if sys.platform.startswith("linux"): | 40 if sys.platform.startswith("linux"): |
41 platforms = ["linux-x64", "android-arm"] | 41 platforms = ["linux-x64"] |
42 elif sys.platform == "darwin": | 42 elif sys.platform.startswith("darwin"): |
43 platforms = ["android-arm"] | 43 platforms = ["mac-x64"] |
44 else: | 44 else: |
45 print "No prebuilt shell available for %s" % sys.platform | 45 print "No prebuilt dart_snapshotter available for %s" % sys.platform |
46 return 0 | 46 return 0 |
47 | 47 |
48 for platform in platforms: | 48 for platform in platforms: |
49 download_version_for_platform(version, platform, tools_directory) | 49 download_version_for_platform(version, platform, tools_directory) |
50 | 50 |
51 with open(stamp_path, 'w') as stamp_file: | 51 with open(stamp_path, 'w') as stamp_file: |
52 stamp_file.write(version) | 52 stamp_file.write(version) |
53 return 0 | 53 return 0 |
54 | 54 |
55 def download_version_for_platform(version, platform, tools_directory): | 55 def download_version_for_platform(version, platform, tools_directory): |
56 find_depot_tools_path = os.path.join(CURRENT_PATH, tools_directory) | 56 find_depot_tools_path = os.path.join(CURRENT_PATH, tools_directory) |
57 sys.path.insert(0, find_depot_tools_path) | 57 sys.path.insert(0, find_depot_tools_path) |
58 # pylint: disable=F0401 | 58 # pylint: disable=F0401 |
59 import find_depot_tools | 59 import find_depot_tools |
60 depot_tools_path = find_depot_tools.add_depot_tools_to_path() | 60 depot_tools_path = find_depot_tools.add_depot_tools_to_path() |
61 | 61 |
62 basename = platform + ".zip" | 62 basename = platform + ".zip" |
63 gs_path = "gs://mojo/shell/" + version + "/" + basename | 63 gs_path = "gs://mojo/dart_snapshotter/" + version + "/" + basename |
64 | 64 |
65 with tempfile.NamedTemporaryFile() as temp_zip_file: | 65 with tempfile.NamedTemporaryFile() as temp_zip_file: |
66 gs.download_from_public_bucket(gs_path, temp_zip_file.name, | 66 gs.download_from_public_bucket(gs_path, temp_zip_file.name, |
67 depot_tools_path) | 67 depot_tools_path) |
68 binary_name = BINARY_FOR_PLATFORM[platform] | 68 binary_name = BINARY_FOR_PLATFORM[platform] |
69 output_dir = os.path.join(PREBUILT_FILE_PATH, platform) | 69 output_dir = os.path.join(PREBUILT_FILE_PATH, platform) |
70 with zipfile.ZipFile(temp_zip_file.name) as z: | 70 with zipfile.ZipFile(temp_zip_file.name) as z: |
71 zi = z.getinfo(binary_name) | 71 zi = z.getinfo(binary_name) |
72 mode = zi.external_attr >> 16 | 72 mode = zi.external_attr >> 16 |
73 z.extract(zi, output_dir) | 73 z.extract(zi, output_dir) |
74 os.chmod(os.path.join(output_dir, binary_name), mode) | 74 os.chmod(os.path.join(output_dir, binary_name), mode) |
75 | 75 |
76 | 76 |
77 def main(): | 77 def main(): |
78 parser = argparse.ArgumentParser(description="Download mojo_shell binaries " | 78 parser = argparse.ArgumentParser( |
79 "from google storage") | 79 description="Download dart_snapshotter binaries from google storage") |
80 parser.add_argument("--tools-directory", | 80 parser.add_argument("--tools-directory", |
81 dest="tools_directory", | 81 dest="tools_directory", |
82 metavar="<tools-directory>", | 82 metavar="<tools-directory>", |
83 type=str, | 83 type=str, |
84 required=True, | 84 required=True, |
85 help="Path to the directory containing " | 85 help="Path to the directory containing " |
86 "find_depot_tools.py, specified as a relative path " | 86 "find_depot_tools.py, specified as a relative path " |
87 "from the location of this file.") | 87 "from the location of this file.") |
88 parser.add_argument("--version-file", | 88 parser.add_argument("--version-file", |
89 dest="version_file", | 89 dest="version_file", |
90 metavar="<version-file>", | 90 metavar="<version-file>", |
91 type=str, | 91 type=str, |
92 default="../VERSION", | 92 default="../VERSION", |
93 help="Path to the file containing the version of the " | 93 help="Path to the file containing the version of the " |
94 "shell to be fetched, specified as a relative path " | 94 "dart_snapshotter to be fetched, specified as a" |
95 "from the location of this file (default: " | 95 "relative path from the location of this file " |
96 "%(default)s).") | 96 "(default: %(default)s).") |
97 args = parser.parse_args() | 97 args = parser.parse_args() |
98 return download(args.tools_directory, args.version_file) | 98 return download(args.tools_directory, args.version_file) |
99 | 99 |
100 if __name__ == "__main__": | 100 if __name__ == "__main__": |
101 sys.exit(main()) | 101 sys.exit(main()) |
OLD | NEW |