aboutsummaryrefslogtreecommitdiff
path: root/checkbuild.py
diff options
context:
space:
mode:
authorDan Albert <danalbert@google.com>2018-10-02 10:53:25 -0700
committerDan Albert <danalbert@google.com>2018-10-05 10:53:09 -0700
commite8136de40dbe022bbdd71c18a1ba993b4b02bc51 (patch)
treea7c8a94f1013087f5324fe1e6f7f9681ea884f98 /checkbuild.py
parent1f7ecba9778c5476b06c7f4d78b53f9d7c1d8961 (diff)
downloadndk-e8136de40dbe022bbdd71c18a1ba993b4b02bc51.tar.gz
Revert "Revert "Refactor the build/install module interface.""
This reverts commit c93d87ee5a193bc2a8ba40809415602083f3cf90. Test: ./checkbuild.py Test: ./checkbuild.py --system windows64 Bug: None Change-Id: Ib08c795c7a86b0bb507283b28793ace940e2cd9d
Diffstat (limited to 'checkbuild.py')
-rwxr-xr-xcheckbuild.py352
1 files changed, 169 insertions, 183 deletions
diff --git a/checkbuild.py b/checkbuild.py
index 7c2818230..1bd7feff5 100755
--- a/checkbuild.py
+++ b/checkbuild.py
@@ -225,6 +225,7 @@ class Clang(ndk.builds.Module):
@property
def notices(self):
+ # TODO: Why every host?
return [
os.path.join(self.get_prebuilt_path('darwin'), 'NOTICE'),
os.path.join(self.get_prebuilt_path('linux'), 'NOTICE'),
@@ -232,7 +233,10 @@ class Clang(ndk.builds.Module):
os.path.join(self.get_prebuilt_path('windows64'), 'NOTICE'),
]
- def get_prebuilt_path(self, host):
+ def get_prebuilt_path(self, host=None):
+ if host is None:
+ host = self.host
+
# The 32-bit Windows Clang is a part of the 64-bit Clang package in
# prebuilts/clang.
if host == 'windows':
@@ -243,26 +247,24 @@ class Clang(ndk.builds.Module):
platform_host_tag = host + '-x86'
rel_prebuilt_path = 'prebuilts/clang/host/{}'.format(platform_host_tag)
- prebuilt_path = os.path.join(build_support.android_path(),
- rel_prebuilt_path, self.version)
+ prebuilt_path = ndk.paths.android_path(rel_prebuilt_path, self.version)
if not os.path.isdir(prebuilt_path):
raise RuntimeError(
'Could not find prebuilt LLVM at {}'.format(prebuilt_path))
return prebuilt_path
- def build(self, _build_dir, _dist_dir, _args):
+ def build(self):
pass
- def install(self, out_dir, _dist_dir, args):
- prebuilt_path = self.get_prebuilt_path(args.system)
- install_path = self.get_install_path(out_dir, args.system)
+ def install(self):
+ install_path = self.get_install_path()
install_parent = os.path.dirname(install_path)
if os.path.exists(install_path):
shutil.rmtree(install_path)
if not os.path.exists(install_parent):
os.makedirs(install_parent)
- shutil.copytree(prebuilt_path, install_path)
+ shutil.copytree(self.get_prebuilt_path(), install_path)
# clang-4053586 was patched in the prebuilts directory to add the
# libc++ includes. These are almost certainly a different revision than
@@ -273,7 +275,7 @@ class Clang(ndk.builds.Module):
cxx_includes_path = os.path.join(install_path, 'include')
shutil.rmtree(cxx_includes_path)
- if args.system in ('darwin', 'linux'):
+ if self.host in ('darwin', 'linux'):
# The Linux and Darwin toolchains have Python compiler wrappers
# that currently do nothing. We don't have these for Windows and we
# want to make sure Windows behavior is consistent with the other
@@ -296,13 +298,13 @@ class Clang(ndk.builds.Module):
#
# Note that lld is experimental in the NDK. It is not the default for
# any architecture and has received only minimal testing in the NDK.
- bin_ext = '.exe' if args.system.startswith('windows') else ''
+ bin_ext = '.exe' if self.host.startswith('windows') else ''
os.remove(os.path.join(install_path, 'bin/ld64.lld' + bin_ext))
os.remove(os.path.join(install_path, 'bin/lld' + bin_ext))
os.remove(os.path.join(install_path, 'bin/lld-link' + bin_ext))
- libdir_name = 'lib' if args.system == 'windows' else 'lib64'
- if args.system.startswith('windows'):
+ libdir_name = 'lib' if self.host == 'windows' else 'lib64'
+ if self.host.startswith('windows'):
# The toolchain prebuilts have LLVMgold.dll in the bin directory
# rather than the lib directory that will actually be searched.
bin_dir = os.path.join(install_path, 'bin')
@@ -318,7 +320,7 @@ class Clang(ndk.builds.Module):
install_clanglib = os.path.join(install_path, libdir_name, 'clang')
linux_prebuilt_path = self.get_prebuilt_path('linux')
- if args.system != 'linux':
+ if self.host != 'linux':
# We don't build target binaries as part of the Darwin or Windows
# build. These toolchains need to get these from the Linux
# prebuilts.
@@ -352,7 +354,7 @@ class Clang(ndk.builds.Module):
# Also remove the other libraries that we installed, but they were only
# installed on Linux.
- if args.system == 'linux':
+ if self.host == 'linux':
shutil.rmtree(os.path.join(install_path, 'runtimes_ndk_cxx'))
@@ -466,6 +468,11 @@ class Binutils(ndk.builds.Module):
path = 'toolchains/{toolchain}-4.9/prebuilt/{host}'
notice_group = ndk.builds.NoticeGroup.TOOLCHAIN
+ # TODO: Move GCC wrapper generation to Clang?
+ deps = {
+ 'clang',
+ }
+
@property
def notices(self):
notices = []
@@ -475,44 +482,40 @@ class Binutils(ndk.builds.Module):
notices.append(os.path.join(prebuilt_path, 'NOTICE'))
return notices
- def build(self, _build_dir, _dist_dir, _args):
+ def build(self):
pass
- def install(self, out_dir, _dist_dir, args):
- arches = build_support.ALL_ARCHITECTURES
- if args.arch is not None:
- arches = [args.arch]
-
- for arch in arches:
- self.install_arch(out_dir, args.system, arch)
+ def install(self):
+ for arch in self.arches:
+ self.install_arch(arch)
- def install_arch(self, out_dir, host, arch):
- install_path = self.get_install_path(out_dir, host, arch)
- toolchain_path = get_binutils_prebuilt_path(host, arch)
+ def install_arch(self, arch):
+ install_path = self.get_install_path(arch=arch)
+ toolchain_path = get_binutils_prebuilt_path(self.host, arch)
ndk.builds.install_directory(toolchain_path, install_path)
- self.install_mock_gcc(out_dir, install_path, host, arch)
+ self.install_mock_gcc(install_path, arch)
# We still need libgcc/libatomic. Copy them from the old GCC prebuilts.
for subarch in get_subarches(arch):
- install_libgcc(install_path, host, arch, subarch)
- install_libatomic(install_path, host, arch, subarch)
+ install_libgcc(install_path, self.host, arch, subarch)
+ install_libatomic(install_path, self.host, arch, subarch)
# We don't actually want this, but Clang won't recognize a
# -gcc-toolchain without it.
- install_gcc_crtbegin(install_path, host, arch, subarch)
+ install_gcc_crtbegin(install_path, self.host, arch, subarch)
# Copy the LLVMgold plugin into the binutils plugin directory so ar can
# use it.
- if host == 'linux':
+ if self.host == 'linux':
so = '.so'
- elif host == 'darwin':
+ elif self.host == 'darwin':
so = '.dylib'
else:
so = '.dll'
- is_win = host.startswith('windows')
- libdir_name = 'lib' if host == 'windows' else 'lib64'
- host_tag = build_support.host_to_tag(host)
+ is_win = self.host.startswith('windows')
+ libdir_name = 'lib' if self.host == 'windows' else 'lib64'
+ host_tag = ndk.hosts.host_to_tag(self.host)
clang_prebuilts = build_support.android_path(
'prebuilts/ndk/current/toolchains', host_tag, 'llvm')
clang_bin = os.path.join(clang_prebuilts, 'bin')
@@ -529,7 +532,7 @@ class Binutils(ndk.builds.Module):
if not is_win:
libcxx_1 = os.path.join(
- clang_libs, versioned_so(host, 'libc++', '1'))
+ clang_libs, versioned_so(self.host, 'libc++', '1'))
# The rpath on LLVMgold.so is ../lib64, so we have to install to
# lib/lib64 to have it be in the right place :(
@@ -540,18 +543,18 @@ class Binutils(ndk.builds.Module):
libwinpthread = os.path.join(clang_bin, 'libwinpthread-1.dll')
shutil.copy2(libwinpthread, bfd_plugins)
- def install_mock_gcc(self, out_dir, install_path, host, arch):
+ def install_mock_gcc(self, install_path, arch):
"""Installs gcc scripts that invoke clang.
These are provided to ease porting to new NDKs for projects that are
not actually sensitive to changes in compiler, just changes to compiler
install path.
"""
- is_win = host.startswith('windows')
+ is_win = self.host.startswith('windows')
exe = '.exe' if is_win else ''
cmd = '.cmd' if is_win else ''
clang_install_path = os.path.relpath(
- Clang().get_install_path(out_dir, host, arch),
+ self.get_dep('clang').get_install_path(),
os.path.join(install_path, 'bin'))
shortcuts = {'gcc': 'clang', 'g++': 'clang++'}
@@ -635,14 +638,15 @@ class HostTools(ndk.builds.Module):
ndk.paths.ndk_path('sources/host-tools/toolbox/NOTICE'),
]
- def build(self, build_dir, dist_dir, args):
- build_args = ndk.builds.common_build_args(build_dir, dist_dir, args)
+ def build(self):
+ build_args = ndk.builds.common_build_args(self.out_dir, self.dist_dir,
+ self.host)
print('Building make...')
ndk.builds.invoke_external_build(
'ndk/sources/host-tools/make-3.81/build.py', build_args)
- if args.system in ('windows', 'windows64'):
+ if self.host in ('windows', 'windows64'):
print('Building toolbox...')
ndk.builds.invoke_external_build(
'ndk/sources/host-tools/toolbox/build.py', build_args)
@@ -657,8 +661,8 @@ class HostTools(ndk.builds.Module):
print('Building YASM...')
ndk.builds.invoke_external_build('toolchain/yasm/build.py', build_args)
- def install(self, out_dir, _dist_dir, args):
- install_dir = self.get_install_path(out_dir, args.system)
+ def install(self):
+ install_dir = self.get_install_path()
try:
os.makedirs(install_dir)
@@ -681,15 +685,15 @@ class HostTools(ndk.builds.Module):
'ndk-which',
]
- if args.system in ('windows', 'windows64'):
+ if self.host in ('windows', 'windows64'):
packages.append('toolbox')
files.append('ndk-gdb.cmd')
- host_tag = build_support.host_to_tag(args.system)
+ host_tag = build_support.host_to_tag(self.host)
package_names = [p + '-' + host_tag + '.tar.bz2' for p in packages]
for package_name in package_names:
- package_path = os.path.join(out_dir, package_name)
+ package_path = os.path.join(self.out_dir, self.host, package_name)
subprocess.check_call(
['tar', 'xf', package_path, '-C', install_dir,
'--strip-components=1'])
@@ -724,10 +728,10 @@ class NdkDepends(ndk.builds.InvokeExternalBuildModule):
script = 'ndk/sources/host-tools/ndk-depends/build.py'
notice = ndk.paths.ndk_path('sources/host-tools/ndk-depends/NOTICE')
- def install(self, out_dir, _dist_dir, args):
- src = os.path.join(out_dir, self.name)
- install_dir = self.get_install_path(out_dir, args.system)
- install_exe(src, install_dir, self.name, args.system)
+ def install(self):
+ src = os.path.join(self.out_dir, self.host, self.name)
+ install_dir = self.get_install_path()
+ install_exe(src, install_dir, self.name, self.host)
class NdkStack(ndk.builds.InvokeExternalBuildModule):
@@ -736,10 +740,10 @@ class NdkStack(ndk.builds.InvokeExternalBuildModule):
script = 'ndk/sources/host-tools/ndk-stack/build.py'
notice = ndk.paths.ndk_path('sources/host-tools/ndk-stack/NOTICE')
- def install(self, out_dir, _dist_dir, args):
- src = os.path.join(out_dir, self.name)
- install_dir = self.get_install_path(out_dir, args.system)
- install_exe(src, install_dir, self.name, args.system)
+ def install(self):
+ src = os.path.join(self.out_dir, self.host, self.name)
+ install_dir = self.get_install_path()
+ install_exe(src, install_dir, self.name, self.host)
class GdbServer(ndk.builds.InvokeBuildModule):
@@ -751,10 +755,10 @@ class GdbServer(ndk.builds.InvokeBuildModule):
arch_specific = True
split_build_by_arch = True
- def install(self, out_dir, dist_dir, args):
- src_dir = os.path.join(out_dir, self.name, self.build_arch, 'install')
- install_path = self.get_install_path(
- out_dir, args.system, self.build_arch)
+ def install(self):
+ src_dir = os.path.join(self.out_dir, self.host, self.name,
+ self.build_arch, 'install')
+ install_path = self.get_install_path()
if os.path.exists(install_path):
shutil.rmtree(install_path)
shutil.copytree(src_dir, install_path)
@@ -799,34 +803,28 @@ class Libcxx(ndk.builds.Module):
'ndk-build-shortcut',
}
- def __init__(self):
- super(Libcxx, self).__init__()
- self.abis = None
- self.obj_out = None
- self.lib_out = None
- self.libcxx_path = ndk.paths.android_path('external/libcxx')
+ libcxx_path = ndk.paths.android_path('external/libcxx')
- def set_abis(self, arch):
- if arch is None:
- self.abis = ndk.abis.ALL_ABIS
- else:
- self.abis = ndk.abis.arch_to_abis(arch)
+ @property
+ def obj_out(self):
+ return os.path.join(self.out_dir, 'libcxx/obj')
- def build(self, build_dir, _dist_dir, args):
- # The build directory passed to us is for the target OS, which may not
- # be our host OS (Windows is cross compiled from Linux). We need to use
- # an NDK matching our host OS.
- host_build_dir = os.path.join(
- os.path.dirname(build_dir), ndk.hosts.get_default_host())
- ndk_path = ndk.paths.get_install_path(host_build_dir)
+ @property
+ def lib_out(self):
+ return os.path.join(self.out_dir, 'libcxx/libs')
- ndk_build = os.path.join(ndk_path, 'build/ndk-build')
+ @property
+ def abis(self):
+ abis = []
+ for arch in self.arches:
+ abis.extend(ndk.abis.arch_to_abis(arch))
+ return abis
+
+ def build(self):
+ ndk_build = os.path.join(
+ self.get_dep('ndk-build').get_build_host_install(), 'ndk-build')
bionic_path = ndk.paths.android_path('bionic')
- self.obj_out = os.path.join(build_dir, 'libcxx/obj')
- self.lib_out = os.path.join(build_dir, 'libcxx/libs')
- self.set_abis(args.arch)
-
android_mk = os.path.join(self.libcxx_path, 'Android.mk')
application_mk = os.path.join(self.libcxx_path, 'Application.mk')
@@ -856,9 +854,8 @@ class Libcxx(ndk.builds.Module):
print('Running: ' + ' '.join([pipes.quote(arg) for arg in build_cmd]))
subprocess.check_call(build_cmd)
- def install(self, out_dir, dist_dir, args):
- ndk_path = ndk.paths.get_install_path(out_dir)
- install_root = os.path.join(ndk_path, self.path)
+ def install(self):
+ install_root = self.get_install_path()
if os.path.exists(install_root):
shutil.rmtree(install_root)
@@ -1074,8 +1071,8 @@ class Platforms(ndk.builds.Module):
if name.startswith('crtbegin'):
self.check_elf_note(dst_path)
- def build(self, build_dir, _dist_dir, args):
- build_dir = os.path.join(build_dir, self.path)
+ def build(self):
+ build_dir = os.path.join(self.out_dir, self.path)
if os.path.exists(build_dir):
shutil.rmtree(build_dir)
@@ -1088,12 +1085,12 @@ class Platforms(ndk.builds.Module):
arch_name = 'arch-{}'.format(arch)
dst_dir = os.path.join(build_dir, platform, arch_name)
os.makedirs(dst_dir)
- self.build_crt_objects(dst_dir, api, arch, args.build_number)
+ self.build_crt_objects(dst_dir, api, arch,
+ self.context.build_number)
- def install(self, out_dir, dist_dir, args):
- build_dir = os.path.join(out_dir, self.path)
- install_dir = os.path.join(
- ndk.paths.get_install_path(out_dir), self.path)
+ def install(self):
+ build_dir = os.path.join(self.out_dir, self.path)
+ install_dir = self.get_install_path()
if os.path.exists(install_dir):
shutil.rmtree(install_dir)
@@ -1162,7 +1159,7 @@ class LibShaderc(ndk.builds.Module):
os.path.join(shaderc_dir, 'third_party', 'LICENSE.spirv-tools'),
]
- def build(self, _build_dir, dist_dir, _args):
+ def build(self):
copies = [
{
'source_dir': os.path.join(self.src, 'shaderc'),
@@ -1248,7 +1245,8 @@ class LibShaderc(ndk.builds.Module):
else:
print(source_dir, ':', dest_dir, ":", f, "SKIPPED")
- build_support.make_package('libshaderc', shaderc_path, dist_dir)
+ build_support.make_package('libshaderc', shaderc_path,
+ self.dist_dir)
finally:
shutil.rmtree(temp_dir)
@@ -1282,13 +1280,13 @@ class Sysroot(ndk.builds.Module):
path = 'sysroot'
notice = ndk.paths.android_path('prebuilts/ndk/platform/sysroot/NOTICE')
- def build(self, _out_dir, dist_dir, args):
+ def build(self):
temp_dir = tempfile.mkdtemp()
try:
path = build_support.android_path('prebuilts/ndk/platform/sysroot')
install_path = os.path.join(temp_dir, 'sysroot')
shutil.copytree(path, install_path)
- if args.system != 'linux':
+ if self.host != 'linux':
# linux/netfilter has some headers with names that differ only
# by case, which can't be extracted to a case-insensitive
# filesystem, which are the defaults for Darwin and Windows :(
@@ -1318,7 +1316,7 @@ class Sysroot(ndk.builds.Module):
minor = ndk.config.hotfix
beta = ndk.config.beta
canary = '1' if ndk.config.canary else '0'
- build = args.build_number
+ build = self.context.build_number
if build == 'dev':
build = '0'
@@ -1366,7 +1364,7 @@ class Sysroot(ndk.builds.Module):
build=build,
canary=canary)))
- build_support.make_package('sysroot', install_path, dist_dir)
+ build_support.make_package('sysroot', install_path, self.dist_dir)
finally:
shutil.rmtree(temp_dir)
@@ -1479,17 +1477,17 @@ class BaseToolchain(ndk.builds.Module):
return (Binutils().notices + Clang().notices + Platforms().notices +
Sysroot().notices + SystemStl().notices)
- def build(self, _out_dir, _dist_dir, _args):
+ def build(self):
pass
- def install(self, out_dir, dist_dir, args):
- install_dir = self.get_install_path(out_dir, args.system)
- clang_dir = Clang().get_install_path(out_dir, args.system)
- libandroid_support_dir = LibAndroidSupport().get_install_path(
- out_dir, args.system)
- platforms_dir = Platforms().get_install_path(out_dir, args.system)
- sysroot_dir = Sysroot().get_install_path(out_dir, args.system)
- system_stl_dir = SystemStl().get_install_path(out_dir, args.system)
+ def install(self):
+ install_dir = self.get_install_path()
+ clang_dir = self.get_dep('clang').get_install_path()
+ libandroid_support_dir = self.get_dep(
+ 'libandroid_support').get_install_path()
+ platforms_dir = self.get_dep('platforms').get_install_path()
+ sysroot_dir = self.get_dep('sysroot').get_install_path()
+ system_stl_dir = self.get_dep('system-stl').get_install_path()
if os.path.exists(install_dir):
shutil.rmtree(install_dir)
@@ -1497,21 +1495,16 @@ class BaseToolchain(ndk.builds.Module):
copy_tree(clang_dir, install_dir)
copy_tree(sysroot_dir, os.path.join(install_dir, 'sysroot'))
- arches = build_support.ALL_ARCHITECTURES
- if args.arch is not None:
- arches = [args.arch]
-
- for arch in arches:
- binutils_dir = Binutils().get_install_path(out_dir, args.system,
- arch)
+ for arch in self.arches:
+ binutils_dir = self.get_dep('binutils').get_install_path(arch=arch)
copy_tree(binutils_dir, install_dir)
- for api in Platforms().get_apis():
+ for api in self.get_dep('platforms').get_apis():
if api in Platforms.skip_apis:
continue
platform = 'android-{}'.format(api)
- for arch in Platforms().get_arches(api):
+ for arch in self.get_dep('platforms').get_arches(api):
triple = ndk.abis.arch_to_triple(arch)
arch_name = 'arch-{}'.format(arch)
lib_dir = 'lib64' if arch == 'x86_64' else 'lib'
@@ -1525,7 +1518,7 @@ class BaseToolchain(ndk.builds.Module):
write_clang_wrapper(
os.path.join(install_dir, 'bin'), api, triple,
- args.system.startswith('windows'))
+ self.host.startswith('windows'))
# Clang searches for libstdc++ headers at $GCC_PATH/../include/c++. It
# maybe be worth adding a search for the same path within the usual
@@ -1557,7 +1550,7 @@ class Vulkan(ndk.builds.Module):
notice = ndk.paths.android_path(
'external/vulkan-validation-layers/LICENSE.txt')
- def build(self, build_dir, dist_dir, args):
+ def build(self):
print('Constructing Vulkan validation layer source...')
vulkan_root_dir = ndk.paths.android_path(
'external/vulkan-validation-layers')
@@ -1589,11 +1582,11 @@ class Vulkan(ndk.builds.Module):
"linux",
"windows")
- base_vulkan_path = os.path.join(build_dir, 'vulkan')
+ base_vulkan_path = os.path.join(self.out_dir, 'vulkan')
vulkan_path = os.path.join(base_vulkan_path, 'src')
for properties in copies:
source_dir = properties['source_dir']
- dest_dir = os.path.join(build_dir, properties['dest_dir'])
+ dest_dir = os.path.join(self.out_dir, properties['dest_dir'])
for d in properties['dirs']:
src = os.path.join(source_dir, d)
dst = os.path.join(dest_dir, d)
@@ -1627,15 +1620,10 @@ class Vulkan(ndk.builds.Module):
subprocess.check_call(build_cmd)
print('Generation finished')
- build_args = ndk.builds.common_build_args(build_dir, dist_dir, args)
- if args.arch is not None:
- build_args.append('--arch={}'.format(args.arch))
- build_args.append('--no-symbols')
-
# TODO: Verify source packaged properly
print('Packaging Vulkan source...')
- src = os.path.join(build_dir, 'vulkan')
- build_support.make_package('vulkan', src, dist_dir)
+ src = os.path.join(self.out_dir, 'vulkan')
+ build_support.make_package('vulkan', src, self.dist_dir)
print('Packaging Vulkan source finished')
@@ -1653,6 +1641,7 @@ class Toolchain(ndk.builds.Module):
'base-toolchain',
'libc++',
'libc++abi',
+ 'platforms',
}
@property
@@ -1660,17 +1649,13 @@ class Toolchain(ndk.builds.Module):
return (Libcxx().notices + Libcxxabi().notices +
LibAndroidSupport().notices)
- def build(self, _out_dir, _dist_dir, _args):
+ def build(self):
pass
- def install(self, out_dir, dist_dir, args):
- install_dir = self.get_install_path(out_dir, args.system)
- libcxx_dir = Libcxx().get_install_path(out_dir, args.system)
- libcxxabi_dir = Libcxxabi().get_install_path(out_dir, args.system)
-
- arches = build_support.ALL_ARCHITECTURES
- if args.arch is not None:
- arches = [args.arch]
+ def install(self):
+ install_dir = self.get_install_path()
+ libcxx_dir = self.get_dep('libc++').get_install_path()
+ libcxxabi_dir = self.get_dep('libc++abi').get_install_path()
libcxx_hdr_dir = os.path.join(install_dir, 'sysroot/usr/include/c++')
os.makedirs(libcxx_hdr_dir)
@@ -1681,7 +1666,7 @@ class Toolchain(ndk.builds.Module):
libcxxabi_inc_src = os.path.join(libcxxabi_dir, 'include')
copy_tree(libcxxabi_inc_src, libcxx_inc_dst)
- for arch in arches:
+ for arch in self.arches:
# We need to replace libgcc with linker scripts that also use
# libunwind on arm32. We already get libgcc from copying binutils,
# but re-install it so we get the linker scripts.
@@ -1690,7 +1675,7 @@ class Toolchain(ndk.builds.Module):
# libunwind isn't available until libc++ has been built.
for subarch in get_subarches(arch):
install_libgcc(
- install_dir, args.system, arch, subarch, new_layout=True)
+ install_dir, self.host, arch, subarch, new_layout=True)
triple = ndk.abis.arch_to_triple(arch)
abi, = ndk.abis.arch_to_abis(arch)
@@ -1710,11 +1695,11 @@ class Toolchain(ndk.builds.Module):
for lib in libs:
shutil.copy2(os.path.join(libcxx_lib_dir, lib), sysroot_dst)
- for api in Platforms().get_apis():
+ for api in self.get_dep('platforms').get_apis():
if api in Platforms.skip_apis:
continue
- for arch in Platforms().get_arches(api):
+ for arch in self.get_dep('platforms').get_arches(api):
triple = ndk.abis.arch_to_triple(arch)
dst_dir = os.path.join(install_dir, 'sysroot/usr/lib', triple,
str(api))
@@ -1825,9 +1810,9 @@ class NdkBuild(ndk.builds.PackageModule):
src = ndk.paths.ndk_path('build')
notice = ndk.paths.ndk_path('NOTICE')
- def install(self, out_dir, dist_dir, args):
- super(NdkBuild, self).install(out_dir, dist_dir, args)
- install_path = self.get_install_path(out_dir, args.system)
+ def install(self):
+ super(NdkBuild, self).install()
+ install_path = self.get_install_path()
abis_json = os.path.join(Meta.path, 'abis.json')
generate_language_specific_metadata(
@@ -1868,17 +1853,17 @@ class SimplePerf(ndk.builds.Module):
path = 'simpleperf'
notice = ndk.paths.android_path('prebuilts/simpleperf/NOTICE')
- def build(self, build_dir, dist_dir, args):
+ def build(self):
print('Building simpleperf...')
- install_dir = os.path.join(build_dir, 'simpleperf')
+ install_dir = os.path.join(self.out_dir, 'simpleperf')
if os.path.exists(install_dir):
shutil.rmtree(install_dir)
os.makedirs(install_dir)
simpleperf_path = ndk.paths.android_path('prebuilts/simpleperf')
dirs = ['doc', 'inferno', 'bin/android']
- is_win = args.system.startswith('windows')
- host_bin_dir = 'windows' if is_win else args.system
+ is_win = self.host.startswith('windows')
+ host_bin_dir = 'windows' if is_win else self.host
dirs.append(os.path.join('bin/', host_bin_dir))
for d in dirs:
shutil.copytree(os.path.join(simpleperf_path, d),
@@ -1898,7 +1883,7 @@ class SimplePerf(ndk.builds.Module):
shutil.copy2(os.path.join(simpleperf_path, item), install_dir)
shutil.copy2(os.path.join(simpleperf_path, 'ChangeLog'), install_dir)
- build_support.make_package('simpleperf', install_dir, dist_dir)
+ build_support.make_package('simpleperf', install_dir, self.dist_dir)
class RenderscriptLibs(ndk.builds.PackageModule):
@@ -1985,13 +1970,12 @@ class CanaryReadme(ndk.builds.Module):
path = 'README.canary'
no_notice = True
- def build(self, _out_dir, _dist_dir, _args):
+ def build(self):
pass
- def install(self, out_dir, _dist_dir, _args):
+ def install(self):
if ndk.config.canary:
- extract_dir = ndk.paths.get_install_path(out_dir)
- canary_path = os.path.join(extract_dir, self.path)
+ canary_path = self.get_install_path()
with open(canary_path, 'w') as canary_file:
canary_file.write(CANARY_TEXT)
@@ -2015,14 +1999,13 @@ class SourceProperties(ndk.builds.Module):
path = 'source.properties'
no_notice = True
- def build(self, _out_dir, _dist_dir, _args):
+ def build(self):
pass
- def install(self, out_dir, _dist_dir, args):
- install_dir = ndk.paths.get_install_path(out_dir)
- path = os.path.join(install_dir, self.path)
+ def install(self):
+ path = self.get_install_path()
with open(path, 'w') as source_properties:
- build = args.build_number
+ build = self.context.build_number
if build == 'dev':
build = '0'
version = '{}.{}.{}'.format(
@@ -2072,30 +2055,30 @@ def create_notice_file(path, for_group):
output_file.write(os.linesep.join(sorted(list(licenses))))
-def launch_build(worker, module, out_dir, dist_dir, args, log_dir):
- result = do_build(worker, module, out_dir, dist_dir, args, log_dir)
+def launch_build(worker, module, log_dir):
+ result = do_build(worker, module, log_dir)
if not result:
return result, module
- do_install(worker, module, out_dir, dist_dir, args)
+ do_install(worker, module)
return True, module
-def do_build(worker, module, out_dir, dist_dir, args, log_dir):
+def do_build(worker, module, log_dir):
with open(module.log_path(log_dir), 'w') as log_file:
os.dup2(log_file.fileno(), sys.stdout.fileno())
os.dup2(log_file.fileno(), sys.stderr.fileno())
try:
worker.status = 'Building {}...'.format(module)
- module.build(out_dir, dist_dir, args)
+ module.build()
return True
except Exception: # pylint: disable=broad-except
traceback.print_exc()
return False
-def do_install(worker, module, out_dir, dist_dir, args):
+def do_install(worker, module):
worker.status = 'Installing {}...'.format(module)
- module.install(out_dir, dist_dir, args)
+ module.install()
def split_module_by_arch(module, arches):
@@ -2314,8 +2297,7 @@ def log_build_failure(log_path, dist_dir):
error_log.write(contents)
-def launch_buildable(deps, workqueue, out_dir, dist_dir, log_dir, args,
- skip_modules):
+def launch_buildable(deps, workqueue, log_dir, skip_deps, skip_modules):
# If args.skip_deps is true, we could get into a case where we just
# dequeued the only module that was still building and the only
# items in get_buildable() are modules that will be skipped.
@@ -2327,14 +2309,13 @@ def launch_buildable(deps, workqueue, out_dir, dist_dir, log_dir, args,
# modules before we complete the loop.
while deps.buildable_modules:
for module in deps.get_buildable():
- if args.skip_deps and module in skip_modules:
+ if skip_deps and module in skip_modules:
deps.complete(module)
continue
- workqueue.add_task(
- launch_build, module, out_dir, dist_dir, args, log_dir)
+ workqueue.add_task(launch_build, module, log_dir)
-def wait_for_build(deps, workqueue, out_dir, dist_dir, log_dir, args,
+def wait_for_build(deps, workqueue, dist_dir, log_dir, skip_deps,
skip_modules):
console = ndk.ansi.get_console()
ui = ndk.ui.get_build_progress_ui(console, workqueue)
@@ -2353,9 +2334,8 @@ def wait_for_build(deps, workqueue, out_dir, dist_dir, log_dir, args,
print('Build succeeded: {}'.format(module))
deps.complete(module)
- launch_buildable(
- deps, workqueue, out_dir, dist_dir, log_dir, args,
- skip_modules)
+ launch_buildable(deps, workqueue, log_dir, skip_deps,
+ skip_modules)
ui.draw()
ui.clear()
@@ -2363,23 +2343,30 @@ def wait_for_build(deps, workqueue, out_dir, dist_dir, log_dir, args,
def build_ndk(modules, deps_only, out_dir, dist_dir, args):
- out_dir = os.path.join(out_dir, args.system)
- deps = ndk.deps.DependencyManager(modules)
+ arches = build_support.ALL_ARCHITECTURES
+ if args.arch is not None:
+ arches = [args.arch]
+
+ build_context = ndk.builds.BuildContext(
+ out_dir, dist_dir, ALL_MODULES, args.system, arches, args.build_number)
+
+ for module in modules:
+ module.context = build_context
log_dir = os.path.join(dist_dir, 'logs')
if not os.path.exists(log_dir):
os.makedirs(log_dir)
+ ndk_dir = ndk.paths.get_install_path(out_dir, args.system)
+ if not os.path.exists(ndk_dir):
+ os.makedirs(ndk_dir)
+
+ deps = ndk.deps.DependencyManager(modules)
workqueue = ndk.workqueue.WorkQueue(args.jobs)
try:
- ndk_dir = ndk.paths.get_install_path(out_dir)
- if not os.path.exists(ndk_dir):
- os.makedirs(ndk_dir)
-
- launch_buildable(
- deps, workqueue, out_dir, dist_dir, log_dir, args, deps_only)
+ launch_buildable(deps, workqueue, log_dir, args.skip_deps, deps_only)
wait_for_build(
- deps, workqueue, out_dir, dist_dir, log_dir, args, deps_only)
+ deps, workqueue, dist_dir, log_dir, args.skip_deps, deps_only)
if deps.get_buildable():
raise RuntimeError(
@@ -2411,8 +2398,7 @@ def build_ndk_for_cross_compile(out_dir, arches, args):
def create_ndk_symlink(out_dir):
- this_host_out = os.path.join(out_dir, ndk.hosts.get_default_host())
- this_host_ndk = ndk.paths.get_install_path(this_host_out)
+ this_host_ndk = ndk.paths.get_install_path()
ndk_symlink = os.path.join(out_dir, os.path.basename(this_host_ndk))
if not os.path.exists(ndk_symlink):
os.symlink(this_host_ndk, ndk_symlink)