Separate 'Source' and 'Builder' in different classes instead of Mixin.
This allow a better separation between what is common to all builds and what is specific to a build target.
This commit is contained in:
parent
514a53db2a
commit
b5208e4708
296
kiwix-build.py
296
kiwix-build.py
|
@ -258,19 +258,22 @@ class BuildEnv:
|
||||||
##### PROJECT
|
##### PROJECT
|
||||||
################################################################################
|
################################################################################
|
||||||
class Dependency:
|
class Dependency:
|
||||||
subsource_dir = None
|
force_native_build = False
|
||||||
|
version = None
|
||||||
def __init__(self, buildEnv):
|
def __init__(self, buildEnv):
|
||||||
self.buildEnv = buildEnv
|
self.buildEnv = buildEnv
|
||||||
|
self.source = self.Source(self)
|
||||||
|
self.builder = self.Builder(self)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def full_name(self):
|
||||||
|
if self.version:
|
||||||
|
return "{}-{}".format(self.name, self.version)
|
||||||
|
return self.name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def source_path(self):
|
def source_path(self):
|
||||||
if self.subsource_dir:
|
return pj(self.buildEnv.source_dir, self.source.source_dir)
|
||||||
return pj(self.buildEnv.source_dir, self.source_dir, self.subsource_dir)
|
|
||||||
return pj(self.buildEnv.source_dir, self.source_dir)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def build_path(self):
|
|
||||||
return pj(self.buildEnv.build_dir, self.source_dir)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _log_dir(self):
|
def _log_dir(self):
|
||||||
|
@ -299,19 +302,32 @@ class Dependency:
|
||||||
print("ERROR")
|
print("ERROR")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
class ReleaseDownloadMixin:
|
|
||||||
archive_top_dir = None
|
class Source:
|
||||||
|
"""Base Class to the real preparator
|
||||||
|
A source preparator must install source in the self.source_dir attribute
|
||||||
|
inside the buildEnv.source_dir."""
|
||||||
|
def __init__(self, target):
|
||||||
|
self.target = target
|
||||||
|
self.buildEnv = target.buildEnv
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extract_path(self):
|
def name(self):
|
||||||
return pj(self.buildEnv.source_dir, self.extract_dir)
|
return self.target.name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def source_dir(self):
|
def source_dir(self):
|
||||||
return "{}-{}".format(self.name, self.version)
|
return self.target.full_name
|
||||||
|
|
||||||
|
def command(self, *args, **kwargs):
|
||||||
|
return self.target.command(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class ReleaseDownload(Source):
|
||||||
|
archive_top_dir = None
|
||||||
@property
|
@property
|
||||||
def extract_dir(self):
|
def extract_path(self):
|
||||||
return "{}-{}".format(self.name, self.version)
|
return pj(self.buildEnv.source_dir, self.source_dir)
|
||||||
|
|
||||||
def _download(self, context):
|
def _download(self, context):
|
||||||
self.buildEnv.download(self.archive)
|
self.buildEnv.download(self.archive)
|
||||||
|
@ -323,7 +339,7 @@ class ReleaseDownloadMixin:
|
||||||
extract_archive(pj(self.buildEnv.archive_dir, self.archive.name),
|
extract_archive(pj(self.buildEnv.archive_dir, self.archive.name),
|
||||||
self.buildEnv.source_dir,
|
self.buildEnv.source_dir,
|
||||||
topdir=self.archive_top_dir,
|
topdir=self.archive_top_dir,
|
||||||
name=self.extract_dir)
|
name=self.source_dir)
|
||||||
|
|
||||||
def _patch(self, context):
|
def _patch(self, context):
|
||||||
context.try_skip(self.extract_path)
|
context.try_skip(self.extract_path)
|
||||||
|
@ -338,7 +354,7 @@ class ReleaseDownloadMixin:
|
||||||
self.command('patch', self._patch)
|
self.command('patch', self._patch)
|
||||||
|
|
||||||
|
|
||||||
class GitCloneMixin:
|
class GitClone(Source):
|
||||||
git_ref = "master"
|
git_ref = "master"
|
||||||
@property
|
@property
|
||||||
def source_dir(self):
|
def source_dir(self):
|
||||||
|
@ -363,7 +379,37 @@ class GitCloneMixin:
|
||||||
self.command('gitupdate', self._git_update)
|
self.command('gitupdate', self._git_update)
|
||||||
|
|
||||||
|
|
||||||
class MakeMixin:
|
class Builder:
|
||||||
|
subsource_dir = None
|
||||||
|
def __init__(self, target):
|
||||||
|
self.target = target
|
||||||
|
self.buildEnv = target.buildEnv
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
return self.target.name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def source_path(self):
|
||||||
|
base_source_path = self.target.source_path
|
||||||
|
if self.subsource_dir:
|
||||||
|
return pj(base_source_path, self.subsource_dir)
|
||||||
|
return base_source_path
|
||||||
|
|
||||||
|
@property
|
||||||
|
def build_path(self):
|
||||||
|
return pj(self.buildEnv.build_dir, self.target.full_name)
|
||||||
|
|
||||||
|
def command(self, *args, **kwargs):
|
||||||
|
return self.target.command(*args, **kwargs)
|
||||||
|
|
||||||
|
def build(self):
|
||||||
|
self.command('configure', self._configure)
|
||||||
|
self.command('compile', self._compile)
|
||||||
|
self.command('install', self._install)
|
||||||
|
|
||||||
|
|
||||||
|
class MakeBuilder(Builder):
|
||||||
configure_option = ""
|
configure_option = ""
|
||||||
make_option = ""
|
make_option = ""
|
||||||
install_option = ""
|
install_option = ""
|
||||||
|
@ -409,13 +455,8 @@ class MakeMixin:
|
||||||
)
|
)
|
||||||
self.buildEnv.run_command(command, self.build_path, context)
|
self.buildEnv.run_command(command, self.build_path, context)
|
||||||
|
|
||||||
def build(self):
|
|
||||||
self.command('configure', self._configure)
|
|
||||||
self.command('compile', self._compile)
|
|
||||||
self.command('install', self._install)
|
|
||||||
|
|
||||||
|
class CMakeBuilder(MakeBuilder):
|
||||||
class CMakeMixin(MakeMixin):
|
|
||||||
def _configure(self, context):
|
def _configure(self, context):
|
||||||
context.try_skip(self.build_path)
|
context.try_skip(self.build_path)
|
||||||
command = "{command} {configure_option} -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DCMAKE_INSTALL_PREFIX={install_dir} -DCMAKE_INSTALL_LIBDIR={libdir} {source_path}"
|
command = "{command} {configure_option} -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DCMAKE_INSTALL_PREFIX={install_dir} -DCMAKE_INSTALL_LIBDIR={libdir} {source_path}"
|
||||||
|
@ -438,7 +479,8 @@ class CMakeMixin(MakeMixin):
|
||||||
env.update(self.configure_env)
|
env.update(self.configure_env)
|
||||||
self.buildEnv.run_command(command, self.build_path, context, env=env, allow_wrapper=False)
|
self.buildEnv.run_command(command, self.build_path, context, env=env, allow_wrapper=False)
|
||||||
|
|
||||||
class MesonMixin(MakeMixin):
|
class MesonBuilder(Builder):
|
||||||
|
configure_option = ""
|
||||||
def _gen_env(self):
|
def _gen_env(self):
|
||||||
env = Defaultdict(str, os.environ)
|
env = Defaultdict(str, os.environ)
|
||||||
env['PKG_CONFIG_PATH'] = (env['PKG_CONFIG_PATH'] + ':' + pj(self.buildEnv.install_dir, self.buildEnv.libprefix, 'pkgconfig')
|
env['PKG_CONFIG_PATH'] = (env['PKG_CONFIG_PATH'] + ':' + pj(self.buildEnv.install_dir, self.buildEnv.libprefix, 'pkgconfig')
|
||||||
|
@ -498,133 +540,163 @@ class MesonMixin(MakeMixin):
|
||||||
# gettext
|
# gettext
|
||||||
# *************************************
|
# *************************************
|
||||||
|
|
||||||
class UUID(Dependency, ReleaseDownloadMixin, MakeMixin):
|
class UUID(Dependency):
|
||||||
name = 'uuid'
|
name = 'uuid'
|
||||||
version = "1.42"
|
version = "1.42"
|
||||||
archive = Remotefile('e2fsprogs-1.42.tar.gz',
|
|
||||||
'55b46db0cec3e2eb0e5de14494a88b01ff6c0500edf8ca8927cad6da7b5e4a46')
|
class Source(ReleaseDownload):
|
||||||
source_dir = extract_dir = 'e2fsprogs-1.42'
|
archive = Remotefile('e2fsprogs-1.42.tar.gz',
|
||||||
configure_option = "--enable-libuuid"
|
'55b46db0cec3e2eb0e5de14494a88b01ff6c0500edf8ca8927cad6da7b5e4a46')
|
||||||
configure_env = {'_format_CFLAGS' : "{env.CFLAGS} -fPIC"}
|
extract_dir = 'e2fsprogs-1.42'
|
||||||
make_target = 'libs'
|
|
||||||
make_install_target = 'install-libs'
|
class Builder(MakeBuilder):
|
||||||
|
configure_option = "--enable-libuuid"
|
||||||
|
configure_env = {'_format_CFLAGS' : "{env.CFLAGS} -fPIC"}
|
||||||
|
make_target = 'libs'
|
||||||
|
make_install_target = 'install-libs'
|
||||||
|
|
||||||
|
|
||||||
class Xapian(Dependency, ReleaseDownloadMixin, MakeMixin):
|
class Xapian(Dependency):
|
||||||
name = "xapian-core"
|
name = "xapian-core"
|
||||||
version = "1.4.0"
|
version = "1.4.0"
|
||||||
archive = Remotefile('xapian-core-1.4.0.tar.xz',
|
|
||||||
'10584f57112aa5e9c0e8a89e251aecbf7c582097638bfee79c1fe39a8b6a6477')
|
class Source(ReleaseDownload):
|
||||||
configure_option = ("--enable-shared --enable-static --disable-sse "
|
archive = Remotefile('xapian-core-1.4.0.tar.xz',
|
||||||
"--disable-backend-inmemory --disable-documentation")
|
'10584f57112aa5e9c0e8a89e251aecbf7c582097638bfee79c1fe39a8b6a6477')
|
||||||
patches = ["xapian_pkgconfig.patch"]
|
patches = ["xapian_pkgconfig.patch"]
|
||||||
configure_env = {'_format_LDFLAGS' : "-L{buildEnv.install_dir}/{buildEnv.libprefix}",
|
|
||||||
'_format_CXXFLAGS' : "-I{buildEnv.install_dir}/include"}
|
class Builder(MakeBuilder):
|
||||||
|
configure_option = ("--enable-shared --enable-static --disable-sse "
|
||||||
|
"--disable-backend-inmemory --disable-documentation")
|
||||||
|
configure_env = {'_format_LDFLAGS' : "-L{buildEnv.install_dir}/{buildEnv.libprefix}",
|
||||||
|
'_format_CXXFLAGS' : "-I{buildEnv.install_dir}/include"}
|
||||||
|
|
||||||
|
|
||||||
class CTPP2(Dependency, ReleaseDownloadMixin, CMakeMixin):
|
class CTPP2(Dependency):
|
||||||
name = "ctpp2"
|
name = "ctpp2"
|
||||||
version = "2.8.3"
|
version = "2.8.3"
|
||||||
archive = Remotefile('ctpp2-2.8.3.tar.gz',
|
|
||||||
'a83ffd07817adb575295ef40fbf759892512e5a63059c520f9062d9ab8fb42fc')
|
class Source(ReleaseDownload):
|
||||||
configure_option = "-DMD5_SUPPORT=OFF"
|
archive = Remotefile('ctpp2-2.8.3.tar.gz',
|
||||||
patches = ["ctpp2_include.patch",
|
'a83ffd07817adb575295ef40fbf759892512e5a63059c520f9062d9ab8fb42fc')
|
||||||
|
patches = ["ctpp2_include.patch",
|
||||||
"ctpp2_no_src_modification.patch",
|
"ctpp2_no_src_modification.patch",
|
||||||
"ctpp2_fix-static-libname.patch",
|
"ctpp2_fix-static-libname.patch",
|
||||||
"ctpp2_mingw32.patch",
|
"ctpp2_mingw32.patch",
|
||||||
"ctpp2_dll_export_VMExecutable.patch",
|
"ctpp2_dll_export_VMExecutable.patch",
|
||||||
"ctpp2_win_install_lib_in_lib_dir.patch"]
|
"ctpp2_win_install_lib_in_lib_dir.patch"]
|
||||||
|
|
||||||
|
class Builder(CMakeBuilder):
|
||||||
|
configure_option = "-DMD5_SUPPORT=OFF"
|
||||||
|
|
||||||
class Pugixml(Dependency, ReleaseDownloadMixin, MesonMixin):
|
|
||||||
|
class Pugixml(Dependency):
|
||||||
name = "pugixml"
|
name = "pugixml"
|
||||||
version = "1.2"
|
version = "1.2"
|
||||||
archive = Remotefile('pugixml-1.2.tar.gz',
|
|
||||||
'0f422dad86da0a2e56a37fb2a88376aae6e931f22cc8b956978460c9db06136b')
|
class Source(ReleaseDownload):
|
||||||
patches = ["pugixml_meson.patch"]
|
archive = Remotefile('pugixml-1.2.tar.gz',
|
||||||
|
'0f422dad86da0a2e56a37fb2a88376aae6e931f22cc8b956978460c9db06136b')
|
||||||
|
patches = ["pugixml_meson.patch"]
|
||||||
|
|
||||||
|
Builder = MesonBuilder
|
||||||
|
|
||||||
|
|
||||||
class MicroHttpd(Dependency, ReleaseDownloadMixin, MakeMixin):
|
class MicroHttpd(Dependency):
|
||||||
name = "libmicrohttpd"
|
name = "libmicrohttpd"
|
||||||
configure_option = "--enable-shared --enable-static --disable-https --without-libgcrypt --without-libcurl"
|
|
||||||
version = "0.9.46"
|
version = "0.9.46"
|
||||||
archive = Remotefile('libmicrohttpd-0.9.46.tar.gz',
|
|
||||||
'06dbd2654f390fa1e8196fe063fc1449a6c2ed65a38199a49bf29ad8a93b8979',
|
class Source(ReleaseDownload):
|
||||||
'http://ftp.gnu.org/gnu/libmicrohttpd/libmicrohttpd-0.9.46.tar.gz')
|
archive = Remotefile('libmicrohttpd-0.9.46.tar.gz',
|
||||||
|
'06dbd2654f390fa1e8196fe063fc1449a6c2ed65a38199a49bf29ad8a93b8979',
|
||||||
|
'http://ftp.gnu.org/gnu/libmicrohttpd/libmicrohttpd-0.9.46.tar.gz')
|
||||||
|
|
||||||
|
class Builder(MakeBuilder):
|
||||||
|
configure_option = "--enable-shared --enable-static --disable-https --without-libgcrypt --without-libcurl"
|
||||||
|
|
||||||
|
|
||||||
class Icu(Dependency, ReleaseDownloadMixin, MakeMixin):
|
class Icu(Dependency):
|
||||||
name = "icu4c"
|
name = "icu4c"
|
||||||
version = "56_1"
|
version = "56_1"
|
||||||
archive = Remotefile('icu4c-56_1-src.tgz',
|
|
||||||
'3a64e9105c734dcf631c0b3ed60404531bce6c0f5a64bfe1a6402a4cc2314816'
|
|
||||||
)
|
|
||||||
data = Remotefile('icudt56l.dat',
|
|
||||||
'e23d85eee008f335fc49e8ef37b1bc2b222db105476111e3d16f0007d371cbca')
|
|
||||||
patches = ["icu4c_fix_static_lib_name_mingw.patch"]
|
|
||||||
subsource_dir = "source"
|
|
||||||
|
|
||||||
def __init__(self, buildEnv, cross_compile_process=False, cross_build=None):
|
def __init__(self, buildEnv, cross_compile_process=False, cross_build=None):
|
||||||
Dependency.__init__(self, buildEnv)
|
Dependency.__init__(self, buildEnv)
|
||||||
self.cross_compile_process = cross_compile_process
|
self.builder.cross_compile_process = cross_compile_process
|
||||||
self.cross_build = cross_build
|
self.builder.cross_build = cross_build
|
||||||
|
|
||||||
@property
|
class Source(ReleaseDownload):
|
||||||
def build_path(self):
|
archive = Remotefile('icu4c-56_1-src.tgz',
|
||||||
if self.cross_compile_process and not self.cross_build:
|
'3a64e9105c734dcf631c0b3ed60404531bce6c0f5a64bfe1a6402a4cc2314816'
|
||||||
return pj(self.buildEnv.build_dir, self.source_dir+"_native")
|
)
|
||||||
return pj(self.buildEnv.build_dir, self.source_dir)
|
patches = ["icu4c_fix_static_lib_name_mingw.patch"]
|
||||||
|
data = Remotefile('icudt56l.dat',
|
||||||
|
'e23d85eee008f335fc49e8ef37b1bc2b222db105476111e3d16f0007d371cbca')
|
||||||
|
|
||||||
@property
|
def _download_data(self, context):
|
||||||
def configure_option(self):
|
self.buildEnv.download(self.data)
|
||||||
default_configure_option = "--disable-samples --disable-tests --disable-extras --disable-dyload"
|
|
||||||
if self.buildEnv.build_static:
|
|
||||||
default_configure_option += " --enable-static --disable-shared"
|
|
||||||
else:
|
|
||||||
default_configure_option += " --enable-shared --enable-shared"
|
|
||||||
if self.cross_build:
|
|
||||||
return default_configure_option + " --with-cross-build=" + self.cross_build.build_path
|
|
||||||
return default_configure_option
|
|
||||||
|
|
||||||
def _download_data(self, context):
|
def _copy_data(self, context):
|
||||||
self.buildEnv.download(self.data)
|
context.try_skip(self.extract_path)
|
||||||
|
shutil.copyfile(pj(self.buildEnv.archive_dir, self.data.name), pj(self.extract_path, 'source', 'data', 'in', self.data.name))
|
||||||
|
|
||||||
def _copy_data(self, context):
|
def prepare(self):
|
||||||
context.try_skip(self.source_path)
|
super().prepare()
|
||||||
shutil.copyfile(pj(self.buildEnv.archive_dir, self.data.name), pj(self.source_path, 'data', 'in', self.data.name))
|
self.command("download_data", self._download_data)
|
||||||
|
self.command("copy_data", self._copy_data)
|
||||||
|
|
||||||
def _install(self, context):
|
class Builder(MakeBuilder):
|
||||||
if self.cross_compile_process and not self.cross_build:
|
subsource_dir = "source"
|
||||||
raise SkipCommand()
|
|
||||||
return super()._install.(context)
|
|
||||||
|
|
||||||
def prepare(self):
|
@property
|
||||||
super().prepare()
|
def configure_option(self):
|
||||||
self.command('download_data', self._download_data)
|
default_configure_option = "--disable-samples --disable-tests --disable-extras --disable-dyload"
|
||||||
self.command('copy_data', self._copy_data)
|
if self.buildEnv.build_static:
|
||||||
|
default_configure_option += " --enable-static --disable-shared"
|
||||||
|
else:
|
||||||
|
default_configure_option += " --enable-shared --enable-shared"
|
||||||
|
if self.cross_build:
|
||||||
|
return default_configure_option + " --with-cross-build=" + self.cross_build.build_path
|
||||||
|
return default_configure_option
|
||||||
|
|
||||||
|
def _install(self, context):
|
||||||
|
if self.target.cross_compile_process and not self.target.cross_build:
|
||||||
|
raise SkipCommand()
|
||||||
|
return super()._install.(context)
|
||||||
|
|
||||||
|
|
||||||
class Zimlib(Dependency, GitCloneMixin, MesonMixin):
|
class Zimlib(Dependency):
|
||||||
name = "zimlib"
|
name = "zimlib"
|
||||||
#git_remote = "https://gerrit.wikimedia.org/r/p/openzim.git"
|
|
||||||
git_remote = "https://github.com/mgautierfr/openzim"
|
class Source(GitClone):
|
||||||
git_dir = "openzim"
|
#git_remote = "https://gerrit.wikimedia.org/r/p/openzim.git"
|
||||||
git_ref = "meson"
|
git_remote = "https://github.com/mgautierfr/openzim"
|
||||||
subsource_dir = "zimlib"
|
git_dir = "openzim"
|
||||||
|
git_ref = "meson"
|
||||||
|
|
||||||
|
class Builder(MesonBuilder):
|
||||||
|
subsource_dir = "zimlib"
|
||||||
|
|
||||||
|
|
||||||
class Kiwixlib(Dependency, GitCloneMixin, MesonMixin):
|
class Kiwixlib(Dependency):
|
||||||
name = "kiwix-lib"
|
name = "kiwix-lib"
|
||||||
git_remote = "https://github.com/kiwix/kiwix-lib.git"
|
|
||||||
git_dir = "kiwix-lib"
|
class Source(GitClone):
|
||||||
configure_option = "-Dctpp2-install-prefix={buildEnv.install_dir}"
|
git_remote = "https://github.com/kiwix/kiwix-lib.git"
|
||||||
|
git_dir = "kiwix-lib"
|
||||||
|
|
||||||
|
class Builder(MesonBuilder):
|
||||||
|
configure_option = "-Dctpp2-install-prefix={buildEnv.install_dir}"
|
||||||
|
|
||||||
|
|
||||||
class KiwixTools(Dependency, GitCloneMixin, MesonMixin):
|
class KiwixTools(Dependency):
|
||||||
name = "kiwix-tools"
|
name = "kiwix-tools"
|
||||||
git_remote = "https://github.com/kiwix/kiwix-tools.git"
|
|
||||||
git_dir = "kiwix-tools"
|
class Source(GitClone):
|
||||||
configure_option = "-Dctpp2-install-prefix={buildEnv.install_dir}"
|
git_remote = "https://github.com/kiwix/kiwix-tools.git"
|
||||||
|
git_dir = "kiwix-tools"
|
||||||
|
|
||||||
|
class Builder(MesonBuilder):
|
||||||
|
configure_option = "-Dctpp2-install-prefix={buildEnv.install_dir}"
|
||||||
|
|
||||||
|
|
||||||
class Builder:
|
class Builder:
|
||||||
|
@ -659,13 +731,15 @@ class Builder:
|
||||||
|
|
||||||
def prepare(self):
|
def prepare(self):
|
||||||
for dependency in self.dependencies:
|
for dependency in self.dependencies:
|
||||||
print("prepare {} :".format(dependency.name))
|
source = dependency.source
|
||||||
dependency.prepare()
|
print("prepare {} :".format(source.name))
|
||||||
|
source.prepare()
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
for dependency in self.dependencies:
|
for dependency in self.dependencies:
|
||||||
print("build {} :".format(dependency.name))
|
builder = dependency.builder
|
||||||
dependency.build()
|
print("build {} :".format(builder.name))
|
||||||
|
builder.build()
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
|
Loading…
Reference in New Issue