From 115fbfa1476c328ae58e9eff7c784bf67e8e5aae Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Mon, 28 May 2018 11:44:54 +0200 Subject: [PATCH] Move dependencies declaration of a target into the builder. This is the builder that depends on other target, not the target itself. --- kiwixbuild/builder.py | 4 +-- kiwixbuild/dependencies/all_dependencies.py | 36 ++++++++++----------- kiwixbuild/dependencies/base.py | 6 +++- kiwixbuild/dependencies/icu4c.py | 3 +- kiwixbuild/dependencies/kiwix_android.py | 3 +- kiwixbuild/dependencies/kiwix_custom_app.py | 3 +- kiwixbuild/dependencies/kiwix_lib.py | 23 ++++++------- kiwixbuild/dependencies/kiwix_tools.py | 3 +- kiwixbuild/dependencies/libaria2.py | 2 +- kiwixbuild/dependencies/libmagic.py | 3 +- kiwixbuild/dependencies/libzim.py | 16 ++++----- kiwixbuild/dependencies/xapian.py | 14 ++++---- kiwixbuild/dependencies/zim_tools.py | 3 +- kiwixbuild/dependencies/zimwriterfs.py | 16 ++++----- 14 files changed, 72 insertions(+), 63 deletions(-) diff --git a/kiwixbuild/builder.py b/kiwixbuild/builder.py index 52b9525..a83d3c6 100644 --- a/kiwixbuild/builder.py +++ b/kiwixbuild/builder.py @@ -32,12 +32,12 @@ class Builder: targetClass = Dependency.all_deps[targetName] target = targetClass(self.buildEnv) targets[targetName] = target - for dep in target.dependencies: + for dep in target.builder.get_dependencies(self.platform): self.add_targets(dep, targets) def order_dependencies(self, _targets, targetName): target = _targets[targetName] - for depName in target.dependencies: + for depName in target.builder.dependencies(self.platform): yield from self.order_dependencies(_targets, depName) yield targetName diff --git a/kiwixbuild/dependencies/all_dependencies.py b/kiwixbuild/dependencies/all_dependencies.py index 9eb6837..c55d727 100644 --- a/kiwixbuild/dependencies/all_dependencies.py +++ b/kiwixbuild/dependencies/all_dependencies.py @@ -8,23 +8,21 @@ from kiwixbuild._global import neutralEnv class AllBaseDependencies(Dependency): name = "alldependencies" - @property - def dependencies(self): - base_deps = ['zlib', 'lzma', 'xapian-core', 'gumbo', 'pugixml', 'libmicrohttpd', 'libaria2'] - if self.buildEnv.platform_info.build != 'native': - base_deps += ["icu4c_cross-compile"] - if self.buildEnv.platform_info.build != 'win32': - base_deps += ["libmagic_cross-compile"] - else: - base_deps += ["icu4c", "libmagic"] - if ( self.buildEnv.platform_info.build != 'android' - and neutralEnv('distname') != 'Darwin'): - base_deps += ['ctpp2c', 'ctpp2'] - if self.buildEnv.platform_info.build == 'android': - base_deps += ['Gradle'] - - return base_deps - - Source = NoopSource - Builder = NoopBuilder + class Builder(NoopBuilder): + @classmethod + def get_dependencies(cls, platformInfo): + base_deps = ['zlib', 'lzma', 'xapian-core', 'gumbo', 'pugixml', 'libmicrohttpd', 'libaria2'] + if platformInfo.build != 'native': + base_deps += ["icu4c_cross-compile"] + if platformInfo.build != 'win32': + base_deps += ["libmagic_cross-compile"] + else: + base_deps += ["icu4c", "libmagic"] + if (platformInfo.build != 'android' and + neutralEnv('distname') != 'Darwin'): + base_deps += ['ctpp2c', 'ctpp2'] + if platformInfo.build == 'android': + base_deps += ['Gradle'] + + return base_deps diff --git a/kiwixbuild/dependencies/base.py b/kiwixbuild/dependencies/base.py index b7ee722..45fb39f 100644 --- a/kiwixbuild/dependencies/base.py +++ b/kiwixbuild/dependencies/base.py @@ -20,7 +20,6 @@ class _MetaDependency(type): class Dependency(metaclass=_MetaDependency): all_deps = {} - dependencies = [] force_native_build = False def __init__(self, buildEnv): @@ -205,11 +204,16 @@ class SvnClone(Source): class Builder: subsource_dir = None + dependencies = [] def __init__(self, target): self.target = target self.buildEnv = target.buildEnv + @classmethod + def get_dependencies(cls, platformInfo): + return cls.dependencies + @property def name(self): return self.target.name diff --git a/kiwixbuild/dependencies/icu4c.py b/kiwixbuild/dependencies/icu4c.py index 84ce484..77ade0c 100644 --- a/kiwixbuild/dependencies/icu4c.py +++ b/kiwixbuild/dependencies/icu4c.py @@ -48,9 +48,10 @@ class Icu_native(Icu): class Icu_cross_compile(Icu): name = "icu4c_cross-compile" - dependencies = ['icu4c_native'] class Builder(Icu.Builder): + dependencies = ['icu4c_native'] + @property def configure_option(self): icu_native_dep = self.buildEnv.targetsDict['icu4c_native'] diff --git a/kiwixbuild/dependencies/kiwix_android.py b/kiwixbuild/dependencies/kiwix_android.py index 9273a01..6e00b33 100644 --- a/kiwixbuild/dependencies/kiwix_android.py +++ b/kiwixbuild/dependencies/kiwix_android.py @@ -9,13 +9,14 @@ from kiwixbuild.utils import pj class KiwixAndroid(Dependency): name = "kiwix-android" - dependencies = ["Gradle", "kiwix-lib"] class Source(GitClone): git_remote = "https://github.com/kiwix/kiwix-android" git_dir = "kiwix-android" class Builder(GradleBuilder): + dependencies = ["Gradle", "kiwix-lib"] + def build(self): if self.buildEnv.options.targets == 'kiwix-android-custom': print("SKIP") diff --git a/kiwixbuild/dependencies/kiwix_custom_app.py b/kiwixbuild/dependencies/kiwix_custom_app.py index 75d4058..5c52efe 100644 --- a/kiwixbuild/dependencies/kiwix_custom_app.py +++ b/kiwixbuild/dependencies/kiwix_custom_app.py @@ -10,7 +10,6 @@ from kiwixbuild.utils import Remotefile, pj, SkipCommand class KiwixCustomApp(Dependency): name = "kiwix-android-custom" - dependencies = ["kiwix-android", "kiwix-lib"] def __init__(self, buildEnv): super().__init__(buildEnv) @@ -21,6 +20,8 @@ class KiwixCustomApp(Dependency): git_dir = "kiwix-android-custom" class Builder(GradleBuilder): + dependencies = ["kiwix-android", "kiwix-lib"] + @property def gradle_target(self): return "assemble{}".format(self.target.custom_name) diff --git a/kiwixbuild/dependencies/kiwix_lib.py b/kiwixbuild/dependencies/kiwix_lib.py index 46e8bc3..dee3627 100644 --- a/kiwixbuild/dependencies/kiwix_lib.py +++ b/kiwixbuild/dependencies/kiwix_lib.py @@ -7,22 +7,23 @@ from kiwixbuild._global import neutralEnv class Kiwixlib(Dependency): name = "kiwix-lib" - @property - def dependencies(self): - base_dependencies = ["pugixml", "libzim", "zlib", "lzma", "libaria2"] - if ( self.buildEnv.platform_info.build != 'android' - and neutralEnv('distname') != 'Darwin'): - base_dependencies += ['ctpp2c', 'ctpp2'] - if self.buildEnv.platform_info.build != 'native': - return base_dependencies + ["icu4c_cross-compile"] - else: - return base_dependencies + ["icu4c"] - class Source(GitClone): git_remote = "https://github.com/kiwix/kiwix-lib.git" git_dir = "kiwix-lib" class Builder(MesonBuilder): + @classmethod + def get_dependencies(cls, platformInfo): + base_dependencies = ["pugixml", "libzim", "zlib", "lzma", "libaria2"] + if (platformInfo.build != 'android' and + neutralEnv('distname') != 'Darwin'): + base_dependencies += ['ctpp2c', 'ctpp2'] + if platformInfo.build != 'native': + return base_dependencies + ["icu4c_cross-compile"] + else: + return base_dependencies + ["icu4c"] + + @property def configure_option(self): base_option = "-Dctpp2-install-prefix={buildEnv.install_dir}" diff --git a/kiwixbuild/dependencies/kiwix_tools.py b/kiwixbuild/dependencies/kiwix_tools.py index 3ff33c0..1551ce7 100644 --- a/kiwixbuild/dependencies/kiwix_tools.py +++ b/kiwixbuild/dependencies/kiwix_tools.py @@ -5,13 +5,14 @@ from .base import ( class KiwixTools(Dependency): name = "kiwix-tools" - dependencies = ["kiwix-lib", "libmicrohttpd", "zlib"] class Source(GitClone): git_remote = "https://github.com/kiwix/kiwix-tools.git" git_dir = "kiwix-tools" class Builder(MesonBuilder): + dependencies = ["kiwix-lib", "libmicrohttpd", "zlib"] + @property def configure_option(self): if self.buildEnv.platform_info.static: diff --git a/kiwixbuild/dependencies/libaria2.py b/kiwixbuild/dependencies/libaria2.py index d59e443..e0a5d38 100644 --- a/kiwixbuild/dependencies/libaria2.py +++ b/kiwixbuild/dependencies/libaria2.py @@ -8,7 +8,6 @@ from kiwixbuild.utils import Remotefile, run_command class Aria2(Dependency): name = "libaria2" - dependencies = ['zlib'] class Source(ReleaseDownload): archive = Remotefile('libaria2-1.33.1.tar.gz', @@ -23,4 +22,5 @@ class Aria2(Dependency): run_command(command, self.extract_path, context) class Builder(MakeBuilder): + dependencies = ['zlib'] configure_option = "--enable-libaria2 --disable-ssl --disable-bittorent --disable-metalink --without-sqlite3 --without-libxml2 --without-libexpat" diff --git a/kiwixbuild/dependencies/libmagic.py b/kiwixbuild/dependencies/libmagic.py index b7691a6..b093191 100644 --- a/kiwixbuild/dependencies/libmagic.py +++ b/kiwixbuild/dependencies/libmagic.py @@ -38,9 +38,10 @@ class LibMagic_native(LibMagicBase): class LibMagic_cross_compile(LibMagicBase): name = "libmagic_cross-compile" - dependencies = ['libmagic_native'] class Builder(LibMagicBase.Builder): + dependencies = ['libmagic_native'] + def _compile(self, context): context.try_skip(self.build_path) command = "make -j4 {make_target} {make_option}".format( diff --git a/kiwixbuild/dependencies/libzim.py b/kiwixbuild/dependencies/libzim.py index eb46df8..3b0c19a 100644 --- a/kiwixbuild/dependencies/libzim.py +++ b/kiwixbuild/dependencies/libzim.py @@ -6,17 +6,17 @@ from .base import ( class Libzim(Dependency): name = "libzim" - @property - def dependencies(self): - base_dependencies = ['zlib', 'lzma', 'xapian-core'] - if self.buildEnv.platform_info.build != 'native': - return base_dependencies + ["icu4c_cross-compile"] - else: - return base_dependencies + ["icu4c"] - class Source(GitClone): git_remote = "https://github.com/openzim/libzim.git" git_dir = "libzim" class Builder(MesonBuilder): test_option = "-t 8" + + @classmethod + def get_dependencies(cls, platformInfo): + base_dependencies = ['zlib', 'lzma', 'xapian-core'] + if platformInfo.build != 'native': + return base_dependencies + ["icu4c_cross-compile"] + else: + return base_dependencies + ["icu4c"] diff --git a/kiwixbuild/dependencies/xapian.py b/kiwixbuild/dependencies/xapian.py index 0236e8f..8fc49a0 100644 --- a/kiwixbuild/dependencies/xapian.py +++ b/kiwixbuild/dependencies/xapian.py @@ -20,10 +20,10 @@ class Xapian(Dependency): configure_env = {'_format_LDFLAGS': "-L{buildEnv.install_dir}/{buildEnv.libprefix}", '_format_CXXFLAGS': "-I{buildEnv.install_dir}/include"} - @property - def dependencies(self): - deps = ['zlib', 'lzma'] - if (self.buildEnv.platform_info.build == 'win32' - or neutralEnv('distname') == 'Darwin'): - return deps - return deps + ['uuid'] + @classmethod + def get_dependencies(cls, platformInfo): + deps = ['zlib', 'lzma'] + if (platformInfo.build == 'win32' + or neutralEnv('distname') == 'Darwin'): + return deps + return deps + ['uuid'] diff --git a/kiwixbuild/dependencies/zim_tools.py b/kiwixbuild/dependencies/zim_tools.py index 0634390..f3454dd 100644 --- a/kiwixbuild/dependencies/zim_tools.py +++ b/kiwixbuild/dependencies/zim_tools.py @@ -5,13 +5,14 @@ from .base import ( class ZimTools(Dependency): name = "zim-tools" - dependencies = ['libzim'] class Source(GitClone): git_remote = "https://github.com/openzim/zim-tools.git" git_dir = "zim-tools" class Builder(MesonBuilder): + dependencies = ['libzim'] + @property def configure_option(self): if self.buildEnv.platform_info.static: diff --git a/kiwixbuild/dependencies/zimwriterfs.py b/kiwixbuild/dependencies/zimwriterfs.py index 075ef8e..3b0808e 100644 --- a/kiwixbuild/dependencies/zimwriterfs.py +++ b/kiwixbuild/dependencies/zimwriterfs.py @@ -6,20 +6,20 @@ from .base import ( class Zimwriterfs(Dependency): name = "zimwriterfs" - @property - def dependencies(self): - base_dependencies = ['libzim', 'zlib', 'xapian-core', 'gumbo'] - if self.buildEnv.platform_info.build != 'native': - return base_dependencies + ["icu4c_cross-compile", "libmagic_cross-compile"] - else: - return base_dependencies + ["icu4c", "libmagic"] - class Source(GitClone): git_remote = "https://github.com/openzim/zimwriterfs.git" git_dir = "zimwriterfs" release_git_ref = "1.1" class Builder(MesonBuilder): + @classmethod + def get_dependencies(cls, platformInfo): + base_dependencies = ['libzim', 'zlib', 'xapian-core', 'gumbo'] + if platformInfo.build != 'native': + return base_dependencies + ["icu4c_cross-compile", "libmagic_cross-compile"] + else: + return base_dependencies + ["icu4c", "libmagic"] + @property def configure_option(self): base_option = "-Dmagic-install-prefix={buildEnv.install_dir}"