From db6aa2eed247c5f5fe16efd6fb676158704887d3 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 28 Nov 2023 14:26:30 +0100 Subject: [PATCH] Use the correct path separator on Windows --- kiwixbuild/buildenv.py | 9 ++++----- kiwixbuild/configs/armhf.py | 15 ++++++--------- kiwixbuild/configs/base.py | 6 ++---- kiwixbuild/configs/musl.py | 19 +++++++------------ kiwixbuild/configs/wasm.py | 13 +++++-------- kiwixbuild/dependencies/libmagic.py | 11 +++++++---- kiwixbuild/utils.py | 24 ++++++++++++++++++++++++ 7 files changed, 55 insertions(+), 42 deletions(-) diff --git a/kiwixbuild/buildenv.py b/kiwixbuild/buildenv.py index 81945b2..0c10157 100644 --- a/kiwixbuild/buildenv.py +++ b/kiwixbuild/buildenv.py @@ -123,13 +123,12 @@ class BuildEnv: def get_env(self, *, cross_comp_flags, cross_compilers, cross_path): env = self.configInfo.get_env() pkgconfig_path = pj(self.install_dir, self.libprefix, "pkgconfig") - env["PKG_CONFIG_PATH"] = ":".join([env["PKG_CONFIG_PATH"], pkgconfig_path]) + env["PKG_CONFIG_PATH"].append(pkgconfig_path) - env["PATH"] = ":".join([escape_path(pj(self.install_dir, "bin")), env["PATH"]]) + env["PATH"].insert(0, pj(self.install_dir, "bin")) - env["LD_LIBRARY_PATH"] = ":".join( + env["LD_LIBRARY_PATH"].extend( [ - env["LD_LIBRARY_PATH"], pj(self.install_dir, "lib"), pj(self.install_dir, self.libprefix), ] @@ -161,7 +160,7 @@ class BuildEnv: if cross_compilers: self.configInfo.set_compiler(env) if cross_path: - env["PATH"] = ":".join(self.configInfo.get_bin_dir() + [env["PATH"]]) + env["PATH"][0:0] = self.configInfo.get_bin_dir() return env @property diff --git a/kiwixbuild/configs/armhf.py b/kiwixbuild/configs/armhf.py index de666a3..708d192 100644 --- a/kiwixbuild/configs/armhf.py +++ b/kiwixbuild/configs/armhf.py @@ -1,6 +1,6 @@ from .base import ConfigInfo, MixedMixin -from kiwixbuild.utils import pj +from kiwixbuild.utils import pj, get_separator from kiwixbuild._global import get_target_step @@ -76,17 +76,14 @@ class ArmConfigInfo(ConfigInfo): def get_env(self): env = super().get_env() - env["LD_LIBRARY_PATH"] = ":".join( - [ - pj(self.root_path, self.arch_full, "lib64"), - pj(self.root_path, "lib"), - env["LD_LIBRARY_PATH"], - ] - ) + env["LD_LIBRARY_PATH"][0:0] = [ + pj(self.root_path, self.arch_full, "lib64"), + pj(self.root_path, "lib") + ] env["PKG_CONFIG_LIBDIR"] = pj(self.root_path, "lib", "pkgconfig") env["QEMU_LD_PREFIX"] = pj(self.root_path, self.arch_full, "libc") env["QEMU_SET_ENV"] = "LD_LIBRARY_PATH={}".format( - ":".join( + get_separator().join( [pj(self.root_path, self.arch_full, "lib"), env["LD_LIBRARY_PATH"]] ) ) diff --git a/kiwixbuild/configs/base.py b/kiwixbuild/configs/base.py index 21049d5..5de6483 100644 --- a/kiwixbuild/configs/base.py +++ b/kiwixbuild/configs/base.py @@ -161,15 +161,13 @@ def MixedMixin(static_name): def get_env(self): env = super().get_env() - env["PATH"] = ":".join( - [pj(self.static_buildEnv.install_dir, "bin")] + [env["PATH"]] - ) + env["PATH"].insert(0, pj(self.static_buildEnv.install_dir, "bin")) pkgconfig_path = pj( self.static_buildEnv.install_dir, self.static_buildEnv.libprefix, "pkgconfig", ) - env["PKG_CONFIG_PATH"] = ":".join([env["PKG_CONFIG_PATH"], pkgconfig_path]) + env["PKG_CONFIG_PATH"].append(pkgconfig_path) env["CPPFLAGS"] = " ".join( [ "-I" + pj(self.static_buildEnv.install_dir, "include"), diff --git a/kiwixbuild/configs/musl.py b/kiwixbuild/configs/musl.py index c1eebd8..b8f9f18 100644 --- a/kiwixbuild/configs/musl.py +++ b/kiwixbuild/configs/musl.py @@ -1,6 +1,6 @@ from .base import ConfigInfo, MixedMixin -from kiwixbuild.utils import pj +from kiwixbuild.utils import pj, get_separator from kiwixbuild._global import get_target_step @@ -73,17 +73,14 @@ class MuslConfigInfo(ConfigInfo): def get_env(self): env = super().get_env() - env["LD_LIBRARY_PATH"] = ":".join( - [ - pj(self.root_path, self.arch_full, "lib64"), - pj(self.root_path, "lib"), - env["LD_LIBRARY_PATH"], - ] - ) + env["LD_LIBRARY_PATH"][0:0] = [ + pj(self.root_path, self.arch_full, "lib64"), + pj(self.root_path, "lib") + ] env["PKG_CONFIG_LIBDIR"] = pj(self.root_path, "lib", "pkgconfig") env["QEMU_LD_PREFIX"] = pj(self.root_path, self.arch_full, "libc") env["QEMU_SET_ENV"] = "LD_LIBRARY_PATH={}".format( - ":".join( + get_separator().join( [pj(self.root_path, self.arch_full, "lib"), env["LD_LIBRARY_PATH"]] ) ) @@ -91,9 +88,7 @@ class MuslConfigInfo(ConfigInfo): def set_comp_flags(self, env): super().set_comp_flags(env) - env["LD_LIBRARY_PATH"] = ":".join( - [pj(self.root_path, self.arch_full, "lib"), env["LD_LIBRARY_PATH"]] - ) + env["LD_LIBRARY_PATH"].insert(0, pj(self.root_path, self.arch_full, "lib")) env["CFLAGS"] = ( " -fPIC -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 " + env["CFLAGS"] diff --git a/kiwixbuild/configs/wasm.py b/kiwixbuild/configs/wasm.py index ff0503e..6562550 100644 --- a/kiwixbuild/configs/wasm.py +++ b/kiwixbuild/configs/wasm.py @@ -79,14 +79,11 @@ class WasmConfigInfo(ConfigInfo): def get_env(self): env = super().get_env() - env["PATH"] = ":".join( - [ - env["PATH"], - self.install_path, - pj(self.install_path, "upstream", "emscripten"), - pj(self.install_path, "node", "14.18.2_64bit", "bin"), - ] - ) + env["PATH"].extend([ + self.install_path, + pj(self.install_path, "upstream", "emscripten"), + pj(self.install_path, "node", "14.18.2_64bit", "bin"), + ]) env["EMSDK"] = self.install_path env["EMSDK_NODE"] = pj( self.install_path, "node", "14.18.2_64bit", "bin", "node" diff --git a/kiwixbuild/dependencies/libmagic.py b/kiwixbuild/dependencies/libmagic.py index 18d2f9d..7ed47c2 100644 --- a/kiwixbuild/dependencies/libmagic.py +++ b/kiwixbuild/dependencies/libmagic.py @@ -41,12 +41,15 @@ class LibMagic(Dependency): if configInfo.build == "native": return super()._compile(context) context.try_skip(self.build_path) - command = ["make", "-j4", *self.make_targets, *self.make_options] + command = [ + "make", + "-j4", + *self.make_targets, + *self.make_options + ] env = self.buildEnv.get_env( cross_comp_flags=True, cross_compilers=True, cross_path=True ) libmagic_native_builder = get_target_step("libmagic", "native_static") - env["PATH"] = ":".join( - [pj(libmagic_native_builder.build_path, "src"), env["PATH"]] - ) + env["PATH"].insert(0, pj(libmagic_native_builder.build_path, "src")) run_command(command, self.build_path, context, env=env) diff --git a/kiwixbuild/utils.py b/kiwixbuild/utils.py index 3d4f4f5..d82679b 100644 --- a/kiwixbuild/utils.py +++ b/kiwixbuild/utils.py @@ -63,8 +63,30 @@ class DefaultEnv(Defaultdict): def __getitem__(self, name): if name == b"PATH": raise KeyError + if name in ['PATH', 'PKG_CONFIG_PATH', 'LD_LIBRARY_PATH']: + item = super().__getitem__(name) + if isinstance(item, PathArray): + return item + else: + item = PathArray(item) + self[name] = item + return item return super().__getitem__(name) +def get_separator(): + return ';' if neutralEnv('distname') == 'Windows' else ':' + +class PathArray(list): + def __init__(self, value): + self.separator = get_separator() + if not value: + super().__init__([]) + else: + super().__init__(value.split(self.separator)) + + def __str__(self): + return self.separator.join(self) + def remove_duplicates(iterable, key_function=None): seen = set() @@ -297,9 +319,11 @@ def run_command(command, cwd, context, *, env=None, input=None): print("run command '{}'".format(command), file=log) print("current directory is '{}'".format(cwd), file=log) print("env is :", file=log) + env = {k:str(v) for k,v in env.items()} for k, v in env.items(): print(" {} : {!r}".format(k, v), file=log) + if log: log.flush() kwargs = dict()