{android,win32}/build.py: add tarball_path and src_path to toolchain class
Reduce dependencies on global variables.
This commit is contained in:
parent
ec2a2522aa
commit
86486336ec
|
@ -45,7 +45,12 @@ build_arch = 'linux-x86_64'
|
||||||
# set up the NDK toolchain
|
# set up the NDK toolchain
|
||||||
|
|
||||||
class AndroidNdkToolchain:
|
class AndroidNdkToolchain:
|
||||||
def __init__(self, use_cxx, use_clang):
|
def __init__(self, tarball_path, src_path, build_path,
|
||||||
|
use_cxx, use_clang):
|
||||||
|
self.tarball_path = tarball_path
|
||||||
|
self.src_path = src_path
|
||||||
|
self.build_path = build_path
|
||||||
|
|
||||||
self.ndk_arch = 'arm'
|
self.ndk_arch = 'arm'
|
||||||
android_abi = 'armeabi-v7a'
|
android_abi = 'armeabi-v7a'
|
||||||
ndk_platform = 'android-14'
|
ndk_platform = 'android-14'
|
||||||
|
@ -135,12 +140,11 @@ class Project:
|
||||||
self.use_cxx = use_cxx
|
self.use_cxx = use_cxx
|
||||||
self.use_clang = use_clang
|
self.use_clang = use_clang
|
||||||
|
|
||||||
def download(self):
|
def download(self, toolchain):
|
||||||
global tarball_path
|
return download_and_verify(self.url, self.md5, toolchain.tarball_path)
|
||||||
return download_and_verify(self.url, self.md5, tarball_path)
|
|
||||||
|
|
||||||
def is_installed(self, toolchain):
|
def is_installed(self, toolchain):
|
||||||
tarball = self.download()
|
tarball = self.download(toolchain)
|
||||||
installed = os.path.join(toolchain.install_prefix, self.installed)
|
installed = os.path.join(toolchain.install_prefix, self.installed)
|
||||||
tarball_mtime = os.path.getmtime(tarball)
|
tarball_mtime = os.path.getmtime(tarball)
|
||||||
try:
|
try:
|
||||||
|
@ -148,12 +152,11 @@ class Project:
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def unpack(self):
|
def unpack(self, toolchain):
|
||||||
global src_path
|
return untar(self.download(toolchain), toolchain.src_path, self.base)
|
||||||
return untar(self.download(), src_path, self.base)
|
|
||||||
|
|
||||||
def make_build_path(self):
|
def make_build_path(self, toolchain):
|
||||||
path = os.path.join(build_path, self.base)
|
path = os.path.join(toolchain.build_path, self.base)
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(path)
|
shutil.rmtree(path)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
|
@ -172,14 +175,14 @@ class AutotoolsProject(Project):
|
||||||
self.cppflags = cppflags
|
self.cppflags = cppflags
|
||||||
|
|
||||||
def build(self, toolchain):
|
def build(self, toolchain):
|
||||||
src = self.unpack()
|
src = self.unpack(toolchain)
|
||||||
if self.autogen:
|
if self.autogen:
|
||||||
subprocess.check_call(['/usr/bin/aclocal'], cwd=src)
|
subprocess.check_call(['/usr/bin/aclocal'], cwd=src)
|
||||||
subprocess.check_call(['/usr/bin/automake', '--add-missing', '--force-missing', '--foreign'], cwd=src)
|
subprocess.check_call(['/usr/bin/automake', '--add-missing', '--force-missing', '--foreign'], cwd=src)
|
||||||
subprocess.check_call(['/usr/bin/autoconf'], cwd=src)
|
subprocess.check_call(['/usr/bin/autoconf'], cwd=src)
|
||||||
subprocess.check_call(['/usr/bin/libtoolize', '--force'], cwd=src)
|
subprocess.check_call(['/usr/bin/libtoolize', '--force'], cwd=src)
|
||||||
|
|
||||||
build = self.make_build_path()
|
build = self.make_build_path(toolchain)
|
||||||
|
|
||||||
configure = [
|
configure = [
|
||||||
os.path.join(src, 'configure'),
|
os.path.join(src, 'configure'),
|
||||||
|
@ -210,8 +213,8 @@ class FfmpegProject(Project):
|
||||||
self.cppflags = cppflags
|
self.cppflags = cppflags
|
||||||
|
|
||||||
def build(self, toolchain):
|
def build(self, toolchain):
|
||||||
src = self.unpack()
|
src = self.unpack(toolchain)
|
||||||
build = self.make_build_path()
|
build = self.make_build_path(toolchain)
|
||||||
|
|
||||||
configure = [
|
configure = [
|
||||||
os.path.join(src, 'configure'),
|
os.path.join(src, 'configure'),
|
||||||
|
@ -244,7 +247,7 @@ class BoostProject(Project):
|
||||||
**kwargs)
|
**kwargs)
|
||||||
|
|
||||||
def build(self, toolchain):
|
def build(self, toolchain):
|
||||||
src = self.unpack()
|
src = self.unpack(toolchain)
|
||||||
|
|
||||||
# install the headers manually; don't build any library
|
# install the headers manually; don't build any library
|
||||||
# (because right now, we only use header-only libraries)
|
# (because right now, we only use header-only libraries)
|
||||||
|
@ -367,12 +370,14 @@ thirdparty_libs = [
|
||||||
|
|
||||||
# build the third-party libraries
|
# build the third-party libraries
|
||||||
for x in thirdparty_libs:
|
for x in thirdparty_libs:
|
||||||
toolchain = AndroidNdkToolchain(use_cxx=x.use_cxx, use_clang=x.use_clang)
|
toolchain = AndroidNdkToolchain(tarball_path, src_path, build_path,
|
||||||
|
use_cxx=x.use_cxx, use_clang=x.use_clang)
|
||||||
if not x.is_installed(toolchain):
|
if not x.is_installed(toolchain):
|
||||||
x.build(toolchain)
|
x.build(toolchain)
|
||||||
|
|
||||||
# configure and build MPD
|
# configure and build MPD
|
||||||
toolchain = AndroidNdkToolchain(use_cxx=True, use_clang=True)
|
toolchain = AndroidNdkToolchain(tarball_path, src_path, build_path,
|
||||||
|
use_cxx=True, use_clang=True)
|
||||||
|
|
||||||
configure = [
|
configure = [
|
||||||
os.path.join(mpd_path, 'configure'),
|
os.path.join(mpd_path, 'configure'),
|
||||||
|
|
|
@ -30,8 +30,12 @@ build_path = os.path.join(arch_path, 'build')
|
||||||
root_path = os.path.join(arch_path, 'root')
|
root_path = os.path.join(arch_path, 'root')
|
||||||
|
|
||||||
class CrossGccToolchain:
|
class CrossGccToolchain:
|
||||||
def __init__(self, toolchain_path, arch, install_prefix):
|
def __init__(self, toolchain_path, arch,
|
||||||
|
tarball_path, src_path, build_path, install_prefix):
|
||||||
self.arch = arch
|
self.arch = arch
|
||||||
|
self.tarball_path = tarball_path
|
||||||
|
self.src_path = src_path
|
||||||
|
self.build_path = build_path
|
||||||
self.install_prefix = install_prefix
|
self.install_prefix = install_prefix
|
||||||
|
|
||||||
toolchain_bin = os.path.join(toolchain_path, 'bin')
|
toolchain_bin = os.path.join(toolchain_path, 'bin')
|
||||||
|
@ -80,11 +84,11 @@ class Project:
|
||||||
self.md5 = md5
|
self.md5 = md5
|
||||||
self.installed = installed
|
self.installed = installed
|
||||||
|
|
||||||
def download(self):
|
def download(self, toolchain):
|
||||||
return download_and_verify(self.url, self.md5, tarball_path)
|
return download_and_verify(self.url, self.md5, toolchain.tarball_path)
|
||||||
|
|
||||||
def is_installed(self, toolchain):
|
def is_installed(self, toolchain):
|
||||||
tarball = self.download()
|
tarball = self.download(toolchain)
|
||||||
installed = os.path.join(toolchain.install_prefix, self.installed)
|
installed = os.path.join(toolchain.install_prefix, self.installed)
|
||||||
tarball_mtime = os.path.getmtime(tarball)
|
tarball_mtime = os.path.getmtime(tarball)
|
||||||
try:
|
try:
|
||||||
|
@ -92,16 +96,15 @@ class Project:
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def unpack(self, out_of_tree=True):
|
def unpack(self, toolchain, out_of_tree=True):
|
||||||
global src_path, build_path
|
|
||||||
if out_of_tree:
|
if out_of_tree:
|
||||||
parent_path = src_path
|
parent_path = toolchain.src_path
|
||||||
else:
|
else:
|
||||||
parent_path = build_path
|
parent_path = toolchain.build_path
|
||||||
return untar(self.download(), parent_path, self.base)
|
return untar(self.download(toolchain), parent_path, self.base)
|
||||||
|
|
||||||
def make_build_path(self):
|
def make_build_path(self, toolchain):
|
||||||
path = os.path.join(build_path, self.base)
|
path = os.path.join(toolchain.build_path, self.base)
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(path)
|
shutil.rmtree(path)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
|
@ -120,14 +123,14 @@ class AutotoolsProject(Project):
|
||||||
self.cppflags = cppflags
|
self.cppflags = cppflags
|
||||||
|
|
||||||
def build(self, toolchain):
|
def build(self, toolchain):
|
||||||
src = self.unpack()
|
src = self.unpack(toolchain)
|
||||||
if self.autogen:
|
if self.autogen:
|
||||||
subprocess.check_call(['/usr/bin/aclocal'], cwd=src)
|
subprocess.check_call(['/usr/bin/aclocal'], cwd=src)
|
||||||
subprocess.check_call(['/usr/bin/automake', '--add-missing', '--force-missing', '--foreign'], cwd=src)
|
subprocess.check_call(['/usr/bin/automake', '--add-missing', '--force-missing', '--foreign'], cwd=src)
|
||||||
subprocess.check_call(['/usr/bin/autoconf'], cwd=src)
|
subprocess.check_call(['/usr/bin/autoconf'], cwd=src)
|
||||||
subprocess.check_call(['/usr/bin/libtoolize', '--force'], cwd=src)
|
subprocess.check_call(['/usr/bin/libtoolize', '--force'], cwd=src)
|
||||||
|
|
||||||
build = self.make_build_path()
|
build = self.make_build_path(toolchain)
|
||||||
|
|
||||||
configure = [
|
configure = [
|
||||||
os.path.join(src, 'configure'),
|
os.path.join(src, 'configure'),
|
||||||
|
@ -157,7 +160,7 @@ class ZlibProject(Project):
|
||||||
Project.__init__(self, url, md5, installed, **kwargs)
|
Project.__init__(self, url, md5, installed, **kwargs)
|
||||||
|
|
||||||
def build(self, toolchain):
|
def build(self, toolchain):
|
||||||
src = self.unpack(out_of_tree=False)
|
src = self.unpack(toolchain, out_of_tree=False)
|
||||||
|
|
||||||
subprocess.check_call(['/usr/bin/make', '--quiet',
|
subprocess.check_call(['/usr/bin/make', '--quiet',
|
||||||
'-f', 'win32/Makefile.gcc',
|
'-f', 'win32/Makefile.gcc',
|
||||||
|
@ -179,8 +182,8 @@ class FfmpegProject(Project):
|
||||||
self.cppflags = cppflags
|
self.cppflags = cppflags
|
||||||
|
|
||||||
def build(self, toolchain):
|
def build(self, toolchain):
|
||||||
src = self.unpack()
|
src = self.unpack(toolchain)
|
||||||
build = self.make_build_path()
|
build = self.make_build_path(toolchain)
|
||||||
|
|
||||||
configure = [
|
configure = [
|
||||||
os.path.join(src, 'configure'),
|
os.path.join(src, 'configure'),
|
||||||
|
@ -215,7 +218,7 @@ class BoostProject(Project):
|
||||||
**kwargs)
|
**kwargs)
|
||||||
|
|
||||||
def build(self, toolchain):
|
def build(self, toolchain):
|
||||||
src = self.unpack()
|
src = self.unpack(toolchain)
|
||||||
|
|
||||||
# install the headers manually; don't build any library
|
# install the headers manually; don't build any library
|
||||||
# (because right now, we only use header-only libraries)
|
# (because right now, we only use header-only libraries)
|
||||||
|
@ -332,7 +335,8 @@ thirdparty_libs = [
|
||||||
]
|
]
|
||||||
|
|
||||||
# build the third-party libraries
|
# build the third-party libraries
|
||||||
toolchain = CrossGccToolchain('/usr', host_arch, root_path)
|
toolchain = CrossGccToolchain('/usr', host_arch,
|
||||||
|
tarball_path, src_path, build_path, root_path)
|
||||||
|
|
||||||
for x in thirdparty_libs:
|
for x in thirdparty_libs:
|
||||||
if not x.is_installed(toolchain):
|
if not x.is_installed(toolchain):
|
||||||
|
|
Loading…
Reference in New Issue