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).
This commit is contained in:
Matthieu Gautier 2018-06-19 11:27:07 +02:00
parent 8c5809c4d7
commit 781f6740f2
30 changed files with 252 additions and 230 deletions

View File

@ -26,7 +26,7 @@ class PlatformNeutralEnv:
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.mesontest_command = "{} test".format(self.meson_command) self.mesontest_command = [*self.meson_command, "test"]
def detect_platform(self): def detect_platform(self):
_platform = platform.system() _platform = platform.system()
@ -56,7 +56,7 @@ class PlatformNeutralEnv:
# Doesn't exist in PATH or isn't executable # Doesn't exist in PATH or isn't executable
continue continue
if retcode == 0: if retcode == 0:
return n return [n]
def _detect_meson(self): def _detect_meson(self):
for n in ['meson.py', 'meson']: for n in ['meson.py', 'meson']:
@ -67,7 +67,7 @@ class PlatformNeutralEnv:
# Doesn't exist in PATH or isn't executable # Doesn't exist in PATH or isn't executable
continue continue
if retcode == 0: if retcode == 0:
return n return [n]
class BuildEnv: class BuildEnv:

View File

@ -45,13 +45,13 @@ class android_ndk(Dependency):
context.try_skip(self.build_path) context.try_skip(self.build_path)
script = pj(self.source_path, 'build/tools/make_standalone_toolchain.py') script = pj(self.source_path, 'build/tools/make_standalone_toolchain.py')
add_execution_right(script) add_execution_right(script)
command = '{script} --arch={arch} --api={api} --install-dir={install_dir} --force' command = [
command = command.format( script,
script=script, '--arch={}'.format(self.arch),
arch=self.arch, '--api={}'.format(api),
api=self.api, '--install-dir', self.install_path,
install_dir=self.install_path '--force'
) ]
context.force_native_build = True context.force_native_build = True
run_command(command, self.build_path, context, buildEnv=self.buildEnv) run_command(command, self.build_path, context, buildEnv=self.buildEnv)

View File

@ -26,11 +26,11 @@ class android_sdk(Dependency):
tools_dir = pj(self.install_path, 'tools') tools_dir = pj(self.install_path, 'tools')
shutil.copytree(self.source_path, tools_dir) shutil.copytree(self.source_path, tools_dir)
script = pj(tools_dir, 'android') script = pj(tools_dir, 'android')
command = '{script} --verbose update sdk -a --no-ui --filter {packages}' command = [
command = command.format( script,
script=script, '--verbose', 'update', 'sdk', '-a', '--no-ui',
packages = ','.join(str(i) for i in [1,2,8,34,162]) '--filter', ','.join(str(i) for i in [1,2,8,34,162])
) ]
# packages correspond to : # packages correspond to :
# - 1 : Android SDK Tools, revision 25.2.5 # - 1 : Android SDK Tools, revision 25.2.5
# - 2 : Android SDK Platform-tools, revision 25.0.3 # - 2 : Android SDK Platform-tools, revision 25.0.3

View File

@ -61,7 +61,7 @@ class Source:
context.force_native_build = True context.force_native_build = True
for p in self.patches: for p in self.patches:
with open(pj(SCRIPT_DIR, 'patches', p), 'r') as patch_input: 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): def command(self, name, function, *args):
print(" {} {} : ".format(name, self.name), end="", flush=True) print(" {} {} : ".format(name, self.name), end="", flush=True)
@ -149,15 +149,18 @@ class GitClone(Source):
def _git_clone(self, context): def _git_clone(self, context):
if os.path.exists(self.git_path): if os.path.exists(self.git_path):
raise SkipCommand() raise SkipCommand()
command = "git clone --depth=1 --branch {} {} {}".format( command = [
self.git_ref, self.git_remote, self.source_dir) "git", "clone", "--depth=1",
"--branch", self.git_ref,
self.git_remote, self.source_dir
]
run_command(command, neutralEnv('source_dir'), context) run_command(command, neutralEnv('source_dir'), context)
def _git_update(self, context): def _git_update(self, context):
command = "git fetch origin {}".format( command = ["git", "fetch", "origin", self.git_ref]
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(command, self.git_path, context)
run_command("git checkout "+self.git_ref, self.git_path, context)
def prepare(self): def prepare(self):
self.command('gitclone', self._git_clone) self.command('gitclone', self._git_clone)
@ -178,12 +181,15 @@ class SvnClone(Source):
def _svn_checkout(self, context): def _svn_checkout(self, context):
if os.path.exists(self.svn_path): if os.path.exists(self.svn_path):
raise SkipCommand() 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) run_command(command, neutralEnv('source_dir'), context)
def _svn_update(self, context): def _svn_update(self, context):
context.try_skip(self.svn_path) 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): def prepare(self):
self.command('svncheckout', self._svn_checkout) self.command('svncheckout', self._svn_checkout)
@ -274,35 +280,34 @@ class NoopBuilder(Builder):
class MakeBuilder(Builder): class MakeBuilder(Builder):
configure_option_template = "{dep_options} {static_option} {env_option} --prefix {install_dir} --libdir {libdir}" configure_options = []
configure_option = "" dynamic_configure_options = ["--enable-shared", "--disable-static"]
dynamic_configure_option = "--enable-shared --disable-static" static_configure_options = ["--enable-static", "--disable-shared"]
static_configure_option = "--enable-static --disable-shared" make_options = []
make_option = "" install_options = []
install_option = ""
configure_script = "configure" configure_script = "configure"
configure_env = None configure_env = None
make_target = "" make_targets = []
make_install_target = "install" make_install_targets = ["install"]
@property @property
def all_configure_option(self): def all_configure_options(self):
option = self.configure_option_template.format( yield from self.configure_options
dep_options=self.configure_option, if self.buildEnv.platformInfo.static:
static_option=self.static_configure_option if self.buildEnv.platformInfo.static else self.dynamic_configure_option, yield from self.static_configure_options
env_option=self.buildEnv.platformInfo.configure_option if not self.target.force_native_build else "", else:
install_dir=self.buildEnv.install_dir, yield from self.dynamic_configure_options
libdir=pj(self.buildEnv.install_dir, self.buildEnv.libprefix) if not self.target.force_native_build:
) yield from self.buildEnv.platformInfo.configure_options
return option yield from ('--prefix', self.buildEnv.install_dir)
yield from ('--libdir', pj(self.buildEnv.install_dir, self.buildEnv.libprefix))
def _configure(self, context): def _configure(self, context):
context.try_skip(self.build_path) context.try_skip(self.build_path)
command = "{configure_script} {configure_option}" command = [
command = command.format( pj(self.source_path, self.configure_script),
configure_script=pj(self.source_path, self.configure_script), *self.all_configure_options
configure_option=self.all_configure_option ]
)
env = DefaultEnv() env = DefaultEnv()
if self.buildEnv.platformInfo.static: if self.buildEnv.platformInfo.static:
env['CFLAGS'] = env['CFLAGS'] + ' -fPIC' env['CFLAGS'] = env['CFLAGS'] + ' -fPIC'
@ -317,45 +322,43 @@ class MakeBuilder(Builder):
def _compile(self, context): def _compile(self, context):
context.try_skip(self.build_path) context.try_skip(self.build_path)
command = "make -j4 {make_target} {make_option}".format( command = [
make_target=self.make_target, "make", "-j4",
make_option=self.make_option *self.make_targets,
) *self.make_options
]
run_command(command, self.build_path, context, buildEnv=self.buildEnv) run_command(command, self.build_path, context, buildEnv=self.buildEnv)
def _install(self, context): def _install(self, context):
context.try_skip(self.build_path) context.try_skip(self.build_path)
command = "make {make_install_target} {make_option}".format( command = [
make_install_target=self.make_install_target, "make",
make_option=self.make_option *self.make_install_targets,
) *self.install_options
]
run_command(command, self.build_path, context, buildEnv=self.buildEnv) run_command(command, self.build_path, context, buildEnv=self.buildEnv)
def _make_dist(self, context): def _make_dist(self, context):
context.try_skip(self.build_path) context.try_skip(self.build_path)
command = "make dist" command = ["make", "dist"]
run_command(command, self.build_path, context, buildEnv=self.buildEnv) run_command(command, self.build_path, context, buildEnv=self.buildEnv)
class CMakeBuilder(MakeBuilder): class CMakeBuilder(MakeBuilder):
def _configure(self, context): def _configure(self, context):
context.try_skip(self.build_path) context.try_skip(self.build_path)
cross_option = "" cross_options = []
if not self.target.force_native_build and self.buildEnv.cmake_crossfile: if not self.target.force_native_build and self.buildEnv.cmake_crossfile:
cross_option = "-DCMAKE_TOOLCHAIN_FILE={}".format(self.buildEnv.cmake_crossfile) cross_options += ["-DCMAKE_TOOLCHAIN_FILE={}".format(self.buildEnv.cmake_crossfile)]
command = ("cmake {configure_option}" command = [
" -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON" "cmake",
" -DCMAKE_INSTALL_PREFIX={install_dir}" *self.configure_options,
" -DCMAKE_INSTALL_LIBDIR={libdir}" "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON",
" {source_path}" "-DCMAKE_INSTALL_PREFIX={}".format(self.buildEnv.install_dir),
" {cross_option}") "-DCMAKE_INSTALL_LIBDIR={}".format(self.buildEnv.libprefix),
command = command.format( self.source_path,
configure_option=self.configure_option, *cross_options
install_dir=self.buildEnv.install_dir, ]
libdir=self.buildEnv.libprefix,
source_path=self.source_path,
cross_option=cross_option
)
env = DefaultEnv() env = DefaultEnv()
if self.buildEnv.platformInfo.static: if self.buildEnv.platformInfo.static:
env['CFLAGS'] = env['CFLAGS'] + ' -fPIC' env['CFLAGS'] = env['CFLAGS'] + ' -fPIC'
@ -370,44 +373,36 @@ class CMakeBuilder(MakeBuilder):
class QMakeBuilder(MakeBuilder): class QMakeBuilder(MakeBuilder):
qmake_target = ""
@property @property
def env_option(self): def env_options(self):
options = ""
if 'QMAKE_CC' in os.environ: 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: if 'QMAKE_CXX' in os.environ:
options += 'QMAKE_CXX={} '.format(os.environ['QMAKE_CXX']) yield 'QMAKE_CXX={} '.format(os.environ['QMAKE_CXX'])
return options
def _configure(self, context): def _configure(self, context):
context.try_skip(self.build_path) context.try_skip(self.build_path)
cross_option = "" command = [
command = ("qmake {configure_option}" "qmake",
" {env_option}" *self.configure_options,
" {source_path}" *self.env_options,
" {cross_option}") self.source_path
command = command.format( ]
configure_option=self.configure_option,
env_option=self.env_option,
source_path=self.source_path,
cross_option=cross_option
)
run_command(command, self.build_path, context, buildEnv=self.buildEnv, cross_env_only=True) run_command(command, self.build_path, context, buildEnv=self.buildEnv, cross_env_only=True)
def _install(self, context): def _install(self, context):
context.try_skip(self.build_path) context.try_skip(self.build_path)
command = "make {make_install_target} {make_option}".format( command = [
make_install_target=self.make_install_target, "make",
make_option=self.make_option *self.make_install_targets,
) *self.install_options
]
run_command(command, self.build_path, context, buildEnv=self.buildEnv) run_command(command, self.build_path, context, buildEnv=self.buildEnv)
class MesonBuilder(Builder): class MesonBuilder(Builder):
configure_option = "" configure_options = []
test_option = "" test_options = []
@property @property
def library_type(self): def library_type(self):
@ -418,29 +413,22 @@ class MesonBuilder(Builder):
if os.path.exists(self.build_path): if os.path.exists(self.build_path):
shutil.rmtree(self.build_path) shutil.rmtree(self.build_path)
os.makedirs(self.build_path) os.makedirs(self.build_path)
configure_option = self.configure_option.format(buildEnv=self.buildEnv) cross_options = []
cross_option = ""
if not self.target.force_native_build and self.buildEnv.meson_crossfile: if not self.target.force_native_build and self.buildEnv.meson_crossfile:
cross_option = "--cross-file {}".format( cross_options += ["--cross-file", self.buildEnv.meson_crossfile]
self.buildEnv.meson_crossfile) command = [
command = ("{command} . {build_path}" *neutralEnv('meson_command'),
" --default-library={library_type}" '.', self.build_path,
" {configure_option}" '--default-library={}'.format(self.library_type),
" --prefix={buildEnv.install_dir}" *self.configure_options,
" --libdir={buildEnv.libprefix}" '--prefix={}'.format(self.buildEnv.install_dir),
" {cross_option}") '--libdir={}'.format(self.buildEnv.libprefix),
command = command.format( *cross_options
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
)
run_command(command, self.source_path, context, buildEnv=self.buildEnv, cross_env_only=True) run_command(command, self.source_path, context, buildEnv=self.buildEnv, cross_env_only=True)
def _compile(self, context): 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) run_command(command, self.build_path, context, buildEnv=self.buildEnv)
def _test(self, context): def _test(self, context):
@ -449,21 +437,25 @@ class MesonBuilder(Builder):
and not self.buildEnv.platformInfo.static) and not self.buildEnv.platformInfo.static)
): ):
raise SkipCommand() 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) run_command(command, self.build_path, context, buildEnv=self.buildEnv)
def _install(self, context): 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) run_command(command, self.build_path, context, buildEnv=self.buildEnv)
def _make_dist(self, context): 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) run_command(command, self.build_path, context, buildEnv=self.buildEnv)
class GradleBuilder(Builder): class GradleBuilder(Builder):
gradle_target = "build" gradle_targets = ["build"]
gradle_option = "-i --no-daemon --build-cache" gradle_options = ["-i", "--no-daemon", "--build-cache"]
def build(self): def build(self):
self.command('configure', self._configure) self.command('configure', self._configure)
@ -479,8 +471,9 @@ class GradleBuilder(Builder):
shutil.copytree(self.source_path, self.build_path) shutil.copytree(self.source_path, self.build_path)
def _compile(self, context): def _compile(self, context):
command = "gradle {gradle_target} {gradle_option}" command = [
command = command.format( 'gradle',
gradle_target=self.gradle_target, *self.gradle_targets,
gradle_option=self.gradle_option) *self.gradle_options
]
run_command(command, self.build_path, context, buildEnv=self.buildEnv) run_command(command, self.build_path, context, buildEnv=self.buildEnv)

View File

@ -4,6 +4,7 @@ from .base import (
CMakeBuilder) CMakeBuilder)
from kiwixbuild.utils import Remotefile, pj, run_command from kiwixbuild.utils import Remotefile, pj, run_command
from glob import glob
class CTPP2(Dependency): class CTPP2(Dependency):
name = "ctpp2" name = "ctpp2"
@ -25,13 +26,13 @@ class CTPP2(Dependency):
class Builder(CMakeBuilder): class Builder(CMakeBuilder):
@property @property
def configure_option(self): def configure_options(self):
yield "-DMD5_SUPPORT=OFF"
yield "-DICONV_SUPPORT=OFF"
libprefix = self.buildEnv.libprefix libprefix = self.buildEnv.libprefix
options = "-DMD5_SUPPORT=OFF -DICONV_SUPPORT=OFF"
if libprefix.startswith('lib'): if libprefix.startswith('lib'):
libprefix = libprefix[3:] libprefix = libprefix[3:]
options += " -DLIB_SUFFIX={}".format(libprefix) yield "-DLIB_SUFFIX={}".format(libprefix)
return options
class CTPP2C(CTPP2): class CTPP2C(CTPP2):
@ -39,7 +40,7 @@ class CTPP2C(CTPP2):
force_native_build = True force_native_build = True
class Builder(CTPP2.Builder): class Builder(CTPP2.Builder):
make_target = "ctpp2c" make_targets = ["ctpp2c"]
@property @property
def build_path(self): def build_path(self):
@ -47,8 +48,9 @@ class CTPP2C(CTPP2):
def _install(self, context): def _install(self, context):
context.try_skip(self.build_path) context.try_skip(self.build_path)
command = "cp {ctpp2c}* {install_dir}".format( command = (
ctpp2c=pj(self.build_path, 'ctpp2c'), 'cp',
install_dir=pj(self.buildEnv.install_dir, 'bin') *glob(pj(self.build_path, 'ctpp2c*')),
pj(self.buildEnv.install_dir, 'bin')
) )
run_command(command, self.build_path, context, buildEnv=self.buildEnv) run_command(command, self.build_path, context, buildEnv=self.buildEnv)

View File

@ -17,7 +17,7 @@ class Gumbo(Dependency):
def _post_prepare_script(self, context): def _post_prepare_script(self, context):
context.try_skip(self.extract_path) context.try_skip(self.extract_path)
command = "./autogen.sh" command = ["./autogen.sh"]
run_command(command, self.extract_path, context) run_command(command, self.extract_path, context)
Builder = MakeBuilder Builder = MakeBuilder

View File

@ -32,17 +32,20 @@ class Icu(Dependency):
return [(plt, 'icu4c')] return [(plt, 'icu4c')]
@property @property
def configure_option(self): def configure_options(self):
options = ("--disable-samples --disable-tests --disable-extras " yield "--disable-samples"
"--disable-dyload --enable-rpath " yield "--disable-tests"
"--disable-icuio --disable-layoutex") yield "--disable-extras"
yield "--disable-dyload"
yield "--enable-rpath"
yield "--disable-icuio"
yield "--disable-layoutex"
platformInfo = self.buildEnv.platformInfo platformInfo = self.buildEnv.platformInfo
if platformInfo.build != 'native': if platformInfo.build != 'native':
icu_native_builder = get_target_step( icu_native_builder = get_target_step(
'icu4c', 'icu4c',
'native_static' if platformInfo.static else 'native_dyn') 'native_static' if platformInfo.static else 'native_dyn')
options += " --with-cross-build={} --disable-tools".format( yield "--with-cross-build={}".format(icu_native_builder.build_path)
icu_native_builder.build_path) yield "--disable-tools"
if platformInfo.build == 'android': if platformInfo.build == 'android':
options += " --with-data-packaging=archive" yield "--with-data-packaging=archive"
return options

View File

@ -40,11 +40,12 @@ class IOSFatLib(Dependency):
if f.endswith('.a') or f.endswith('.dylib'): if f.endswith('.a') or f.endswith('.dylib'):
libs.append(f) libs.append(f)
os.makedirs(pj(self.buildEnv.install_dir, 'lib'), exist_ok=True) os.makedirs(pj(self.buildEnv.install_dir, 'lib'), exist_ok=True)
command_tmp = "lipo -create {input} -output {output}"
for l in libs: for l in libs:
command = command_tmp.format( command = [
input=" ".join(pj(d, l) for d in lib_dirs), 'lipo',
output=pj(self.buildEnv.install_dir, 'lib', l)) '-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) run_command(command, self.buildEnv.install_dir, context)
def build(self): def build(self):

View File

@ -6,7 +6,7 @@ from .base import (
GitClone, GitClone,
GradleBuilder) 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 from kiwixbuild._global import option, get_target_step
class KiwixCustomApp(Dependency): class KiwixCustomApp(Dependency):
@ -24,22 +24,22 @@ class KiwixCustomApp(Dependency):
dependencies = ["kiwix-android", "kiwix-lib"] dependencies = ["kiwix-android", "kiwix-lib"]
@property @property
def gradle_target(self): def gradle_targets(self):
return "assemble{}".format(self.target.custom_name) yield "assemble{}".format(self.target.custom_name)
@property @property
def gradle_option(self): def gradle_options(self):
template = ("-i -P customDir={customDir}" yield "-i"
" -P zim_file_size={zim_size}" yield "-P"
" -P version_code={version_code}" yield "customDir={}".format(pj(self.build_path, 'custom'))
" -P version_name={version_name}" yield "-P"
" -P content_version_code={content_version_code}") yield "zim_file_size={}".format(zim_size)
return template.format( yield "-P"
customDir=pj(self.build_path, 'custom'), yield "version_code={}".format(os.environ['VERSION_CODE'])
zim_size=self._get_zim_size(), yield "-P"
version_code=os.environ['VERSION_CODE'], yield "version_name={}".format(os.environ['VERSION_NAME'])
version_name=os.environ['VERSION_NAME'], yield "-P"
content_version_code=os.environ['CONTENT_VERSION_CODE']) yield "content_version_code={}".format(os.environ['CONTENT_VERSION_CODE'])
@property @property
def build_path(self): def build_path(self):
@ -104,9 +104,10 @@ class KiwixCustomApp(Dependency):
except FileNotFoundError: except FileNotFoundError:
pass pass
os.makedirs(pj(self.build_path, 'custom')) os.makedirs(pj(self.build_path, 'custom'))
command = "./gen-custom-android-directory.py {custom_name} --output-dir {custom_dir}" command = [
command = command.format( "./gen-custom-android-directory.py",
custom_name=self.target.custom_name, self.target.custom_name,
custom_dir=pj(self.build_path, 'custom', self.target.custom_name) "--output-dir",
) pj(self.build_path, 'custom', self.target.custom_name)
self.buildEnv.run_command(command, self.source_path, context) ]
run_command(command, self.source_path, context, buildEnv=self.buildEnv)

View File

@ -13,8 +13,7 @@ class KiwixDesktop(Dependency):
class Builder(QMakeBuilder): class Builder(QMakeBuilder):
dependencies = ["qt", "qtwebengine", "kiwix-lib"] dependencies = ["qt", "qtwebengine", "kiwix-lib"]
@property @property
def configure_option(self): def configure_options(self):
options = ["PREFIX={}".format(self.buildEnv.install_dir)] yield "PREFIX={}".format(self.buildEnv.install_dir)
if self.buildEnv.platformInfo.static: if self.buildEnv.platformInfo.static:
options.append('"CONFIG+=static"') yield 'CONFIG+=static'
return " ".join(options)

View File

@ -22,11 +22,10 @@ class Kiwixlib(Dependency):
@property @property
def configure_option(self): def configure_options(self):
base_option = "-Dctpp2-install-prefix={buildEnv.install_dir}" yield "-Dctpp2-install-prefix={}".format(self.buildEnv.install_dir)
if self.buildEnv.platformInfo.build == 'android': if self.buildEnv.platformInfo.build == 'android':
base_option += ' -Dandroid=true' yield '-Dandroid=true'
return base_option
@property @property
def library_type(self): def library_type(self):

View File

@ -14,7 +14,6 @@ class KiwixTools(Dependency):
dependencies = ["kiwix-lib", "libmicrohttpd", "zlib"] dependencies = ["kiwix-lib", "libmicrohttpd", "zlib"]
@property @property
def configure_option(self): def configure_options(self):
if self.buildEnv.platformInfo.static: if self.buildEnv.platformInfo.static:
return "-Dstatic-linkage=true" yield "-Dstatic-linkage=true"
return ""

View File

@ -18,9 +18,9 @@ class Aria2(Dependency):
def _post_prepare_script(self, context): def _post_prepare_script(self, context):
context.try_skip(self.extract_path) context.try_skip(self.extract_path)
command = "autoreconf -i" command = ["autoreconf", "-i"]
run_command(command, self.extract_path, context) run_command(command, self.extract_path, context)
class Builder(MakeBuilder): class Builder(MakeBuilder):
dependencies = ['zlib'] 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"]

View File

@ -32,10 +32,12 @@ class LibMagic(Dependency):
if platformInfo.build == 'native': if platformInfo.build == 'native':
return super()._compile(context) return super()._compile(context)
context.try_skip(self.build_path) context.try_skip(self.build_path)
command = "make -j4 {make_target} {make_option}".format( command = [
make_target=self.make_target, "make",
make_option=self.make_option "-j4",
) *self.make_targets,
*self.make_options
]
libmagic_native_builder = get_target_step('libmagic', 'native_static') libmagic_native_builder = get_target_step('libmagic', 'native_static')
env = DefaultEnv() env = DefaultEnv()
env['PATH'] = ':'.join([pj(libmagic_native_builder.build_path, 'src'), env['PATH']]) env['PATH'] = ':'.join([pj(libmagic_native_builder.build_path, 'src'), env['PATH']])

View File

@ -14,4 +14,4 @@ class MicroHttpd(Dependency):
'http://ftp.gnu.org/gnu/libmicrohttpd/libmicrohttpd-0.9.46.tar.gz') 'http://ftp.gnu.org/gnu/libmicrohttpd/libmicrohttpd-0.9.46.tar.gz')
class Builder(MakeBuilder): class Builder(MakeBuilder):
configure_option = "--disable-https --without-libgcrypt --without-libcurl" configure_options = ["--disable-https", "--without-libgcrypt", "--without-libcurl"]

View File

@ -11,5 +11,5 @@ class Libzim(Dependency):
git_dir = "libzim" git_dir = "libzim"
class Builder(MesonBuilder): class Builder(MesonBuilder):
test_option = "-t 8" test_options = ["-t", "8"]
dependencies = ['zlib', 'lzma', 'xapian-core', 'icu4c'] dependencies = ['zlib', 'lzma', 'xapian-core', 'icu4c']

View File

@ -14,6 +14,4 @@ class lzma(Dependency):
'https://tukaani.org/xz/xz-5.2.3.tar.bz2') 'https://tukaani.org/xz/xz-5.2.3.tar.bz2')
class Builder(MakeBuilder): class Builder(MakeBuilder):
@property configure_options = ["--disable-assembler", "--disable-xz", "--disable-xzdec"]
def configure_option(self):
return "--disable-assembler --disable-xz --disable-xzdec"

View File

@ -21,12 +21,23 @@ class Qt(Dependency):
class Builder(MakeBuilder): class Builder(MakeBuilder):
dependencies = ['icu4c', 'zlib'] dependencies = ['icu4c', 'zlib']
configure_option_template = "{dep_options} {static_option} {env_option} -prefix {install_dir} -libdir {libdir}" dynamic_configure_options = ["-shared"]
dynamic_configure_option = "-shared" static_configure_options = ["-static"]
static_configure_option = "-static"
@property @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 = [ skip_modules = [
'qt3d', 'qt3d',
'qtcanvas3d', 'qtcanvas3d',
@ -55,10 +66,15 @@ class Qt(Dependency):
'qtwebglplugin', 'qtwebglplugin',
'qtwebsockets', 'qtwebsockets',
# 'qtwebview', # 'qtwebview',
] ]
skip_modules = " ".join("-skip {}".format(m) for m in skip_modules) yield '-recheck'
options = "-recheck -opensource -confirm-license -ccache -make libs {}".format(skip_modules) yield '-opensource'
return options yield '-confirm-license'
yield '-ccache'
yield from ('-make', 'libs')
for module in skip_modules:
yield from ('-skip', module)
class QtWebEngine(Dependency): class QtWebEngine(Dependency):
name = "qtwebengine" name = "qtwebengine"

View File

@ -17,9 +17,14 @@ class UUID(Dependency):
extract_dir = 'e2fsprogs-libs-1.43.4' extract_dir = 'e2fsprogs-libs-1.43.4'
class Builder(MakeBuilder): class Builder(MakeBuilder):
configure_option = ("--enable-libuuid --disable-debugfs --disable-imager --disable-resizer --disable-defrag --enable-fsck" configure_options = ["--enable-libuuid",
" --disable-uuidd") "--disable-debugfs",
"--disable-imager",
"--disable-resizer",
"--disable-defrag",
"--enable-fsck",
"--disable-uuidd"]
configure_env = {'_format_CFLAGS': "{env.CFLAGS} -fPIC"} configure_env = {'_format_CFLAGS': "{env.CFLAGS} -fPIC"}
static_configure_option = dynamic_configure_option = "" static_configure_options = dynamic_configure_options = []
make_target = 'libs' make_targets = ['libs']
make_install_target = 'install-libs' make_install_targets = ['install-libs']

View File

@ -17,7 +17,7 @@ class Xapian(Dependency):
patches = ['xapian_sys_types.patch'] patches = ['xapian_sys_types.patch']
class Builder(MakeBuilder): 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}", configure_env = {'_format_LDFLAGS': "-L{buildEnv.install_dir}/{buildEnv.libprefix}",
'_format_CXXFLAGS': "-I{buildEnv.install_dir}/include"} '_format_CXXFLAGS': "-I{buildEnv.install_dir}/include"}

View File

@ -14,7 +14,6 @@ class ZimTools(Dependency):
dependencies = ['libzim'] dependencies = ['libzim']
@property @property
def configure_option(self): def configure_options(self):
if self.buildEnv.platformInfo.static: if self.buildEnv.platformInfo.static:
return "-Dstatic-linkage=true" yield "-Dstatic-linkage=true"
return ""

View File

@ -14,8 +14,7 @@ class Zimwriterfs(Dependency):
dependencies = ['libzim', 'zlib', 'xapian-core', 'gumbo', 'icu4c', 'libmagic'] dependencies = ['libzim', 'zlib', 'xapian-core', 'gumbo', 'icu4c', 'libmagic']
@property @property
def configure_option(self): def configure_options(self):
base_option = "-Dmagic-install-prefix={buildEnv.install_dir}" yield "-Dmagic-install-prefix={}".format(self.buildEnv.install_dir)
if self.buildEnv.platformInfo.static: if self.buildEnv.platformInfo.static:
base_option += " -Dstatic-linkage=true" yield "-Dstatic-linkage=true"
return base_option

View File

@ -18,9 +18,8 @@ class zlib(Dependency):
patches = ['zlib_std_libname.patch'] patches = ['zlib_std_libname.patch']
class Builder(MakeBuilder): class Builder(MakeBuilder):
dynamic_configure_option = "--shared" dynamic_configure_options = ["--shared"]
static_configure_option = "--static" static_configure_options = ["--static"]
configure_option_template = "{dep_options} {static_option} --prefix {install_dir} --libdir {libdir}"
def _pre_build_script(self, context): def _pre_build_script(self, context):
context.try_skip(self.build_path) context.try_skip(self.build_path)
@ -33,13 +32,20 @@ class zlib(Dependency):
return super()._configure(context) return super()._configure(context)
@property @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': 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( return
host='i686-w64-mingw32', yield "--makefile"
static="0" if self.buildEnv.platformInfo.static else "1", yield "{}/Makefile.gcc".format(self.buildEnv.platformInfo.build)
include_path=pj(self.buildEnv.install_dir, 'include'), yield "PREFIX={}-".format(self.buildEnv.platformInfo.arch_full)
library_path=pj(self.buildEnv.install_dir, self.buildEnv.libprefix), yield "SHARED_MODE={}".format("0" if self.buildEnv.platformInfo.static else "1")
binary_path=pj(self.buildEnv.install_dir, 'bin'), yield "INCLUDE_PATH={}".format(pj(self.buildEnv.install_dir, 'include'))
) yield "LIBRARY_PATH={}".format(pj(self.buildEnv.install_dir, self.buildEnv.libprefix))
return "" yield "BINARY_PATH={}".format(pj(self.buildEnv.install_dir, 'bin'))

View File

@ -85,8 +85,8 @@ class AndroidPlatformInfo(PlatformInfo):
env['CXX'] = binaries['CXX'] env['CXX'] = binaries['CXX']
@property @property
def configure_option(self): def configure_options(self):
return '--host={}'.format(self.arch_full) yield '--host={}'.format(self.arch_full)
def finalize_setup(self): def finalize_setup(self):
super().finalize_setup() super().finalize_setup()

View File

@ -61,8 +61,8 @@ class ArmhfPlatformInfo(PlatformInfo):
return "exec_wrapper = 'qemu-arm'" return "exec_wrapper = 'qemu-arm'"
@property @property
def configure_option(self): def configure_options(self):
return '--host={}'.format(self.arch_full) yield '--host={}'.format(self.arch_full)
def get_bin_dir(self): def get_bin_dir(self):
return [pj(self.root_path, 'bin')] return [pj(self.root_path, 'bin')]

View File

@ -23,7 +23,7 @@ class PlatformInfo(metaclass=_MetaPlatform):
all_platforms = {} all_platforms = {}
all_running_platforms = {} all_running_platforms = {}
toolchain_names = [] toolchain_names = []
configure_option = "" configure_options = []
@classmethod @classmethod
def get_platform(cls, name, targets=None): def get_platform(cls, name, targets=None):

View File

@ -26,8 +26,8 @@ class I586PlatformInfo(PlatformInfo):
} }
@property @property
def configure_option(self): def configure_options(self):
return '--host={}'.format(self.arch_full) yield '--host={}'.format(self.arch_full)
@property @property
def binaries(self): def binaries(self):

View File

@ -76,8 +76,8 @@ class iOSPlatformInfo(PlatformInfo):
} }
@property @property
def configure_option(self): def configure_options(self):
return '--host={}'.format(self.arch_full) yield '--host={}'.format(self.arch_full)
def set_compiler(self, env): def set_compiler(self, env):
env['CC'] = self.binaries['CC'] env['CC'] = self.binaries['CC']

View File

@ -62,8 +62,8 @@ class Win32PlatformInfo(PlatformInfo):
return "exec_wrapper = 'wine'" return "exec_wrapper = 'wine'"
@property @property
def configure_option(self): def configure_options(self):
return '--host={}'.format(self.arch_full) yield '--host={}'.format(self.arch_full)
def set_compiler(self, env): def set_compiler(self, env):
for k, v in self.binaries.items(): for k, v in self.binaries.items():

View File

@ -263,7 +263,7 @@ def run_command(command, cwd, context, buildEnv=None, env=None, input=None, cros
kwargs = dict() kwargs = dict()
if input: if input:
kwargs['stdin'] = subprocess.PIPE 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: if input:
process.communicate(input.encode()) process.communicate(input.encode())
retcode = process.wait() retcode = process.wait()