From 781f6740f2d0ce11d64cbe244254667008c9f64c Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 19 Jun 2018 11:27:07 +0200 Subject: [PATCH] Run the command without using shell=True. It mainly allow to run command in directory containing space. (Hello, `C:\Program Files\...`) It would also allow to work on directory containning spaces (`C:\Users\John Doe`) but xapian configure (at least) expressly doesn't support it :/ - Run the command without shell=True - The command must be a list instead of a string. - All options must also be a list (or an iterable). --- kiwixbuild/buildenv.py | 6 +- kiwixbuild/dependencies/android_ndk.py | 14 +- kiwixbuild/dependencies/android_sdk.py | 10 +- kiwixbuild/dependencies/base.py | 205 ++++++++++---------- kiwixbuild/dependencies/ctpp2.py | 18 +- kiwixbuild/dependencies/gumbo.py | 2 +- kiwixbuild/dependencies/icu4c.py | 19 +- kiwixbuild/dependencies/ios_fat_lib.py | 9 +- kiwixbuild/dependencies/kiwix_custom_app.py | 43 ++-- kiwixbuild/dependencies/kiwix_desktop.py | 7 +- kiwixbuild/dependencies/kiwix_lib.py | 7 +- kiwixbuild/dependencies/kiwix_tools.py | 5 +- kiwixbuild/dependencies/libaria2.py | 4 +- kiwixbuild/dependencies/libmagic.py | 10 +- kiwixbuild/dependencies/libmicrohttpd.py | 2 +- kiwixbuild/dependencies/libzim.py | 2 +- kiwixbuild/dependencies/lzma.py | 4 +- kiwixbuild/dependencies/qt.py | 32 ++- kiwixbuild/dependencies/uuid.py | 15 +- kiwixbuild/dependencies/xapian.py | 2 +- kiwixbuild/dependencies/zim_tools.py | 5 +- kiwixbuild/dependencies/zimwriterfs.py | 7 +- kiwixbuild/dependencies/zlib.py | 30 +-- kiwixbuild/platforms/android.py | 4 +- kiwixbuild/platforms/armhf.py | 4 +- kiwixbuild/platforms/base.py | 2 +- kiwixbuild/platforms/i586.py | 4 +- kiwixbuild/platforms/ios.py | 4 +- kiwixbuild/platforms/win32.py | 4 +- kiwixbuild/utils.py | 2 +- 30 files changed, 252 insertions(+), 230 deletions(-) diff --git a/kiwixbuild/buildenv.py b/kiwixbuild/buildenv.py index 83d0338..97f6551 100644 --- a/kiwixbuild/buildenv.py +++ b/kiwixbuild/buildenv.py @@ -26,7 +26,7 @@ class PlatformNeutralEnv: self.meson_command = self._detect_meson() if not self.meson_command: sys.exit("ERROR: meson command not fount") - self.mesontest_command = "{} test".format(self.meson_command) + self.mesontest_command = [*self.meson_command, "test"] def detect_platform(self): _platform = platform.system() @@ -56,7 +56,7 @@ class PlatformNeutralEnv: # Doesn't exist in PATH or isn't executable continue if retcode == 0: - return n + return [n] def _detect_meson(self): for n in ['meson.py', 'meson']: @@ -67,7 +67,7 @@ class PlatformNeutralEnv: # Doesn't exist in PATH or isn't executable continue if retcode == 0: - return n + return [n] class BuildEnv: diff --git a/kiwixbuild/dependencies/android_ndk.py b/kiwixbuild/dependencies/android_ndk.py index fa2b00e..0f7e4da 100644 --- a/kiwixbuild/dependencies/android_ndk.py +++ b/kiwixbuild/dependencies/android_ndk.py @@ -45,13 +45,13 @@ class android_ndk(Dependency): context.try_skip(self.build_path) script = pj(self.source_path, 'build/tools/make_standalone_toolchain.py') add_execution_right(script) - command = '{script} --arch={arch} --api={api} --install-dir={install_dir} --force' - command = command.format( - script=script, - arch=self.arch, - api=self.api, - install_dir=self.install_path - ) + command = [ + script, + '--arch={}'.format(self.arch), + '--api={}'.format(api), + '--install-dir', self.install_path, + '--force' + ] context.force_native_build = True run_command(command, self.build_path, context, buildEnv=self.buildEnv) diff --git a/kiwixbuild/dependencies/android_sdk.py b/kiwixbuild/dependencies/android_sdk.py index d09f433..1bc442e 100644 --- a/kiwixbuild/dependencies/android_sdk.py +++ b/kiwixbuild/dependencies/android_sdk.py @@ -26,11 +26,11 @@ class android_sdk(Dependency): tools_dir = pj(self.install_path, 'tools') shutil.copytree(self.source_path, tools_dir) script = pj(tools_dir, 'android') - command = '{script} --verbose update sdk -a --no-ui --filter {packages}' - command = command.format( - script=script, - packages = ','.join(str(i) for i in [1,2,8,34,162]) - ) + command = [ + script, + '--verbose', 'update', 'sdk', '-a', '--no-ui', + '--filter', ','.join(str(i) for i in [1,2,8,34,162]) + ] # packages correspond to : # - 1 : Android SDK Tools, revision 25.2.5 # - 2 : Android SDK Platform-tools, revision 25.0.3 diff --git a/kiwixbuild/dependencies/base.py b/kiwixbuild/dependencies/base.py index c375db3..d147bc1 100644 --- a/kiwixbuild/dependencies/base.py +++ b/kiwixbuild/dependencies/base.py @@ -61,7 +61,7 @@ class Source: context.force_native_build = True for p in self.patches: with open(pj(SCRIPT_DIR, 'patches', p), 'r') as patch_input: - run_command("patch -p1", self.source_path, context, input=patch_input.read()) + run_command(["patch", "-p1"], self.source_path, context, input=patch_input.read()) def command(self, name, function, *args): print(" {} {} : ".format(name, self.name), end="", flush=True) @@ -149,15 +149,18 @@ class GitClone(Source): def _git_clone(self, context): if os.path.exists(self.git_path): raise SkipCommand() - command = "git clone --depth=1 --branch {} {} {}".format( - self.git_ref, self.git_remote, self.source_dir) + command = [ + "git", "clone", "--depth=1", + "--branch", self.git_ref, + self.git_remote, self.source_dir + ] run_command(command, neutralEnv('source_dir'), context) def _git_update(self, context): - command = "git fetch origin {}".format( - self.git_ref) + command = ["git", "fetch", "origin", self.git_ref] + run_command(command, self.git_path, context) + command = ["git", "checkout", self.git_ref] run_command(command, self.git_path, context) - run_command("git checkout "+self.git_ref, self.git_path, context) def prepare(self): self.command('gitclone', self._git_clone) @@ -178,12 +181,15 @@ class SvnClone(Source): def _svn_checkout(self, context): if os.path.exists(self.svn_path): raise SkipCommand() - command = "svn checkout {} {}".format(self.svn_remote, self.svn_dir) + command = [ + "svn", "checkout", + self.svn_remote, self.svn_dir + ] run_command(command, neutralEnv('source_dir'), context) def _svn_update(self, context): context.try_skip(self.svn_path) - run_command("svn update", self.svn_path, context) + run_command(["svn", "update"], self.svn_path, context) def prepare(self): self.command('svncheckout', self._svn_checkout) @@ -274,35 +280,34 @@ class NoopBuilder(Builder): class MakeBuilder(Builder): - configure_option_template = "{dep_options} {static_option} {env_option} --prefix {install_dir} --libdir {libdir}" - configure_option = "" - dynamic_configure_option = "--enable-shared --disable-static" - static_configure_option = "--enable-static --disable-shared" - make_option = "" - install_option = "" + configure_options = [] + dynamic_configure_options = ["--enable-shared", "--disable-static"] + static_configure_options = ["--enable-static", "--disable-shared"] + make_options = [] + install_options = [] configure_script = "configure" configure_env = None - make_target = "" - make_install_target = "install" + make_targets = [] + make_install_targets = ["install"] @property - def all_configure_option(self): - option = self.configure_option_template.format( - dep_options=self.configure_option, - static_option=self.static_configure_option if self.buildEnv.platformInfo.static else self.dynamic_configure_option, - env_option=self.buildEnv.platformInfo.configure_option if not self.target.force_native_build else "", - install_dir=self.buildEnv.install_dir, - libdir=pj(self.buildEnv.install_dir, self.buildEnv.libprefix) - ) - return option + def all_configure_options(self): + yield from self.configure_options + if self.buildEnv.platformInfo.static: + yield from self.static_configure_options + else: + yield from self.dynamic_configure_options + if not self.target.force_native_build: + yield from self.buildEnv.platformInfo.configure_options + yield from ('--prefix', self.buildEnv.install_dir) + yield from ('--libdir', pj(self.buildEnv.install_dir, self.buildEnv.libprefix)) def _configure(self, context): context.try_skip(self.build_path) - command = "{configure_script} {configure_option}" - command = command.format( - configure_script=pj(self.source_path, self.configure_script), - configure_option=self.all_configure_option - ) + command = [ + pj(self.source_path, self.configure_script), + *self.all_configure_options + ] env = DefaultEnv() if self.buildEnv.platformInfo.static: env['CFLAGS'] = env['CFLAGS'] + ' -fPIC' @@ -317,45 +322,43 @@ class MakeBuilder(Builder): def _compile(self, context): context.try_skip(self.build_path) - command = "make -j4 {make_target} {make_option}".format( - make_target=self.make_target, - make_option=self.make_option - ) + command = [ + "make", "-j4", + *self.make_targets, + *self.make_options + ] run_command(command, self.build_path, context, buildEnv=self.buildEnv) def _install(self, context): context.try_skip(self.build_path) - command = "make {make_install_target} {make_option}".format( - make_install_target=self.make_install_target, - make_option=self.make_option - ) + command = [ + "make", + *self.make_install_targets, + *self.install_options + ] run_command(command, self.build_path, context, buildEnv=self.buildEnv) def _make_dist(self, context): context.try_skip(self.build_path) - command = "make dist" + command = ["make", "dist"] run_command(command, self.build_path, context, buildEnv=self.buildEnv) class CMakeBuilder(MakeBuilder): def _configure(self, context): context.try_skip(self.build_path) - cross_option = "" + cross_options = [] if not self.target.force_native_build and self.buildEnv.cmake_crossfile: - cross_option = "-DCMAKE_TOOLCHAIN_FILE={}".format(self.buildEnv.cmake_crossfile) - command = ("cmake {configure_option}" - " -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON" - " -DCMAKE_INSTALL_PREFIX={install_dir}" - " -DCMAKE_INSTALL_LIBDIR={libdir}" - " {source_path}" - " {cross_option}") - command = command.format( - configure_option=self.configure_option, - install_dir=self.buildEnv.install_dir, - libdir=self.buildEnv.libprefix, - source_path=self.source_path, - cross_option=cross_option - ) + cross_options += ["-DCMAKE_TOOLCHAIN_FILE={}".format(self.buildEnv.cmake_crossfile)] + command = [ + "cmake", + *self.configure_options, + "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON", + "-DCMAKE_INSTALL_PREFIX={}".format(self.buildEnv.install_dir), + "-DCMAKE_INSTALL_LIBDIR={}".format(self.buildEnv.libprefix), + self.source_path, + *cross_options + ] env = DefaultEnv() if self.buildEnv.platformInfo.static: env['CFLAGS'] = env['CFLAGS'] + ' -fPIC' @@ -370,44 +373,36 @@ class CMakeBuilder(MakeBuilder): class QMakeBuilder(MakeBuilder): - qmake_target = "" - @property - def env_option(self): - options = "" + def env_options(self): if 'QMAKE_CC' in os.environ: - options += 'QMAKE_CC={} '.format(os.environ['QMAKE_CC']) + yield 'QMAKE_CC={} '.format(os.environ['QMAKE_CC']) if 'QMAKE_CXX' in os.environ: - options += 'QMAKE_CXX={} '.format(os.environ['QMAKE_CXX']) - return options + yield 'QMAKE_CXX={} '.format(os.environ['QMAKE_CXX']) def _configure(self, context): context.try_skip(self.build_path) - cross_option = "" - command = ("qmake {configure_option}" - " {env_option}" - " {source_path}" - " {cross_option}") - command = command.format( - configure_option=self.configure_option, - env_option=self.env_option, - source_path=self.source_path, - cross_option=cross_option - ) + command = [ + "qmake", + *self.configure_options, + *self.env_options, + self.source_path + ] run_command(command, self.build_path, context, buildEnv=self.buildEnv, cross_env_only=True) def _install(self, context): context.try_skip(self.build_path) - command = "make {make_install_target} {make_option}".format( - make_install_target=self.make_install_target, - make_option=self.make_option - ) + command = [ + "make", + *self.make_install_targets, + *self.install_options + ] run_command(command, self.build_path, context, buildEnv=self.buildEnv) class MesonBuilder(Builder): - configure_option = "" - test_option = "" + configure_options = [] + test_options = [] @property def library_type(self): @@ -418,29 +413,22 @@ class MesonBuilder(Builder): if os.path.exists(self.build_path): shutil.rmtree(self.build_path) os.makedirs(self.build_path) - configure_option = self.configure_option.format(buildEnv=self.buildEnv) - cross_option = "" + cross_options = [] if not self.target.force_native_build and self.buildEnv.meson_crossfile: - cross_option = "--cross-file {}".format( - self.buildEnv.meson_crossfile) - command = ("{command} . {build_path}" - " --default-library={library_type}" - " {configure_option}" - " --prefix={buildEnv.install_dir}" - " --libdir={buildEnv.libprefix}" - " {cross_option}") - command = command.format( - command=neutralEnv('meson_command'), - library_type=self.library_type, - configure_option=configure_option, - build_path=self.build_path, - buildEnv=self.buildEnv, - cross_option=cross_option - ) + cross_options += ["--cross-file", self.buildEnv.meson_crossfile] + command = [ + *neutralEnv('meson_command'), + '.', self.build_path, + '--default-library={}'.format(self.library_type), + *self.configure_options, + '--prefix={}'.format(self.buildEnv.install_dir), + '--libdir={}'.format(self.buildEnv.libprefix), + *cross_options + ] run_command(command, self.source_path, context, buildEnv=self.buildEnv, cross_env_only=True) def _compile(self, context): - command = "{} -v".format(neutralEnv('ninja_command')) + command = [*neutralEnv('ninja_command'), '-v'] run_command(command, self.build_path, context, buildEnv=self.buildEnv) def _test(self, context): @@ -449,21 +437,25 @@ class MesonBuilder(Builder): and not self.buildEnv.platformInfo.static) ): raise SkipCommand() - command = "{} --verbose {}".format(neutralEnv('mesontest_command'), self.test_option) + command = [ + *neutralEnv('mesontest_command'), + '--verbose', + *self.test_options + ] run_command(command, self.build_path, context, buildEnv=self.buildEnv) def _install(self, context): - command = "{} -v install".format(neutralEnv('ninja_command')) + command = [*neutralEnv('ninja_command'), '-v', 'install'] run_command(command, self.build_path, context, buildEnv=self.buildEnv) def _make_dist(self, context): - command = "{} -v dist".format(neutralEnv('ninja_command')) + command = [*neutralEnv('ninja_command'), '-v', 'dist'] run_command(command, self.build_path, context, buildEnv=self.buildEnv) class GradleBuilder(Builder): - gradle_target = "build" - gradle_option = "-i --no-daemon --build-cache" + gradle_targets = ["build"] + gradle_options = ["-i", "--no-daemon", "--build-cache"] def build(self): self.command('configure', self._configure) @@ -479,8 +471,9 @@ class GradleBuilder(Builder): shutil.copytree(self.source_path, self.build_path) def _compile(self, context): - command = "gradle {gradle_target} {gradle_option}" - command = command.format( - gradle_target=self.gradle_target, - gradle_option=self.gradle_option) + command = [ + 'gradle', + *self.gradle_targets, + *self.gradle_options + ] run_command(command, self.build_path, context, buildEnv=self.buildEnv) diff --git a/kiwixbuild/dependencies/ctpp2.py b/kiwixbuild/dependencies/ctpp2.py index 4b05b03..c8c8e47 100644 --- a/kiwixbuild/dependencies/ctpp2.py +++ b/kiwixbuild/dependencies/ctpp2.py @@ -4,6 +4,7 @@ from .base import ( CMakeBuilder) from kiwixbuild.utils import Remotefile, pj, run_command +from glob import glob class CTPP2(Dependency): name = "ctpp2" @@ -25,13 +26,13 @@ class CTPP2(Dependency): class Builder(CMakeBuilder): @property - def configure_option(self): + def configure_options(self): + yield "-DMD5_SUPPORT=OFF" + yield "-DICONV_SUPPORT=OFF" libprefix = self.buildEnv.libprefix - options = "-DMD5_SUPPORT=OFF -DICONV_SUPPORT=OFF" if libprefix.startswith('lib'): libprefix = libprefix[3:] - options += " -DLIB_SUFFIX={}".format(libprefix) - return options + yield "-DLIB_SUFFIX={}".format(libprefix) class CTPP2C(CTPP2): @@ -39,7 +40,7 @@ class CTPP2C(CTPP2): force_native_build = True class Builder(CTPP2.Builder): - make_target = "ctpp2c" + make_targets = ["ctpp2c"] @property def build_path(self): @@ -47,8 +48,9 @@ class CTPP2C(CTPP2): def _install(self, context): context.try_skip(self.build_path) - command = "cp {ctpp2c}* {install_dir}".format( - ctpp2c=pj(self.build_path, 'ctpp2c'), - install_dir=pj(self.buildEnv.install_dir, 'bin') + command = ( + 'cp', + *glob(pj(self.build_path, 'ctpp2c*')), + pj(self.buildEnv.install_dir, 'bin') ) run_command(command, self.build_path, context, buildEnv=self.buildEnv) diff --git a/kiwixbuild/dependencies/gumbo.py b/kiwixbuild/dependencies/gumbo.py index 078f0fd..23693c3 100644 --- a/kiwixbuild/dependencies/gumbo.py +++ b/kiwixbuild/dependencies/gumbo.py @@ -17,7 +17,7 @@ class Gumbo(Dependency): def _post_prepare_script(self, context): context.try_skip(self.extract_path) - command = "./autogen.sh" + command = ["./autogen.sh"] run_command(command, self.extract_path, context) Builder = MakeBuilder diff --git a/kiwixbuild/dependencies/icu4c.py b/kiwixbuild/dependencies/icu4c.py index cc1587a..1f8d88c 100644 --- a/kiwixbuild/dependencies/icu4c.py +++ b/kiwixbuild/dependencies/icu4c.py @@ -32,17 +32,20 @@ class Icu(Dependency): return [(plt, 'icu4c')] @property - def configure_option(self): - options = ("--disable-samples --disable-tests --disable-extras " - "--disable-dyload --enable-rpath " - "--disable-icuio --disable-layoutex") + def configure_options(self): + yield "--disable-samples" + yield "--disable-tests" + yield "--disable-extras" + yield "--disable-dyload" + yield "--enable-rpath" + yield "--disable-icuio" + yield "--disable-layoutex" platformInfo = self.buildEnv.platformInfo if platformInfo.build != 'native': icu_native_builder = get_target_step( 'icu4c', 'native_static' if platformInfo.static else 'native_dyn') - options += " --with-cross-build={} --disable-tools".format( - icu_native_builder.build_path) + yield "--with-cross-build={}".format(icu_native_builder.build_path) + yield "--disable-tools" if platformInfo.build == 'android': - options += " --with-data-packaging=archive" - return options + yield "--with-data-packaging=archive" diff --git a/kiwixbuild/dependencies/ios_fat_lib.py b/kiwixbuild/dependencies/ios_fat_lib.py index fddf107..27e6cfe 100644 --- a/kiwixbuild/dependencies/ios_fat_lib.py +++ b/kiwixbuild/dependencies/ios_fat_lib.py @@ -40,11 +40,12 @@ class IOSFatLib(Dependency): if f.endswith('.a') or f.endswith('.dylib'): libs.append(f) os.makedirs(pj(self.buildEnv.install_dir, 'lib'), exist_ok=True) - command_tmp = "lipo -create {input} -output {output}" for l in libs: - command = command_tmp.format( - input=" ".join(pj(d, l) for d in lib_dirs), - output=pj(self.buildEnv.install_dir, 'lib', l)) + command = [ + 'lipo', + '-create', *[pj(d, l) for d in lib_dirs], + '-output', pj(self.buildEnv.install_dir, 'lib', l) + ] run_command(command, self.buildEnv.install_dir, context) def build(self): diff --git a/kiwixbuild/dependencies/kiwix_custom_app.py b/kiwixbuild/dependencies/kiwix_custom_app.py index 9422301..d75157c 100644 --- a/kiwixbuild/dependencies/kiwix_custom_app.py +++ b/kiwixbuild/dependencies/kiwix_custom_app.py @@ -6,7 +6,7 @@ from .base import ( GitClone, GradleBuilder) -from kiwixbuild.utils import Remotefile, pj, SkipCommand +from kiwixbuild.utils import Remotefile, pj, SkipCommand, run_command from kiwixbuild._global import option, get_target_step class KiwixCustomApp(Dependency): @@ -24,22 +24,22 @@ class KiwixCustomApp(Dependency): dependencies = ["kiwix-android", "kiwix-lib"] @property - def gradle_target(self): - return "assemble{}".format(self.target.custom_name) + def gradle_targets(self): + yield "assemble{}".format(self.target.custom_name) @property - def gradle_option(self): - template = ("-i -P customDir={customDir}" - " -P zim_file_size={zim_size}" - " -P version_code={version_code}" - " -P version_name={version_name}" - " -P content_version_code={content_version_code}") - return template.format( - customDir=pj(self.build_path, 'custom'), - zim_size=self._get_zim_size(), - version_code=os.environ['VERSION_CODE'], - version_name=os.environ['VERSION_NAME'], - content_version_code=os.environ['CONTENT_VERSION_CODE']) + def gradle_options(self): + yield "-i" + yield "-P" + yield "customDir={}".format(pj(self.build_path, 'custom')) + yield "-P" + yield "zim_file_size={}".format(zim_size) + yield "-P" + yield "version_code={}".format(os.environ['VERSION_CODE']) + yield "-P" + yield "version_name={}".format(os.environ['VERSION_NAME']) + yield "-P" + yield "content_version_code={}".format(os.environ['CONTENT_VERSION_CODE']) @property def build_path(self): @@ -104,9 +104,10 @@ class KiwixCustomApp(Dependency): except FileNotFoundError: pass os.makedirs(pj(self.build_path, 'custom')) - command = "./gen-custom-android-directory.py {custom_name} --output-dir {custom_dir}" - command = command.format( - custom_name=self.target.custom_name, - custom_dir=pj(self.build_path, 'custom', self.target.custom_name) - ) - self.buildEnv.run_command(command, self.source_path, context) + command = [ + "./gen-custom-android-directory.py", + self.target.custom_name, + "--output-dir", + pj(self.build_path, 'custom', self.target.custom_name) + ] + run_command(command, self.source_path, context, buildEnv=self.buildEnv) diff --git a/kiwixbuild/dependencies/kiwix_desktop.py b/kiwixbuild/dependencies/kiwix_desktop.py index 66e810a..1ce1b2b 100644 --- a/kiwixbuild/dependencies/kiwix_desktop.py +++ b/kiwixbuild/dependencies/kiwix_desktop.py @@ -13,8 +13,7 @@ class KiwixDesktop(Dependency): class Builder(QMakeBuilder): dependencies = ["qt", "qtwebengine", "kiwix-lib"] @property - def configure_option(self): - options = ["PREFIX={}".format(self.buildEnv.install_dir)] + def configure_options(self): + yield "PREFIX={}".format(self.buildEnv.install_dir) if self.buildEnv.platformInfo.static: - options.append('"CONFIG+=static"') - return " ".join(options) + yield 'CONFIG+=static' diff --git a/kiwixbuild/dependencies/kiwix_lib.py b/kiwixbuild/dependencies/kiwix_lib.py index a72e5fe..b187d28 100644 --- a/kiwixbuild/dependencies/kiwix_lib.py +++ b/kiwixbuild/dependencies/kiwix_lib.py @@ -22,11 +22,10 @@ class Kiwixlib(Dependency): @property - def configure_option(self): - base_option = "-Dctpp2-install-prefix={buildEnv.install_dir}" + def configure_options(self): + yield "-Dctpp2-install-prefix={}".format(self.buildEnv.install_dir) if self.buildEnv.platformInfo.build == 'android': - base_option += ' -Dandroid=true' - return base_option + yield '-Dandroid=true' @property def library_type(self): diff --git a/kiwixbuild/dependencies/kiwix_tools.py b/kiwixbuild/dependencies/kiwix_tools.py index cfdce90..82c82bf 100644 --- a/kiwixbuild/dependencies/kiwix_tools.py +++ b/kiwixbuild/dependencies/kiwix_tools.py @@ -14,7 +14,6 @@ class KiwixTools(Dependency): dependencies = ["kiwix-lib", "libmicrohttpd", "zlib"] @property - def configure_option(self): + def configure_options(self): if self.buildEnv.platformInfo.static: - return "-Dstatic-linkage=true" - return "" + yield "-Dstatic-linkage=true" diff --git a/kiwixbuild/dependencies/libaria2.py b/kiwixbuild/dependencies/libaria2.py index e0a5d38..48aebc6 100644 --- a/kiwixbuild/dependencies/libaria2.py +++ b/kiwixbuild/dependencies/libaria2.py @@ -18,9 +18,9 @@ class Aria2(Dependency): def _post_prepare_script(self, context): context.try_skip(self.extract_path) - command = "autoreconf -i" + command = ["autoreconf", "-i"] 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" + configure_options = ["--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 e2f8d6e..175b8aa 100644 --- a/kiwixbuild/dependencies/libmagic.py +++ b/kiwixbuild/dependencies/libmagic.py @@ -32,10 +32,12 @@ class LibMagic(Dependency): if platformInfo.build == 'native': return super()._compile(context) context.try_skip(self.build_path) - command = "make -j4 {make_target} {make_option}".format( - make_target=self.make_target, - make_option=self.make_option - ) + command = [ + "make", + "-j4", + *self.make_targets, + *self.make_options + ] libmagic_native_builder = get_target_step('libmagic', 'native_static') env = DefaultEnv() env['PATH'] = ':'.join([pj(libmagic_native_builder.build_path, 'src'), env['PATH']]) diff --git a/kiwixbuild/dependencies/libmicrohttpd.py b/kiwixbuild/dependencies/libmicrohttpd.py index 27f6522..116e629 100644 --- a/kiwixbuild/dependencies/libmicrohttpd.py +++ b/kiwixbuild/dependencies/libmicrohttpd.py @@ -14,4 +14,4 @@ class MicroHttpd(Dependency): 'http://ftp.gnu.org/gnu/libmicrohttpd/libmicrohttpd-0.9.46.tar.gz') class Builder(MakeBuilder): - configure_option = "--disable-https --without-libgcrypt --without-libcurl" + configure_options = ["--disable-https", "--without-libgcrypt", "--without-libcurl"] diff --git a/kiwixbuild/dependencies/libzim.py b/kiwixbuild/dependencies/libzim.py index aa01108..7023cad 100644 --- a/kiwixbuild/dependencies/libzim.py +++ b/kiwixbuild/dependencies/libzim.py @@ -11,5 +11,5 @@ class Libzim(Dependency): git_dir = "libzim" class Builder(MesonBuilder): - test_option = "-t 8" + test_options = ["-t", "8"] dependencies = ['zlib', 'lzma', 'xapian-core', 'icu4c'] diff --git a/kiwixbuild/dependencies/lzma.py b/kiwixbuild/dependencies/lzma.py index 285086e..b1009a3 100644 --- a/kiwixbuild/dependencies/lzma.py +++ b/kiwixbuild/dependencies/lzma.py @@ -14,6 +14,4 @@ class lzma(Dependency): 'https://tukaani.org/xz/xz-5.2.3.tar.bz2') class Builder(MakeBuilder): - @property - def configure_option(self): - return "--disable-assembler --disable-xz --disable-xzdec" + configure_options = ["--disable-assembler", "--disable-xz", "--disable-xzdec"] diff --git a/kiwixbuild/dependencies/qt.py b/kiwixbuild/dependencies/qt.py index d6f0883..f79b99a 100644 --- a/kiwixbuild/dependencies/qt.py +++ b/kiwixbuild/dependencies/qt.py @@ -21,12 +21,23 @@ class Qt(Dependency): class Builder(MakeBuilder): dependencies = ['icu4c', 'zlib'] - configure_option_template = "{dep_options} {static_option} {env_option} -prefix {install_dir} -libdir {libdir}" - dynamic_configure_option = "-shared" - static_configure_option = "-static" + dynamic_configure_options = ["-shared"] + static_configure_options = ["-static"] @property - def configure_option(self): + def all_configure_option(self): + yield from self.configure_options + if self.buildEnv.platformInfo.static: + yield from self.static_configure_options + else: + yield from self.dynamic_configure_options + if not self.target.force_native_build: + yield from self.buildEnv.platformInfo.configure_options + yield from ('-prefix', self.buildEnv.install_dir) + yield from ('-libdir', pj(self.buildEnv.install_dir, self.buildEnv.libprefix)) + + @property + def configure_options(self): skip_modules = [ 'qt3d', 'qtcanvas3d', @@ -55,10 +66,15 @@ class Qt(Dependency): 'qtwebglplugin', 'qtwebsockets', # 'qtwebview', -] - skip_modules = " ".join("-skip {}".format(m) for m in skip_modules) - options = "-recheck -opensource -confirm-license -ccache -make libs {}".format(skip_modules) - return options + ] + yield '-recheck' + yield '-opensource' + yield '-confirm-license' + yield '-ccache' + yield from ('-make', 'libs') + for module in skip_modules: + yield from ('-skip', module) + class QtWebEngine(Dependency): name = "qtwebengine" diff --git a/kiwixbuild/dependencies/uuid.py b/kiwixbuild/dependencies/uuid.py index df3c330..a873917 100644 --- a/kiwixbuild/dependencies/uuid.py +++ b/kiwixbuild/dependencies/uuid.py @@ -17,9 +17,14 @@ class UUID(Dependency): extract_dir = 'e2fsprogs-libs-1.43.4' class Builder(MakeBuilder): - configure_option = ("--enable-libuuid --disable-debugfs --disable-imager --disable-resizer --disable-defrag --enable-fsck" - " --disable-uuidd") + configure_options = ["--enable-libuuid", + "--disable-debugfs", + "--disable-imager", + "--disable-resizer", + "--disable-defrag", + "--enable-fsck", + "--disable-uuidd"] configure_env = {'_format_CFLAGS': "{env.CFLAGS} -fPIC"} - static_configure_option = dynamic_configure_option = "" - make_target = 'libs' - make_install_target = 'install-libs' + static_configure_options = dynamic_configure_options = [] + make_targets = ['libs'] + make_install_targets = ['install-libs'] diff --git a/kiwixbuild/dependencies/xapian.py b/kiwixbuild/dependencies/xapian.py index d3c6a4f..a76376a 100644 --- a/kiwixbuild/dependencies/xapian.py +++ b/kiwixbuild/dependencies/xapian.py @@ -17,7 +17,7 @@ class Xapian(Dependency): patches = ['xapian_sys_types.patch'] class Builder(MakeBuilder): - configure_option = "--disable-sse --disable-backend-inmemory --disable-documentation" + configure_options = ["--disable-sse", "--disable-backend-inmemory", "--disable-documentation"] configure_env = {'_format_LDFLAGS': "-L{buildEnv.install_dir}/{buildEnv.libprefix}", '_format_CXXFLAGS': "-I{buildEnv.install_dir}/include"} diff --git a/kiwixbuild/dependencies/zim_tools.py b/kiwixbuild/dependencies/zim_tools.py index 46332e0..6bcf1b4 100644 --- a/kiwixbuild/dependencies/zim_tools.py +++ b/kiwixbuild/dependencies/zim_tools.py @@ -14,7 +14,6 @@ class ZimTools(Dependency): dependencies = ['libzim'] @property - def configure_option(self): + def configure_options(self): if self.buildEnv.platformInfo.static: - return "-Dstatic-linkage=true" - return "" + yield "-Dstatic-linkage=true" diff --git a/kiwixbuild/dependencies/zimwriterfs.py b/kiwixbuild/dependencies/zimwriterfs.py index 55f73a5..db3b5b4 100644 --- a/kiwixbuild/dependencies/zimwriterfs.py +++ b/kiwixbuild/dependencies/zimwriterfs.py @@ -14,8 +14,7 @@ class Zimwriterfs(Dependency): dependencies = ['libzim', 'zlib', 'xapian-core', 'gumbo', 'icu4c', 'libmagic'] @property - def configure_option(self): - base_option = "-Dmagic-install-prefix={buildEnv.install_dir}" + def configure_options(self): + yield "-Dmagic-install-prefix={}".format(self.buildEnv.install_dir) if self.buildEnv.platformInfo.static: - base_option += " -Dstatic-linkage=true" - return base_option + yield "-Dstatic-linkage=true" diff --git a/kiwixbuild/dependencies/zlib.py b/kiwixbuild/dependencies/zlib.py index babc294..cf6c546 100644 --- a/kiwixbuild/dependencies/zlib.py +++ b/kiwixbuild/dependencies/zlib.py @@ -18,9 +18,8 @@ class zlib(Dependency): patches = ['zlib_std_libname.patch'] class Builder(MakeBuilder): - dynamic_configure_option = "--shared" - static_configure_option = "--static" - configure_option_template = "{dep_options} {static_option} --prefix {install_dir} --libdir {libdir}" + dynamic_configure_options = ["--shared"] + static_configure_options = ["--static"] def _pre_build_script(self, context): context.try_skip(self.build_path) @@ -33,13 +32,20 @@ class zlib(Dependency): return super()._configure(context) @property - def make_option(self): + def all_configure_options(self): + yield from self.configure_options + yield from self.static_configure_options if self.buildEnv.platformInfo.static else self.dynamic_configure_options + yield from ('--prefix', self.buildEnv.install_dir) + yield from ('--libdir', pj(self.buildEnv.install_dir, self.buildEnv.libprefix)) + + @property + def make_options(self): if self.buildEnv.platformInfo.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( - host='i686-w64-mingw32', - static="0" if self.buildEnv.platformInfo.static else "1", - include_path=pj(self.buildEnv.install_dir, 'include'), - library_path=pj(self.buildEnv.install_dir, self.buildEnv.libprefix), - binary_path=pj(self.buildEnv.install_dir, 'bin'), - ) - return "" + return + yield "--makefile" + yield "{}/Makefile.gcc".format(self.buildEnv.platformInfo.build) + yield "PREFIX={}-".format(self.buildEnv.platformInfo.arch_full) + yield "SHARED_MODE={}".format("0" if self.buildEnv.platformInfo.static else "1") + yield "INCLUDE_PATH={}".format(pj(self.buildEnv.install_dir, 'include')) + yield "LIBRARY_PATH={}".format(pj(self.buildEnv.install_dir, self.buildEnv.libprefix)) + yield "BINARY_PATH={}".format(pj(self.buildEnv.install_dir, 'bin')) diff --git a/kiwixbuild/platforms/android.py b/kiwixbuild/platforms/android.py index 91369e4..5827582 100644 --- a/kiwixbuild/platforms/android.py +++ b/kiwixbuild/platforms/android.py @@ -85,8 +85,8 @@ class AndroidPlatformInfo(PlatformInfo): env['CXX'] = binaries['CXX'] @property - def configure_option(self): - return '--host={}'.format(self.arch_full) + def configure_options(self): + yield '--host={}'.format(self.arch_full) def finalize_setup(self): super().finalize_setup() diff --git a/kiwixbuild/platforms/armhf.py b/kiwixbuild/platforms/armhf.py index 354af4b..a1c54b1 100644 --- a/kiwixbuild/platforms/armhf.py +++ b/kiwixbuild/platforms/armhf.py @@ -61,8 +61,8 @@ class ArmhfPlatformInfo(PlatformInfo): return "exec_wrapper = 'qemu-arm'" @property - def configure_option(self): - return '--host={}'.format(self.arch_full) + def configure_options(self): + yield '--host={}'.format(self.arch_full) def get_bin_dir(self): return [pj(self.root_path, 'bin')] diff --git a/kiwixbuild/platforms/base.py b/kiwixbuild/platforms/base.py index 4252195..9f45734 100644 --- a/kiwixbuild/platforms/base.py +++ b/kiwixbuild/platforms/base.py @@ -23,7 +23,7 @@ class PlatformInfo(metaclass=_MetaPlatform): all_platforms = {} all_running_platforms = {} toolchain_names = [] - configure_option = "" + configure_options = [] @classmethod def get_platform(cls, name, targets=None): diff --git a/kiwixbuild/platforms/i586.py b/kiwixbuild/platforms/i586.py index b52dd9e..0e38de7 100644 --- a/kiwixbuild/platforms/i586.py +++ b/kiwixbuild/platforms/i586.py @@ -26,8 +26,8 @@ class I586PlatformInfo(PlatformInfo): } @property - def configure_option(self): - return '--host={}'.format(self.arch_full) + def configure_options(self): + yield '--host={}'.format(self.arch_full) @property def binaries(self): diff --git a/kiwixbuild/platforms/ios.py b/kiwixbuild/platforms/ios.py index 8c2a793..06ae1cd 100644 --- a/kiwixbuild/platforms/ios.py +++ b/kiwixbuild/platforms/ios.py @@ -76,8 +76,8 @@ class iOSPlatformInfo(PlatformInfo): } @property - def configure_option(self): - return '--host={}'.format(self.arch_full) + def configure_options(self): + yield '--host={}'.format(self.arch_full) def set_compiler(self, env): env['CC'] = self.binaries['CC'] diff --git a/kiwixbuild/platforms/win32.py b/kiwixbuild/platforms/win32.py index 81ec903..5204b9c 100644 --- a/kiwixbuild/platforms/win32.py +++ b/kiwixbuild/platforms/win32.py @@ -62,8 +62,8 @@ class Win32PlatformInfo(PlatformInfo): return "exec_wrapper = 'wine'" @property - def configure_option(self): - return '--host={}'.format(self.arch_full) + def configure_options(self): + yield '--host={}'.format(self.arch_full) def set_compiler(self, env): for k, v in self.binaries.items(): diff --git a/kiwixbuild/utils.py b/kiwixbuild/utils.py index eee0bab..e49bd16 100644 --- a/kiwixbuild/utils.py +++ b/kiwixbuild/utils.py @@ -263,7 +263,7 @@ def run_command(command, cwd, context, buildEnv=None, env=None, input=None, cros kwargs = dict() if input: kwargs['stdin'] = subprocess.PIPE - process = subprocess.Popen(command, shell=True, cwd=cwd, env=env, stdout=log or sys.stdout, stderr=subprocess.STDOUT, **kwargs) + process = subprocess.Popen(command, cwd=cwd, env=env, stdout=log or sys.stdout, stderr=subprocess.STDOUT, **kwargs) if input: process.communicate(input.encode()) retcode = process.wait()