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

Side by Side Diff: tools/android/download_android_tools.py

Issue 2858873005: [infra] Roll clang to match the version used by Flutter (Closed)
Patch Set: Fix Mac Android build Created 3 years, 7 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
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright 2017 The Dart project 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.
5
6 # Downloads trimmed-down Android Tools from Google Cloud Storage and extracts
7 # them to INSTALL_DIR, updating INSTALL_DIR/VERSION_* stamp files with current
8 # version. Does nothing if INSTALL_DIR/VERSION_* are already up to date.
9
10 import os
11 import shutil
12 import subprocess
13 import sys
14 import tarfile
15
16 # Path constants. (All of these should be absolute paths.)
17 THIS_DIR = os.path.abspath(os.path.dirname(__file__))
18 DART_ROOT = os.path.abspath(os.path.join(THIS_DIR, '..', '..'))
19 # Should be the same as in upload.py.
20 INSTALL_DIR = os.path.join(DART_ROOT, 'third_party', 'android_tools')
21
22 sys.path.insert(0, os.path.join(DART_ROOT, 'tools'))
23 import find_depot_tools
24
25 DEPOT_PATH = find_depot_tools.add_depot_tools_to_path()
26 GSUTIL_PATH = os.path.join(DEPOT_PATH, 'gsutil.py')
27
28 def RunCommand(command):
29 """Run command and return success (True) or failure."""
30
31 print 'Running %s' % (str(command))
32 if subprocess.call(command, shell=False) == 0:
33 return True
34 print 'Failed.'
35 return False
36
37
38 def GetInstalledVersion(version_stamp):
39 version_file = os.path.join(INSTALL_DIR, version_stamp)
40 if not os.path.exists(version_file):
41 return None
42 with open(version_file) as f:
43 return f.read().strip()
44
45
46 def VersionStampName(tools_name):
47 if sys.platform.startswith('linux'):
48 return 'VERSION_LINUX_' + tools_name.upper()
49 elif sys.platform == 'darwin':
50 return 'VERSION_MACOSX_' + tools_name.upper()
51 else:
52 print('NOTE: Will not download android tools. Unsupported platform: ' + sys. platform)
53 sys.exit(0)
54
55
56 def UpdateTools(tools_name):
57 """Downloads zipped tools from Google Cloud Storage and extracts them,
58 stamping current version."""
59
60 # Read latest version.
61 version_stamp = VersionStampName(tools_name)
62 version = ''
63 with open(os.path.join(THIS_DIR, version_stamp)) as f:
64 version = f.read().strip()
65 # Return if installed binaries are up to date.
66 if version == GetInstalledVersion(version_stamp):
67 return
68
69 # Remove the old install directory checked out from git.
70 if os.path.exists(os.path.join(INSTALL_DIR, '.git')):
71 shutil.rmtree(INSTALL_DIR)
72 # Make sure that the install directory exists.
73 if not os.path.exists(INSTALL_DIR):
74 os.mkdir(INSTALL_DIR)
75 # Remove current installation.
76 tools_root = os.path.join(INSTALL_DIR, tools_name)
77 if os.path.exists(tools_root):
78 shutil.rmtree(tools_root)
79
80 # Download tools from GCS.
81 archive_path = os.path.join(INSTALL_DIR, tools_name + '.tar.gz')
82 download_cmd = ['python', GSUTIL_PATH, 'cp',
83 'gs://mojo/android/tool/%s.tar.gz' % version,
84 archive_path]
85 if not RunCommand(download_cmd):
86 print ('WARNING: Failed to download Android tools.')
87 return
88
89 print "Extracting Android tools (" + tools_name + ")"
90 with tarfile.open(archive_path) as arch:
91 arch.extractall(INSTALL_DIR)
92 os.remove(archive_path)
93 # Write version as the last step.
94 with open(os.path.join(INSTALL_DIR, version_stamp), 'w+') as f:
95 f.write('%s\n' % version)
96
97
98 def main():
99 UpdateTools('sdk')
100 UpdateTools('ndk')
101
102
103 if __name__ == '__main__':
104 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698