[API change] Use just one option to specify the build target.

There is no more option for static or share build. This value is
integrated in the build-target.
This commit is contained in:
Matthieu Gautier 2017-02-22 15:26:24 +01:00
parent c31a29488a
commit 29bba313bc
6 changed files with 47 additions and 50 deletions

View File

@ -12,12 +12,12 @@ deploy:
skip_cleanup: true skip_cleanup: true
script: travis/deploy.sh script: travis/deploy.sh
on: on:
condition: ( "$STATIC_BUILD" = "true" ) && ( "$TRAVIS_EVENT_TYPE" = "cron" ) condition: ( "$DEPLOY" = "true" ) && ( "$TRAVIS_EVENT_TYPE" = "cron" )
env: env:
- STATIC_BUILD=true BUILD_TARGET=native - BUILD_OPTION="--target-platform=native_dyn"
- STATIC_BUILD=true BUILD_TARGET=win32 - BUILD_OPTION="--target-platform=native_static" ARCHIVE_TYPE="--tar" DEPLOY=true
- STATIC_BUILD=false BUILD_TARGET=native - BUILD_OPTION="--target-platform=win32_dyn"
- STATIC_BUILD=false BUILD_TARGET=win32 - BUILD_OPTION="--target-platform=win32_static" ARCHIVE_TYPE="--zip" DEPLOY=true
notifications: notifications:
irc: irc:
channels: channels:

View File

@ -44,28 +44,28 @@ class zlib(Dependency):
@property @property
def all_configure_option(self): def all_configure_option(self):
return '--static' if self.buildEnv.build_static else '--shared' return '--static' if self.buildEnv.platform_info.static else '--shared'
@property @property
def configure_option(self): def configure_option(self):
options = "-DINSTALL_PKGCONFIG_DIR={}".format(pj(self.buildEnv.install_dir, self.buildEnv.libprefix, 'pkgconfig')) options = "-DINSTALL_PKGCONFIG_DIR={}".format(pj(self.buildEnv.install_dir, self.buildEnv.libprefix, 'pkgconfig'))
if self.buildEnv.build_static: if self.buildEnv.platform_info.static:
options += " -DBUILD_SHARED_LIBS=false" options += " -DBUILD_SHARED_LIBS=false"
else: else:
options += " -DBUILD_SHARED_LIBS=true" options += " -DBUILD_SHARED_LIBS=true"
return options return options
def _configure(self, context): def _configure(self, context):
if self.buildEnv.target_info.build == 'win32': if self.buildEnv.platform_info.build == 'win32':
raise SkipCommand() raise SkipCommand()
return super()._configure(context) return super()._configure(context)
@property @property
def make_option(self): def make_option(self):
if self.buildEnv.target_info.build == 'win32': if self.buildEnv.platform_info.build == 'win32':
return "--makefile win32/Makefile.gcc PREFIX={host}- SHARED_MODE={static} INCLUDE_PATH={include_path} LIBRARY_PATH={library_path} BINARY_PATH={binary_path}".format( return "--makefile win32/Makefile.gcc PREFIX={host}- SHARED_MODE={static} INCLUDE_PATH={include_path} LIBRARY_PATH={library_path} BINARY_PATH={binary_path}".format(
host='i686-w64-mingw32', host='i686-w64-mingw32',
static="0" if self.buildEnv.target_info.static else "1", static="0" if self.buildEnv.platform_info.static else "1",
include_path=pj(self.buildEnv.install_dir, 'include'), include_path=pj(self.buildEnv.install_dir, 'include'),
library_path=pj(self.buildEnv.install_dir, self.buildEnv.libprefix), library_path=pj(self.buildEnv.install_dir, self.buildEnv.libprefix),
binary_path=pj(self.buildEnv.install_dir, 'bin'), binary_path=pj(self.buildEnv.install_dir, 'bin'),
@ -121,7 +121,7 @@ class Xapian(Dependency):
@property @property
def dependencies(self): def dependencies(self):
deps = ['zlib', 'lzma'] deps = ['zlib', 'lzma']
if self.buildEnv.build_target == 'win32': if self.buildEnv.platform_info.build == 'win32':
return deps return deps
return deps + ['UUID'] return deps + ['UUID']
@ -241,7 +241,7 @@ class Kiwixlib(Dependency):
@property @property
def dependencies(self): def dependencies(self):
if self.buildEnv.build_target == 'win32': if self.buildEnv.platform_info.build == 'win32':
return ["Xapian", "CTPP2", "Pugixml", "Icu_cross_compile", "Zimlib"] return ["Xapian", "CTPP2", "Pugixml", "Icu_cross_compile", "Zimlib"]
return ["Xapian", "CTPP2", "Pugixml", "Icu", "Zimlib"] return ["Xapian", "CTPP2", "Pugixml", "Icu", "Zimlib"]
@ -265,6 +265,6 @@ class KiwixTools(Dependency):
@property @property
def configure_option(self): def configure_option(self):
base_options = "-Dctpp2-install-prefix={buildEnv.install_dir}" base_options = "-Dctpp2-install-prefix={buildEnv.install_dir}"
if self.buildEnv.build_static: if self.buildEnv.platform_info.static:
base_options += " -Dstatic-linkage=true" base_options += " -Dstatic-linkage=true"
return base_options return base_options

View File

@ -196,7 +196,7 @@ class MakeBuilder(Builder):
def all_configure_option(self): def all_configure_option(self):
return "{} {} {}".format( return "{} {} {}".format(
self.configure_option, self.configure_option,
self.static_configure_option if self.buildEnv.build_static else self.dynamic_configure_option, self.static_configure_option if self.buildEnv.platform_info.static else self.dynamic_configure_option,
self.buildEnv.configure_option if not self.target.force_native_build else "") self.buildEnv.configure_option if not self.target.force_native_build else "")
def _configure(self, context): def _configure(self, context):
@ -209,7 +209,7 @@ class MakeBuilder(Builder):
libdir=pj(self.buildEnv.install_dir, self.buildEnv.libprefix) libdir=pj(self.buildEnv.install_dir, self.buildEnv.libprefix)
) )
env = Defaultdict(str, os.environ) env = Defaultdict(str, os.environ)
if self.buildEnv.build_static: if self.buildEnv.platform_info.static:
env['CFLAGS'] = env['CFLAGS'] + ' -fPIC' env['CFLAGS'] = env['CFLAGS'] + ' -fPIC'
if self.configure_env: if self.configure_env:
for k in self.configure_env: for k in self.configure_env:
@ -254,7 +254,7 @@ class CMakeBuilder(MakeBuilder):
cross_option="-DCMAKE_TOOLCHAIN_FILE={}".format(self.buildEnv.cmake_crossfile) if self.buildEnv.cmake_crossfile else "" cross_option="-DCMAKE_TOOLCHAIN_FILE={}".format(self.buildEnv.cmake_crossfile) if self.buildEnv.cmake_crossfile else ""
) )
env = Defaultdict(str, os.environ) env = Defaultdict(str, os.environ)
if self.buildEnv.build_static: if self.buildEnv.platform_info.static:
env['CFLAGS'] = env['CFLAGS'] + ' -fPIC' env['CFLAGS'] = env['CFLAGS'] + ' -fPIC'
if self.configure_env: if self.configure_env:
for k in self.configure_env: for k in self.configure_env:
@ -271,7 +271,7 @@ class MesonBuilder(Builder):
@property @property
def library_type(self): def library_type(self):
return 'static' if self.buildEnv.build_static else 'shared' return 'static' if self.buildEnv.platform_info.static else 'shared'
def _configure(self, context): def _configure(self, context):
context.try_skip(self.build_path) context.try_skip(self.build_path)

View File

@ -119,15 +119,26 @@ def which(name):
return output[:-1].decode() return output[:-1].decode()
class TargetInfo:
def __init__(self, build, static):
self.build = build
self.static = static
def __str__(self):
return "{}_{}".format(self.build, 'static' if self.static else 'dyn')
class BuildEnv: class BuildEnv:
build_targets = ['native', 'win32'] target_platforms = {
'native_dyn': TargetInfo('native', False),
'native_static': TargetInfo('native', True),
'win32_dyn': TargetInfo('win32', False),
'win32_static': TargetInfo('win32', True)
}
def __init__(self, options, targetsDict): def __init__(self, options, targetsDict):
self.source_dir = pj(options.working_dir, "SOURCE") self.source_dir = pj(options.working_dir, "SOURCE")
build_dir = "BUILD_{target}_{libmod}".format( build_dir = "BUILD_{}".format(options.target_platform)
target=options.build_target,
libmod='static' if options.build_static else 'dyn'
)
self.build_dir = pj(options.working_dir, build_dir) self.build_dir = pj(options.working_dir, build_dir)
self.archive_dir = pj(options.working_dir, "ARCHIVE") self.archive_dir = pj(options.working_dir, "ARCHIVE")
self.log_dir = pj(options.working_dir, 'LOGS') self.log_dir = pj(options.working_dir, 'LOGS')
@ -145,7 +156,7 @@ class BuildEnv:
self.meson_command = self._detect_meson() self.meson_command = self._detect_meson()
if not self.meson_command: if not self.meson_command:
sys.exit("ERROR: meson command not fount") sys.exit("ERROR: meson command not fount")
self.setup_build(options.build_target) self.setup_build(options.target_platform)
self.setup_toolchains() self.setup_toolchains()
self.options = options self.options = options
self.libprefix = options.libprefix or self._detect_libdir() self.libprefix = options.libprefix or self._detect_libdir()
@ -169,20 +180,20 @@ class BuildEnv:
if self.distname == 'ubuntu': if self.distname == 'ubuntu':
self.distname = 'debian' self.distname = 'debian'
def setup_build(self, target): def setup_build(self, target_platform):
self.build_target = target self.platform_info = platform_info = self.target_platforms[target_platform]
if target == 'native': if platform_info.build == 'native':
self.cross_env = {} self.cross_env = {}
else: else:
cross_name = "{host}_{target}".format( cross_name = "{host}_{target}".format(
host = self.distname, host = self.distname,
target = self.build_target) target = platform_info.build)
try: try:
self.cross_env = CROSS_ENV[cross_name] self.cross_env = CROSS_ENV[cross_name]
except KeyError: except KeyError:
sys.exit("ERROR : We don't know how to set env to compile" sys.exit("ERROR : We don't know how to set env to compile"
" a {target} version on a {host} host.".format( " a {target} version on a {host} host.".format(
target = self.build_target, target = platform_info.build,
host = self.distname host = self.distname
)) ))
@ -192,7 +203,7 @@ class BuildEnv:
for toolchain_name in toolchain_names] for toolchain_name in toolchain_names]
def finalize_setup(self): def finalize_setup(self):
getattr(self, 'setup_{}'.format(self.build_target))() getattr(self, 'setup_{}'.format(self.platform_info.build))()
def setup_native(self): def setup_native(self):
self.cmake_crossfile = None self.cmake_crossfile = None
@ -374,17 +385,15 @@ class BuildEnv:
elif self.distname in ('debian', 'Ubuntu'): elif self.distname in ('debian', 'Ubuntu'):
package_installer = 'sudo apt-get install {}' package_installer = 'sudo apt-get install {}'
package_checker = 'LANG=C dpkg -s {} 2>&1 | grep Status | grep "ok installed" 1>/dev/null 2>&1' package_checker = 'LANG=C dpkg -s {} 2>&1 | grep Status | grep "ok installed" 1>/dev/null 2>&1'
mapper_name = "{host}_{target}_{build_type}".format( mapper_name = "{host}_{target}".format(
host=self.distname, host=self.distname,
target=self.build_target, target=self.platform_info)
build_type='static' if self.options.build_static else 'dyn')
try: try:
package_name_mapper = PACKAGE_NAME_MAPPERS[mapper_name] package_name_mapper = PACKAGE_NAME_MAPPERS[mapper_name]
except KeyError: except KeyError:
print("SKIP : We don't know which packages we must install to compile" print("SKIP : We don't know which packages we must install to compile"
" a {target} {build_type} version on a {host} host.".format( " a {target} {build_type} version on a {host} host.".format(
target=self.build_target, target=self.platform_info,
build_type='static' if self.options.build_static else 'dyn',
host=self.distname)) host=self.distname))
return return
@ -546,8 +555,7 @@ def parse_args():
parser.add_argument('targets', default='KiwixTools', nargs='?') parser.add_argument('targets', default='KiwixTools', nargs='?')
parser.add_argument('--working-dir', default=".") parser.add_argument('--working-dir', default=".")
parser.add_argument('--libprefix', default=None) parser.add_argument('--libprefix', default=None)
parser.add_argument('--build-static', action="store_true") parser.add_argument('--target-platform', default="native_dyn", choices=BuildEnv.target_platforms)
parser.add_argument('--build-target', default="native", choices=BuildEnv.build_targets)
parser.add_argument('--verbose', '-v', action="store_true", parser.add_argument('--verbose', '-v', action="store_true",
help=("Print all logs on stdout instead of in specific" help=("Print all logs on stdout instead of in specific"
" log files per commands")) " log files per commands"))

View File

@ -2,9 +2,4 @@
set -e set -e
OPTION="" ./kiwix-build.py $BUILD_OPTION
if [ "${STATIC_BUILD}" = "true" ]; then
OPTION="--build-static"
fi
./kiwix-build.py --build-target=${BUILD_TARGET} ${OPTION}

View File

@ -6,14 +6,8 @@ SSH_KEY=travis/travisci_builder_id_key
chmod 600 ${SSH_KEY} chmod 600 ${SSH_KEY}
BASE_DIR="BUILD_*/INSTALL"
BASE_DIR="BUILD_${BUILD_TARGET}_static/INSTALL" ./kiwix-deploy.py ${BASE_DIR} ${ARCHIVE_TYPE} \
if [ "${BUILD_TARGET}" = "win32" ]; then
ARCHIVE_OPTION="--zip"
else
ARCHIVE_OPTION="--tar"
fi
./kiwix-deploy.py ${BASE_DIR} ${ARCHIVE_OPTION} \
--deploy \ --deploy \
--ssh_private_key=${SSH_KEY} \ --ssh_private_key=${SSH_KEY} \
--server=nightlybot@download.kiwix.org \ --server=nightlybot@download.kiwix.org \