diff options
author | Max Kellermann <max@duempel.org> | 2015-11-20 22:10:22 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2015-11-20 22:14:53 +0100 |
commit | 556f9ee39cf1e675b961614f61e784f996af1e98 (patch) | |
tree | 01c6e79e4907539cdb2a674dac329e266b2a6729 /android/build.py | |
parent | 7dad662d690cc1c374009bbcd0df03bccb8f9ad7 (diff) |
{android,win32}/build.py: move common code to python/build/
Diffstat (limited to 'android/build.py')
-rwxr-xr-x | android/build.py | 55 |
1 files changed, 6 insertions, 49 deletions
diff --git a/android/build.py b/android/build.py index 04af2a0f4..c961a1f82 100755 --- a/android/build.py +++ b/android/build.py @@ -2,8 +2,6 @@ import os, os.path import sys, shutil, subprocess -import urllib.request -import hashlib import re if len(sys.argv) < 3: @@ -27,6 +25,7 @@ arch = 'arm-linux-androideabi' # the path to the MPD sources mpd_path = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]) or '.', '..')) +sys.path[0] = os.path.join(mpd_path, 'python') # output directories lib_path = os.path.abspath('lib') @@ -106,43 +105,8 @@ class AndroidNdkToolchain: # default one on the build host self.env['PKG_CONFIG_LIBDIR'] = os.path.join(install_prefix, 'lib/pkgconfig') -def file_md5(path): - """Calculate the MD5 checksum of a file and return it in hexadecimal notation.""" - - with open(path, 'rb') as f: - m = hashlib.md5() - while True: - data = f.read(65536) - if len(data) == 0: - # end of file - return m.hexdigest() - m.update(data) - -def download_tarball(url, md5): - """Download a tarball, verify its MD5 checksum and return the local path.""" - - global tarball_path - os.makedirs(tarball_path, exist_ok=True) - path = os.path.join(tarball_path, os.path.basename(url)) - - try: - calculated_md5 = file_md5(path) - if md5 == calculated_md5: return path - os.unlink(path) - except FileNotFoundError: - pass - - tmp_path = path + '.tmp' - - print("download", url) - urllib.request.urlretrieve(url, tmp_path) - calculated_md5 = file_md5(tmp_path) - if calculated_md5 != md5: - os.unlink(tmp_path) - raise "MD5 mismatch" - - os.rename(tmp_path, path) - return path +from build.download import download_and_verify +from build.tar import untar class Project: def __init__(self, url, md5, installed, name=None, version=None, @@ -172,7 +136,8 @@ class Project: self.use_clang = use_clang def download(self): - return download_tarball(self.url, self.md5) + global tarball_path + return download_and_verify(self.url, self.md5, tarball_path) def is_installed(self, toolchain): tarball = self.download() @@ -185,15 +150,7 @@ class Project: def unpack(self): global src_path - tarball = self.download() - path = os.path.join(src_path, self.base) - try: - shutil.rmtree(path) - except FileNotFoundError: - pass - os.makedirs(src_path, exist_ok=True) - subprocess.check_call(['/bin/tar', 'xfC', tarball, src_path]) - return path + return untar(self.download(), src_path, self.base) def make_build_path(self): path = os.path.join(build_path, self.base) |