Files
sdk/tools/android/download_android_tools.py
T
Zach Anderson 726732dd6b [infra] Roll clang to match the version used by Flutter
Flutter uses the same clang toolchain as Fuchsia. This CL puts Dart
on that toolchain, as well. This roll should entail no changes to
glibc version requirements on Linux.

The Fuchsia buildtools distribute clang-format with the toolchain
rather than separately, so this CL introduces forwarding scripts
that are copied to the right place under //buildtools.

This CL sets the default for the number of workers in //tools/gn.py
to 1, as the newer GN version fails occasionally when run
concurrently with other invocations.

As Flutter does, this CL uses the clang toolchain to build for
Android. Thus, it is now possible to build for Android on MacOS.

This change is a prerequisite for assembling the SDK in GN
rather than with a python script:

https://codereview.chromium.org/2848943003/

and will be nicer for making prebuilt SDKs for Fuchsia.

Resubmitting this with the following fixes:
1. Rolls further forward to get past a GN bug
2. Fixes the Android build.
3. Style cleanups in gn.py

Review-Url: https://codereview.chromium.org/2858873005 .
2017-05-06 21:45:00 -07:00

104 lines
3.2 KiB
Python

#!/usr/bin/env python
# Copyright 2017 The Dart project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Downloads trimmed-down Android Tools from Google Cloud Storage and extracts
# them to INSTALL_DIR, updating INSTALL_DIR/VERSION_* stamp files with current
# version. Does nothing if INSTALL_DIR/VERSION_* are already up to date.
import os
import shutil
import subprocess
import sys
import tarfile
# Path constants. (All of these should be absolute paths.)
THIS_DIR = os.path.abspath(os.path.dirname(__file__))
DART_ROOT = os.path.abspath(os.path.join(THIS_DIR, '..', '..'))
# Should be the same as in upload.py.
INSTALL_DIR = os.path.join(DART_ROOT, 'third_party', 'android_tools')
sys.path.insert(0, os.path.join(DART_ROOT, 'tools'))
import find_depot_tools
DEPOT_PATH = find_depot_tools.add_depot_tools_to_path()
GSUTIL_PATH = os.path.join(DEPOT_PATH, 'gsutil.py')
def RunCommand(command):
"""Run command and return success (True) or failure."""
print 'Running %s' % (str(command))
if subprocess.call(command, shell=False) == 0:
return True
print 'Failed.'
return False
def GetInstalledVersion(version_stamp):
version_file = os.path.join(INSTALL_DIR, version_stamp)
if not os.path.exists(version_file):
return None
with open(version_file) as f:
return f.read().strip()
def VersionStampName(tools_name):
if sys.platform.startswith('linux'):
return 'VERSION_LINUX_' + tools_name.upper()
elif sys.platform == 'darwin':
return 'VERSION_MACOSX_' + tools_name.upper()
else:
print('NOTE: Will not download android tools. Unsupported platform: ' + sys.platform)
sys.exit(0)
def UpdateTools(tools_name):
"""Downloads zipped tools from Google Cloud Storage and extracts them,
stamping current version."""
# Read latest version.
version_stamp = VersionStampName(tools_name)
version = ''
with open(os.path.join(THIS_DIR, version_stamp)) as f:
version = f.read().strip()
# Return if installed binaries are up to date.
if version == GetInstalledVersion(version_stamp):
return
# Remove the old install directory checked out from git.
if os.path.exists(os.path.join(INSTALL_DIR, '.git')):
shutil.rmtree(INSTALL_DIR)
# Make sure that the install directory exists.
if not os.path.exists(INSTALL_DIR):
os.mkdir(INSTALL_DIR)
# Remove current installation.
tools_root = os.path.join(INSTALL_DIR, tools_name)
if os.path.exists(tools_root):
shutil.rmtree(tools_root)
# Download tools from GCS.
archive_path = os.path.join(INSTALL_DIR, tools_name + '.tar.gz')
download_cmd = ['python', GSUTIL_PATH, 'cp',
'gs://mojo/android/tool/%s.tar.gz' % version,
archive_path]
if not RunCommand(download_cmd):
print ('WARNING: Failed to download Android tools.')
return
print "Extracting Android tools (" + tools_name + ")"
with tarfile.open(archive_path) as arch:
arch.extractall(INSTALL_DIR)
os.remove(archive_path)
# Write version as the last step.
with open(os.path.join(INSTALL_DIR, version_stamp), 'w+') as f:
f.write('%s\n' % version)
def main():
UpdateTools('sdk')
UpdateTools('ndk')
if __name__ == '__main__':
sys.exit(main())