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