Index: third_party/libadblockplus_android/prepare_build_tools.py |
diff --git a/third_party/libadblockplus_android/prepare_build_tools.py b/third_party/libadblockplus_android/prepare_build_tools.py |
index f3dacec733929505eb613c4469168209bdcbd8bf..1a6772de737cadf892229dc915f24179dafaba1c 100644 |
--- a/third_party/libadblockplus_android/prepare_build_tools.py |
+++ b/third_party/libadblockplus_android/prepare_build_tools.py |
@@ -1,54 +1,85 @@ |
import os |
-import urllib |
-import zipfile |
import sys |
import subprocess |
+import shutil |
+ |
+ |
+def get_dst_path(): |
+ cwd = os.getcwd() |
+ return os.path.join(cwd, 'src', 'third_party', |
+ 'libadblockplus_android', 'third_party', 'android_sdk') |
+ |
+ |
+def duplicate_sdk(): |
+ cwd = os.getcwd() |
+ sdk_src = os.path.join(cwd, 'src', 'third_party', 'android_tools', 'sdk') |
+ sdk_dst = get_dst_path() |
+ |
+ if os.path.exists(sdk_dst): |
+ print('Deleting {}'.format(sdk_dst)) |
+ shutil.rmtree(sdk_dst) |
+ else: |
+ dst_parent = os.path.abspath(os.path.join(sdk_dst, os.pardir)) |
+ print('Creating {}'.format(dst_parent)) |
+ os.makedirs(dst_parent) |
+ |
+ print('Copying Android SDK from {} to {}'.format(sdk_src, sdk_dst)) |
+ shutil.copytree(sdk_src, sdk_dst) |
+ |
def install(title, package, version, verbose=False): |
- print('Installing %s ...' % title) |
+ print('Installing {} ...'.format(title)) |
+ |
+ sdk_root = get_dst_path() |
+ sdkmanager = os.path.join(sdk_root, 'tools', 'bin', 'sdkmanager') |
+ |
+ args = [ |
+ sdkmanager, |
+ '--sdk_root={}'.format(sdk_root), |
+ '{};{}'.format(package, version) |
+ ] |
- cwd = os.getcwd() |
- sdk_root = os.path.join(cwd, 'src', 'third_party', 'android_tools', 'sdk') |
- sdkmanager = os.path.join(sdk_root, 'tools', 'bin', 'sdkmanager') |
+ if verbose: |
+ args += ['--verbose'] |
- args = [ |
- sdkmanager, |
- "--sdk_root=%s" % (sdk_root), |
- "%s;%s" % (package, version) |
- ] |
+ process = subprocess.Popen(args, stdin=subprocess.PIPE, |
+ stdout=sys.stdout, stderr=sys.stderr) |
- if verbose: |
- args += [ "--verbose" ] |
+ # Agree to License |
+ process.stdin.write('y') |
+ process.communicate() |
+ process.stdin.close() |
- process = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=sys.stdout, stderr=sys.stderr) |
- process.stdin.write('y') # Agree to License |
- process.communicate() |
- process.stdin.close() |
+ if process.returncode != 0: |
+ print('{} finished with error code {}'.format( |
+ args, process.returncode)) |
- if process.returncode != 0: |
- print("%s finished with error code %s" % (args, process.returncode)) |
+ return process.returncode |
- return process.returncode |
def main(argv): |
- # TODO: update when different version of built-tools and platform are required |
- bt25 = install("Build tools", "build-tools", "25.0.0", True) |
- if bt25 != 0: |
- return bt25 |
+ duplicate_sdk() |
+ |
+ # TODO: update when different version of built-tools |
+ # and platform are required |
+ bt25 = install('Build tools', 'build-tools', '25.0.0', True) |
+ if bt25 != 0: |
+ return bt25 |
+ |
+ a16 = install('Platform 16', 'platforms', 'android-16', True) |
+ if a16 != 0: |
+ return a16 |
- a16 = install("Platform 16", "platforms", "android-16", True) |
- if a16 != 0: |
- return a16 |
+ a21 = install('Platform 21', 'platforms', 'android-21', True) |
+ if a21 != 0: |
+ return a21 |
- a21 = install("Platform 21", "platforms", "android-21", True) |
- if a21 != 0: |
- return a21 |
+ return 0 |
- return 0 |
if '__main__' == __name__: |
- try: |
- sys.exit(main(sys.argv[1:])) |
- except KeyboardInterrupt: |
- sys.stderr.write('interrupted\n') |
- sys.exit(1) |
+ try: |
+ sys.exit(main(sys.argv[1:])) |
+ except KeyboardInterrupt: |
+ sys.stderr.write('interrupted\n') |
+ sys.exit(1) |
diegocarloslima
2018/01/17 13:08:53
Some of the changes here could go in a refactoring
anton
2018/01/17 13:12:11
I've created separate task for applying python cod
|