From c0ec9c44b8eef1dd0efd0b71dc34b739387e234d Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Mon, 5 Feb 2024 17:46:13 +0100 Subject: [PATCH] Rename option `--target-platform` to `--config` The target_platform option has always be wrongly named. This is not the platform we are targeted but how we compile. This was ok at beginning as specifying how we compile somehow define for what we compile but this is not a one to one mapping. --- README.md | 43 +++++---- kiwixbuild/__init__.py | 13 ++- kiwixbuild/buildenv.py | 24 ++--- kiwixbuild/builder.py | 71 +++++++------- kiwixbuild/{platforms => configs}/__init__.py | 0 kiwixbuild/{platforms => configs}/android.py | 16 ++-- kiwixbuild/{platforms => configs}/armhf.py | 12 +-- kiwixbuild/{platforms => configs}/base.py | 54 +++++------ kiwixbuild/{platforms => configs}/flatpak.py | 4 +- kiwixbuild/{platforms => configs}/i586.py | 8 +- kiwixbuild/{platforms => configs}/ios.py | 30 +++--- kiwixbuild/{platforms => configs}/musl.py | 20 ++-- kiwixbuild/{platforms => configs}/native.py | 12 +-- kiwixbuild/{platforms => configs}/neutral.py | 4 +- kiwixbuild/{platforms => configs}/wasm.py | 4 +- kiwixbuild/{platforms => configs}/win32.py | 8 +- kiwixbuild/{platforms => configs}/win64.py | 8 +- kiwixbuild/dependencies/all_dependencies.py | 15 ++- kiwixbuild/dependencies/apple_xcframework.py | 52 +++++------ kiwixbuild/dependencies/base.py | 20 ++-- kiwixbuild/dependencies/icu4c.py | 14 +-- kiwixbuild/dependencies/ios_fat_lib.py | 6 +- kiwixbuild/dependencies/kiwix_desktop.py | 4 +- kiwixbuild/dependencies/kiwix_tools.py | 2 +- kiwixbuild/dependencies/libkiwix.py | 14 +-- kiwixbuild/dependencies/libmagic.py | 8 +- kiwixbuild/dependencies/libzim.py | 20 ++-- kiwixbuild/dependencies/qt.py | 4 +- kiwixbuild/dependencies/tc_android_ndk.py | 10 +- kiwixbuild/dependencies/xapian.py | 4 +- kiwixbuild/dependencies/zim_tools.py | 8 +- kiwixbuild/dependencies/zlib.py | 10 +- kiwixbuild/flatpak_builder.py | 92 +++++++++---------- 33 files changed, 305 insertions(+), 309 deletions(-) rename kiwixbuild/{platforms => configs}/__init__.py (100%) rename kiwixbuild/{platforms => configs}/android.py (93%) rename kiwixbuild/{platforms => configs}/armhf.py (96%) rename kiwixbuild/{platforms => configs}/base.py (76%) rename kiwixbuild/{platforms => configs}/flatpak.py (84%) rename kiwixbuild/{platforms => configs}/i586.py (93%) rename kiwixbuild/{platforms => configs}/ios.py (89%) rename kiwixbuild/{platforms => configs}/musl.py (91%) rename kiwixbuild/{platforms => configs}/native.py (70%) rename kiwixbuild/{platforms => configs}/neutral.py (66%) rename kiwixbuild/{platforms => configs}/wasm.py (97%) rename kiwixbuild/{platforms => configs}/win32.py (94%) rename kiwixbuild/{platforms => configs}/win64.py (94%) diff --git a/README.md b/README.md index 6675fa4..1ba27ed 100644 --- a/README.md +++ b/README.md @@ -78,12 +78,12 @@ invalid choice: 'not-existing-target' (choose from 'alldependencies', 'android-n ... ``` -#### Target platform +#### Config -If no target platform is specified, the default will be `native_dyn`. +If no config is specified, the default will be `native_dyn`. -You can select another target platform using the option -`--target-platform`. For now, there is ten different supported +You can select another config using the option +`--config`. For now, there is ten different supported platforms: - native_dyn @@ -98,9 +98,12 @@ platforms: - android_x86_64 - flatpak -So, if you want to compile `kiwix-tools` for win32 using static linkage: +All `native_*` config means using the native compiler without any cross-compilation option. +Other may simply use cross-compilation or may download a specific toolchain to use. + +If you want to compile `kiwix-tools` for win32 using static linkage: ```bash -kiwix-build --target-platform win32_dyn +kiwix-build --config win32_dyn ``` Android @@ -112,20 +115,20 @@ the `libkiwix` project. When building `libkiwix`, you should directly use the target-platform `android_`: ```bash -kiwix-build libkiwix --target-platform android_arm +kiwix-build libkiwix --config android_arm ``` -But, `libkiwix-app` is mainly multi arch. -To compile `libkiwix-app`, you must use the `android` platform: +You may directly use the special config `android` which will build different android architectures ```bash -kiwix-build --target-platform android libkiwix +kiwix-build --config android libkiwix ``` -By default, when using platform `android`, `libkiwix` will be build for -all architectures. This can be changed by using the option `--android-arch`: +By default, it will build for all android architecture, +you can limit this with option `--android-arch`: ```bash -kiwix-build libkiwix --android-arch arm # aar with arm architecture -kiwix-build libkiwix --android-arch arm --android-arch arm64 # aan with arm and arm64 architectures +kiwix-build libkiwix --config android --android-arch arm # aar with arm architecture +kiwix-build libkiwix --config android --android-arch arm --android-arch arm64 # aan with arm and arm64 architectures +``` To build `kiwix-android` itself, you should see the documentation of `kiwix-android`. @@ -139,13 +142,13 @@ To do so, you should directly use the target-platfrom `ios_multi`. As for `android`, `kiwix-build` will build the library several times (once for each platform) and then create the fat library. ```bash -kiwix-build --target-platform iOS_multi libkiwix +kiwix-build --config iOS_multi libkiwix ``` You can specify the supported architectures with the option `--ios-arch`: ```bash -kiwix-build --target-platform iOS_multi libkiwix # all architetures -kiwix-build --target-platform iOS_multi --ios-arch arm --ios-arch arm64 # arm and arm64 arch only +kiwix-build --config iOS_multi libkiwix # all architetures +kiwix-build --config iOS_multi --ios-arch arm --ios-arch arm64 # arm and arm64 arch only ``` Outputs @@ -154,9 +157,9 @@ Outputs Kiwix-build.py will create several directories: - `ARCHIVES`: All the downloaded archives go there. - `SOURCES`: All the sources (extracted from archives and patched) go there. -- `BUILD_`: All the build files go there. -- `BUILD_/INSTALL`: The installed files go there. -- `BUILD_/LOGS`: The logs files of the build. +- `BUILD_`: All the build files go there. +- `BUILD_/INSTALL`: The installed files go there. +- `BUILD_/LOGS`: The logs files of the build. If you want to install all those directories elsewhere, you can pass the `--working-dir` option to `kiwix-build`: diff --git a/kiwixbuild/__init__.py b/kiwixbuild/__init__.py index 6bb3e5a..33f2926 100644 --- a/kiwixbuild/__init__.py +++ b/kiwixbuild/__init__.py @@ -4,7 +4,7 @@ import os, sys import argparse from .dependencies import Dependency -from .platforms import PlatformInfo +from .configs import ConfigInfo from .builder import Builder from .flatpak_builder import FlatpakBuilder from . import _global @@ -37,7 +37,9 @@ def parse_args(): ), ) parser.add_argument("--libprefix", default=None) - parser.add_argument("--target-platform", choices=PlatformInfo.all_platforms) + parser.add_argument( + "--config", choices=ConfigInfo.all_configs, default="native_dyn" + ) parser.add_argument( "--verbose", "-v", @@ -130,9 +132,6 @@ def parse_args(): if not options.ios_arch: options.ios_arch = ["arm64", "x86_64"] - if not options.target_platform: - options.target_platform = "native_dyn" - return options @@ -140,9 +139,9 @@ def main(): options = parse_args() options.working_dir = os.path.abspath(options.working_dir) _global.set_options(options) - neutralEnv = buildenv.PlatformNeutralEnv() + neutralEnv = buildenv.NeutralEnv() _global.set_neutralEnv(neutralEnv) - if options.target_platform == "flatpak": + if options.config == "flatpak": builder = FlatpakBuilder() else: builder = Builder() diff --git a/kiwixbuild/buildenv.py b/kiwixbuild/buildenv.py index 27c8979..37fe7fc 100644 --- a/kiwixbuild/buildenv.py +++ b/kiwixbuild/buildenv.py @@ -7,7 +7,7 @@ from .utils import pj, download_remote, escape_path from ._global import neutralEnv, option -class PlatformNeutralEnv: +class NeutralEnv: def __init__(self): self.working_dir = option("working_dir") self.source_dir = pj(self.working_dir, "SOURCE") @@ -75,9 +75,9 @@ class PlatformNeutralEnv: class BuildEnv: - def __init__(self, platformInfo): - build_dir = "BUILD_{}".format(platformInfo.name) - self.platformInfo = platformInfo + def __init__(self, configInfo): + build_dir = "BUILD_{}".format(configInfo.name) + self.configInfo = configInfo self.base_build_dir = pj(option("working_dir"), option("build_dir")) self.build_dir = pj(self.base_build_dir, build_dir) self.install_dir = pj(self.build_dir, "INSTALL") @@ -102,8 +102,8 @@ class BuildEnv: return os.path.isfile("/etc/debian_version") def _detect_libdir(self): - if self.platformInfo.libdir is not None: - return self.platformInfo.libdir + if self.configInfo.libdir is not None: + return self.configInfo.libdir if self._is_debianlike(): try: pc = subprocess.Popen( @@ -122,7 +122,7 @@ class BuildEnv: return "lib" def get_env(self, *, cross_comp_flags, cross_compilers, cross_path): - env = self.platformInfo.get_env() + 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]) @@ -158,23 +158,23 @@ class BuildEnv: ) if cross_comp_flags: - self.platformInfo.set_comp_flags(env) + self.configInfo.set_comp_flags(env) if cross_compilers: - self.platformInfo.set_compiler(env) + self.configInfo.set_compiler(env) if cross_path: - env["PATH"] = ":".join(self.platformInfo.get_bin_dir() + [env["PATH"]]) + env["PATH"] = ":".join(self.configInfo.get_bin_dir() + [env["PATH"]]) return env @property def configure_wrapper(self): try: - yield self.platformInfo.configure_wrapper + yield self.configInfo.configure_wrapper except AttributeError: pass @property def make_wrapper(self): try: - yield self.platformInfo.make_wrapper + yield self.configInfo.make_wrapper except AttributeError: pass diff --git a/kiwixbuild/builder.py b/kiwixbuild/builder.py index 7909cd1..587a3a7 100644 --- a/kiwixbuild/builder.py +++ b/kiwixbuild/builder.py @@ -2,7 +2,7 @@ import sys from collections import OrderedDict from .buildenv import * -from .platforms import PlatformInfo +from .configs import ConfigInfo from .utils import remove_duplicates, StopBuild, colorize from .dependencies import Dependency from .packages import PACKAGE_NAME_MAPPERS @@ -19,19 +19,18 @@ from . import _global class Builder: def __init__(self): self._targets = {} - PlatformInfo.get_platform("neutral", self._targets) + ConfigInfo.get_config("neutral", self._targets) - target_platform = option("target_platform") - platform = PlatformInfo.get_platform(target_platform, self._targets) - if neutralEnv("distname") not in platform.compatible_hosts: + config_name = option("config") + config = ConfigInfo.get_config(config_name, self._targets) + if neutralEnv("distname") not in config.compatible_hosts: print( ( - colorize("ERROR") - + ": The target platform {} cannot be build on host {}.\n" - "Select another target platform or change your host system." - ).format(platform.name, neutralEnv("distname")) + colorize("ERROR") + ": The config {} cannot be build on host {}.\n" + "Select another config or change your host system." + ).format(config.name, neutralEnv("distname")) ) - self.targetDefs = platform.add_targets(option("target"), self._targets) + self.targetDefs = config.add_targets(option("target"), self._targets) def finalize_target_steps(self): steps = [] @@ -40,7 +39,7 @@ class Builder: steps = list(remove_duplicates(steps)) if option("build_nodeps"): - # add all platform steps + # add all config steps for dep in steps: stepClass = Dependency.all_deps[dep[1]] if stepClass.dont_skip: @@ -57,18 +56,18 @@ class Builder: self.instanciate_steps() def order_steps(self, targetDef): - for pltName in PlatformInfo.all_running_platforms: - plt = PlatformInfo.all_platforms[pltName] - for tlcName in plt.toolchain_names: + for cfgName in ConfigInfo.all_running_configs: + cfg = ConfigInfo.all_configs[cfgName] + for tlcName in cfg.toolchain_names: tlc = Dependency.all_deps[tlcName] yield ("source", tlcName) - yield ("neutral" if tlc.neutral else pltName, tlcName) + yield ("neutral" if tlc.neutral else cfgName, tlcName) _targets = dict(self._targets) yield from self.order_dependencies(targetDef, _targets) def order_dependencies(self, targetDef, targets): - targetPlatformName, targetName = targetDef - if targetPlatformName == "source": + targetConfigName, targetName = targetDef + if targetConfigName == "source": # Do not try to order sources, they will be added as dep by the # build step two lines later. return @@ -77,24 +76,24 @@ class Builder: except KeyError: return - targetPlatform = PlatformInfo.get_platform(targetPlatformName) - for dep in target.get_dependencies(targetPlatform, True): - depPlatform, depName = targetPlatform.get_fully_qualified_dep(dep) - if (depPlatform, depName) in targets: - yield from self.order_dependencies((depPlatform, depName), targets) + targetConfig = ConfigInfo.get_config(targetConfigName) + for dep in target.get_dependencies(targetConfig, True): + depConfig, depName = targetConfig.get_fully_qualified_dep(dep) + if (depConfig, depName) in targets: + yield from self.order_dependencies((depConfig, depName), targets) yield ("source", targetName) yield targetDef def instanciate_steps(self): for stepDef in list(target_steps()): - stepPlatform, stepName = stepDef + stepConfig, stepName = stepDef stepClass = Dependency.all_deps[stepName] - if stepPlatform == "source": + if stepConfig == "source": source = get_target_step(stepDef)(stepClass) add_target_step(stepDef, source) else: source = get_target_step(stepName, "source") - env = PlatformInfo.get_platform(stepPlatform).buildEnv + env = ConfigInfo.get_config(stepConfig).buildEnv builder = get_target_step(stepDef)(stepClass, source, env) add_target_step(stepDef, builder) @@ -125,18 +124,18 @@ class Builder: def _get_packages(self): packages_list = [] - for platform in PlatformInfo.all_running_platforms.values(): - mapper_name = "{host}_{target}".format( - host=neutralEnv("distname"), target=platform + for config in ConfigInfo.all_running_configs.values(): + mapper_name = "{host}_{config}".format( + host=neutralEnv("distname"), config=config ) package_name_mapper = PACKAGE_NAME_MAPPERS.get(mapper_name, {}) packages_list += package_name_mapper.get("COMMON", []) to_drop = [] for builderDef in self._targets: - platformName, builderName = builderDef - mapper_name = "{host}_{target}".format( - host=neutralEnv("distname"), target=platformName + configName, builderName = builderDef + mapper_name = "{host}_{config}".format( + host=neutralEnv("distname"), config=configName ) package_name_mapper = PACKAGE_NAME_MAPPERS.get(mapper_name, {}) packages = package_name_mapper.get(builderName) @@ -195,9 +194,9 @@ class Builder: else: self.install_packages() self.finalize_target_steps() - print("[SETUP PLATFORMS]") - for platform in PlatformInfo.all_running_platforms.values(): - platform.finalize_setup() + print("[SETUP TOOLCHAINS]") + for config in ConfigInfo.all_running_configs.values(): + config.finalize_setup() print("[PREPARE]") self.prepare_sources() print("[BUILD]") @@ -205,8 +204,8 @@ class Builder: # No error, clean intermediate file at end of build if needed. print("[CLEAN]") if option("clean_at_end"): - for platform in PlatformInfo.all_running_platforms.values(): - platform.clean_intermediate_directories() + for config in ConfigInfo.all_running_configs.values(): + config.clean_intermediate_directories() else: print(colorize("SKIP")) except StopBuild as e: diff --git a/kiwixbuild/platforms/__init__.py b/kiwixbuild/configs/__init__.py similarity index 100% rename from kiwixbuild/platforms/__init__.py rename to kiwixbuild/configs/__init__.py diff --git a/kiwixbuild/platforms/android.py b/kiwixbuild/configs/android.py similarity index 93% rename from kiwixbuild/platforms/android.py rename to kiwixbuild/configs/android.py index 679a6d7..51d6d91 100644 --- a/kiwixbuild/platforms/android.py +++ b/kiwixbuild/configs/android.py @@ -1,9 +1,9 @@ -from .base import PlatformInfo, MetaPlatformInfo +from .base import ConfigInfo, MetaConfigInfo from kiwixbuild.utils import pj from kiwixbuild._global import get_target_step, option -class AndroidPlatformInfo(PlatformInfo): +class AndroidConfigInfo(ConfigInfo): build = "android" static = True toolchain_names = ["android-ndk"] @@ -114,7 +114,7 @@ class AndroidPlatformInfo(PlatformInfo): self.buildEnv.meson_crossfile = self._gen_crossfile("meson_cross_file.txt") -class AndroidArm(AndroidPlatformInfo): +class AndroidArm(AndroidConfigInfo): name = "android_arm" arch = cpu = "arm" arch_full = "arm-linux-androideabi" @@ -122,7 +122,7 @@ class AndroidArm(AndroidPlatformInfo): march = "armv7-a" -class AndroidArm64(AndroidPlatformInfo): +class AndroidArm64(AndroidConfigInfo): name = "android_arm64" arch = "arm64" arch_full = "aarch64-linux-android" @@ -130,25 +130,25 @@ class AndroidArm64(AndroidPlatformInfo): abi = "arm64-v8a" -class AndroidX86(AndroidPlatformInfo): +class AndroidX86(AndroidConfigInfo): name = "android_x86" arch = abi = "x86" arch_full = "i686-linux-android" cpu = "i686" -class AndroidX8664(AndroidPlatformInfo): +class AndroidX8664(AndroidConfigInfo): name = "android_x86_64" arch = cpu = abi = "x86_64" arch_full = "x86_64-linux-android" -class Android(MetaPlatformInfo): +class Android(MetaConfigInfo): name = "android" compatible_hosts = ["fedora", "debian"] @property - def subPlatformNames(self): + def subConfigNames(self): return ["android_{}".format(arch) for arch in option("android_arch")] def add_targets(self, targetName, targets): diff --git a/kiwixbuild/platforms/armhf.py b/kiwixbuild/configs/armhf.py similarity index 96% rename from kiwixbuild/platforms/armhf.py rename to kiwixbuild/configs/armhf.py index 07cf001..de666a3 100644 --- a/kiwixbuild/platforms/armhf.py +++ b/kiwixbuild/configs/armhf.py @@ -1,11 +1,11 @@ -from .base import PlatformInfo, MixedMixin +from .base import ConfigInfo, MixedMixin from kiwixbuild.utils import pj from kiwixbuild._global import get_target_step -# Base platform -class ArmPlatformInfo(PlatformInfo): +# Base config for arm +class ArmConfigInfo(ConfigInfo): compatible_hosts = ["fedora", "debian"] def get_cross_config(self): @@ -113,7 +113,7 @@ class ArmPlatformInfo(PlatformInfo): self.buildEnv.meson_crossfile = self._gen_crossfile("meson_cross_file.txt") -class Armv6(ArmPlatformInfo): +class Armv6(ArmConfigInfo): build = "armv6" arch_full = "armv6-rpi-linux-gnueabihf" toolchain_names = ["armv6"] @@ -136,7 +136,7 @@ class Armv6Mixed(MixedMixin("armv6_static"), Armv6): static = False -class Armv8(ArmPlatformInfo): +class Armv8(ArmConfigInfo): build = "armv8" arch_full = "armv8-rpi3-linux-gnueabihf" toolchain_names = ["armv8"] @@ -159,7 +159,7 @@ class Armv8Mixed(MixedMixin("armv8_static"), Armv8): static = False -class Aarch64(ArmPlatformInfo): +class Aarch64(ArmConfigInfo): build = "aarch64" arch_full = "aarch64-linux-gnu" toolchain_names = ["aarch64"] diff --git a/kiwixbuild/platforms/base.py b/kiwixbuild/configs/base.py similarity index 76% rename from kiwixbuild/platforms/base.py rename to kiwixbuild/configs/base.py index 1210380..43798f2 100644 --- a/kiwixbuild/platforms/base.py +++ b/kiwixbuild/configs/base.py @@ -10,35 +10,35 @@ _SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) TEMPLATES_DIR = pj(os.path.dirname(_SCRIPT_DIR), "templates") -class _MetaPlatform(type): +class _MetaConfig(type): def __new__(cls, name, bases, dct): _class = type.__new__(cls, name, bases, dct) - if name not in ("PlatformInfo", "MetaPlatformInfo") and "name" in dct: + if name not in ("ConfigInfo", "MetaConfigInfo") and "name" in dct: dep_name = dct["name"] - PlatformInfo.all_platforms[dep_name] = _class + ConfigInfo.all_configs[dep_name] = _class return _class -class PlatformInfo(metaclass=_MetaPlatform): - all_platforms = {} - all_running_platforms = {} +class ConfigInfo(metaclass=_MetaConfig): + all_configs = {} + all_running_configs = {} toolchain_names = [] configure_options = [] mixed = False libdir = None @classmethod - def get_platform(cls, name, targets=None): - if name not in cls.all_running_platforms: + def get_config(cls, name, targets=None): + if name not in cls.all_running_configs: if targets is None: print("Should not got there.") - print(cls.all_running_platforms) + print(cls.all_running_configs) raise KeyError(name) - cls.all_running_platforms[name] = cls.all_platforms[name](targets) - return cls.all_running_platforms[name] + cls.all_running_configs[name] = cls.all_configs[name](targets) + return cls.all_running_configs[name] def __init__(self, targets): - self.all_running_platforms[self.name] = self + self.all_running_configs[self.name] = self self.buildEnv = BuildEnv(self) self.setup_toolchains(targets) @@ -49,8 +49,8 @@ class PlatformInfo(metaclass=_MetaPlatform): for tlc_name in self.toolchain_names: ToolchainClass = Dependency.all_deps[tlc_name] targets[("source", tlc_name)] = ToolchainClass.Source - plt_name = "neutral" if ToolchainClass.neutral else self.name - targets[(plt_name, tlc_name)] = ToolchainClass.Builder + cfg_name = "neutral" if ToolchainClass.neutral else self.name + targets[(cfg_name, tlc_name)] = ToolchainClass.Builder def add_targets(self, targetName, targets): if (self.name, targetName) in targets: @@ -60,11 +60,11 @@ class PlatformInfo(metaclass=_MetaPlatform): targets[(self.name, targetName)] = targetClass.Builder for dep in targetClass.Builder.get_dependencies(self, False): if isinstance(dep, tuple): - depPlatformName, depName = dep + depConfigName, depName = dep else: - depPlatformName, depName = self.name, dep - depPlatform = self.get_platform(depPlatformName, targets) - depPlatform.add_targets(depName, targets) + depConfigName, depName = self.name, dep + depConfig = self.get_config(depConfigName, targets) + depConfig.add_targets(depName, targets) return [(self.name, targetName)] def get_fully_qualified_dep(self, dep): @@ -114,14 +114,14 @@ class PlatformInfo(metaclass=_MetaPlatform): self.buildEnv.clean_intermediate_directories() -class MetaPlatformInfo(PlatformInfo): - subPlatformNames = [] +class MetaConfigInfo(ConfigInfo): + subConfigNames = [] def add_targets(self, targetName, targets): targetDefs = [] - for platformName in self.subPlatformNames: - platform = self.get_platform(platformName, targets) - targetDefs += platform.add_targets(targetName, targets) + for configName in self.subConfigNames: + config = self.get_config(configName, targets) + targetDefs += config.add_targets(targetName, targets) return targetDefs @@ -135,8 +135,8 @@ def MixedMixin(static_name): if option("target") == targetName: return super().add_targets(targetName, targets) else: - static_platform = self.get_platform(static_name, targets) - return static_platform.add_targets(targetName, targets) + static_config = self.get_config(static_name, targets) + return static_config.add_targets(targetName, targets) def get_fully_qualified_dep(self, dep): if isinstance(dep, tuple): @@ -147,8 +147,8 @@ def MixedMixin(static_name): @property def static_buildEnv(self): - static_platform = self.get_platform(static_name) - return static_platform.buildEnv + static_config = self.get_config(static_name) + return static_config.buildEnv def get_include_dirs(self): return [ diff --git a/kiwixbuild/platforms/flatpak.py b/kiwixbuild/configs/flatpak.py similarity index 84% rename from kiwixbuild/platforms/flatpak.py rename to kiwixbuild/configs/flatpak.py index be57bca..a49acdd 100644 --- a/kiwixbuild/platforms/flatpak.py +++ b/kiwixbuild/configs/flatpak.py @@ -1,8 +1,8 @@ -from .base import PlatformInfo +from .base import ConfigInfo from kiwixbuild._global import option, neutralEnv -class FlatpakPlatformInfo(PlatformInfo): +class FlatpakConfigInfo(ConfigInfo): name = "flatpak" build = "flatpak" static = "" diff --git a/kiwixbuild/platforms/i586.py b/kiwixbuild/configs/i586.py similarity index 93% rename from kiwixbuild/platforms/i586.py rename to kiwixbuild/configs/i586.py index 341047d..8c402a3 100644 --- a/kiwixbuild/platforms/i586.py +++ b/kiwixbuild/configs/i586.py @@ -1,10 +1,10 @@ import os -from .base import PlatformInfo +from .base import ConfigInfo from kiwixbuild.utils import which, pj -class I586PlatformInfo(PlatformInfo): +class I586ConfigInfo(ConfigInfo): build = "i586" arch_full = "i586-linux-gnu" compatible_hosts = ["fedora", "debian"] @@ -69,11 +69,11 @@ class I586PlatformInfo(PlatformInfo): self.buildEnv.meson_crossfile = self._gen_crossfile("meson_cross_file.txt") -class I586Dyn(I586PlatformInfo): +class I586Dyn(I586ConfigInfo): name = "i586_dyn" static = False -class I586Static(I586PlatformInfo): +class I586Static(I586ConfigInfo): name = "i586_static" static = True diff --git a/kiwixbuild/platforms/ios.py b/kiwixbuild/configs/ios.py similarity index 89% rename from kiwixbuild/platforms/ios.py rename to kiwixbuild/configs/ios.py index 5fb8d7d..bce93a3 100644 --- a/kiwixbuild/platforms/ios.py +++ b/kiwixbuild/configs/ios.py @@ -2,14 +2,14 @@ import subprocess from kiwixbuild._global import option from kiwixbuild.utils import pj, xrun_find -from .base import PlatformInfo, MetaPlatformInfo, MixedMixin +from .base import ConfigInfo, MetaConfigInfo, MixedMixin from kiwixbuild.dependencies.apple_xcframework import AppleXCFramework MIN_MACOS_VERSION = "12.0" -class ApplePlatformInfo(PlatformInfo): +class AppleConfigInfo(ConfigInfo): build = "iOS" static = True compatible_hosts = ["Darwin"] @@ -148,7 +148,7 @@ class ApplePlatformInfo(PlatformInfo): yield f"--host={self.host}" -class iOSArm64(ApplePlatformInfo): +class iOSArm64(AppleConfigInfo): name = "iOS_arm64" arch = cpu = "arm64" host = "arm-apple-darwin" @@ -157,7 +157,7 @@ class iOSArm64(ApplePlatformInfo): min_iphoneos_version = "15.0" -class iOSx64Simulator(ApplePlatformInfo): +class iOSx64Simulator(AppleConfigInfo): name = "iOSSimulator_x86_64" arch = cpu = "x86_64" host = "x86_64-apple-darwin" @@ -166,7 +166,7 @@ class iOSx64Simulator(ApplePlatformInfo): min_iphoneos_version = "15.0" -class iOSArm64Simulator(ApplePlatformInfo): +class iOSArm64Simulator(AppleConfigInfo): name = "iOSSimulator_arm64" arch = cpu = "arm64" host = "arm-apple-darwin" @@ -175,7 +175,7 @@ class iOSArm64Simulator(ApplePlatformInfo): min_iphoneos_version = "15.0" -class macOSArm64(ApplePlatformInfo): +class macOSArm64(AppleConfigInfo): name = "macOS_arm64_static" arch = cpu = "arm64" host = "aarch64-apple-darwin" @@ -185,7 +185,7 @@ class macOSArm64(ApplePlatformInfo): min_macos_version = MIN_MACOS_VERSION -class macOSArm64Mixed(MixedMixin("macOS_arm64_static"), ApplePlatformInfo): +class macOSArm64Mixed(MixedMixin("macOS_arm64_static"), AppleConfigInfo): name = "macOS_arm64_mixed" arch = cpu = "arm64" host = "aarch64-apple-darwin" @@ -195,7 +195,7 @@ class macOSArm64Mixed(MixedMixin("macOS_arm64_static"), ApplePlatformInfo): min_macos_version = MIN_MACOS_VERSION -class macOSx64(ApplePlatformInfo): +class macOSx64(AppleConfigInfo): name = "macOS_x86_64" arch = cpu = "x86_64" host = "x86_64-apple-darwin" @@ -205,33 +205,33 @@ class macOSx64(ApplePlatformInfo): min_macos_version = MIN_MACOS_VERSION -class IOS(MetaPlatformInfo): +class IOS(MetaConfigInfo): name = "iOS_multi" compatible_hosts = ["Darwin"] @property - def subPlatformNames(self): + def subConfigNames(self): return ["iOS_{}".format(arch) for arch in option("ios_arch")] def add_targets(self, targetName, targets): super().add_targets(targetName, targets) - return PlatformInfo.add_targets(self, "_ios_fat_lib", targets) + return ConfigInfo.add_targets(self, "_ios_fat_lib", targets) def __str__(self): return self.name -class AppleStaticAll(MetaPlatformInfo): +class AppleStaticAll(MetaConfigInfo): name = "apple_all_static" compatible_hosts = ["Darwin"] @property - def subPlatformNames(self): - return AppleXCFramework.subPlatformNames + def subConfigNames(self): + return AppleXCFramework.subConfigNames def add_targets(self, targetName, targets): super().add_targets(targetName, targets) - return PlatformInfo.add_targets(self, "apple_xcframework", targets) + return ConfigInfo.add_targets(self, "apple_xcframework", targets) def __str__(self): return self.name diff --git a/kiwixbuild/platforms/musl.py b/kiwixbuild/configs/musl.py similarity index 91% rename from kiwixbuild/platforms/musl.py rename to kiwixbuild/configs/musl.py index c4405c6..c1eebd8 100644 --- a/kiwixbuild/platforms/musl.py +++ b/kiwixbuild/configs/musl.py @@ -1,10 +1,10 @@ -from .base import PlatformInfo, MixedMixin +from .base import ConfigInfo, MixedMixin from kiwixbuild.utils import pj from kiwixbuild._global import get_target_step -class MuslPlatformInfo(PlatformInfo): +class MuslConfigInfo(ConfigInfo): compatible_hosts = ["fedora", "debian"] def get_cross_config(self): @@ -113,7 +113,7 @@ class MuslPlatformInfo(PlatformInfo): self.buildEnv.meson_crossfile = self._gen_crossfile("meson_cross_file.txt") -class Aarch64MuslPlatformInfo(MuslPlatformInfo): +class Aarch64MuslConfigInfo(MuslConfigInfo): build = "aarch64_musl" arch_full = "aarch64-linux-musl" toolchain_names = ["aarch64_musl"] @@ -123,22 +123,22 @@ class Aarch64MuslPlatformInfo(MuslPlatformInfo): qemu = "qemu-arm" -class Aarch64MuslDyn(Aarch64MuslPlatformInfo): +class Aarch64MuslDyn(Aarch64MuslConfigInfo): name = "aarch64_musl_dyn" static = False -class Aarch64MuslStatic(Aarch64MuslPlatformInfo): +class Aarch64MuslStatic(Aarch64MuslConfigInfo): name = "aarch64_musl_static" static = True -class Aarch64MuslMixed(MixedMixin("aarch64_musl_static"), Aarch64MuslPlatformInfo): +class Aarch64MuslMixed(MixedMixin("aarch64_musl_static"), Aarch64MuslConfigInfo): name = "aarch64_musl_mixed" static = False -class X86_64MuslPlatformInfo(MuslPlatformInfo): +class X86_64MuslConfigInfo(MuslConfigInfo): build = "x86-64_musl" arch_full = "x86_64-linux-musl" toolchain_names = ["x86-64_musl"] @@ -147,16 +147,16 @@ class X86_64MuslPlatformInfo(MuslPlatformInfo): cpu = "x86_64" -class X86_64MuslDyn(X86_64MuslPlatformInfo): +class X86_64MuslDyn(X86_64MuslConfigInfo): name = "x86-64_musl_dyn" static = False -class X86_64MuslStatic(X86_64MuslPlatformInfo): +class X86_64MuslStatic(X86_64MuslConfigInfo): name = "x86-64_musl_static" static = True -class x86_64MuslMixed(MixedMixin("x86-64_musl_static"), X86_64MuslPlatformInfo): +class x86_64MuslMixed(MixedMixin("x86-64_musl_static"), X86_64MuslConfigInfo): name = "x86-64_musl_mixed" static = False diff --git a/kiwixbuild/platforms/native.py b/kiwixbuild/configs/native.py similarity index 70% rename from kiwixbuild/platforms/native.py rename to kiwixbuild/configs/native.py index 83efe07..6bf3e36 100644 --- a/kiwixbuild/platforms/native.py +++ b/kiwixbuild/configs/native.py @@ -1,11 +1,11 @@ -from .base import PlatformInfo, MixedMixin +from .base import ConfigInfo, MixedMixin from kiwixbuild.utils import pj from kiwixbuild._global import option, neutralEnv -from kiwixbuild.platforms.ios import MIN_MACOS_VERSION +from kiwixbuild.configs.ios import MIN_MACOS_VERSION -class NativePlatformInfo(PlatformInfo): +class NativeConfigInfo(ConfigInfo): build = "native" def get_env(self): @@ -17,19 +17,19 @@ class NativePlatformInfo(PlatformInfo): return env -class NativeDyn(NativePlatformInfo): +class NativeDyn(NativeConfigInfo): name = "native_dyn" static = False compatible_hosts = ["fedora", "debian", "Darwin"] -class NativeStatic(NativePlatformInfo): +class NativeStatic(NativeConfigInfo): name = "native_static" static = True compatible_hosts = ["fedora", "debian"] -class NativeMixed(MixedMixin("native_static"), NativePlatformInfo): +class NativeMixed(MixedMixin("native_static"), NativeConfigInfo): name = "native_mixed" static = False compatible_hosts = ["fedora", "debian", "Darwin"] diff --git a/kiwixbuild/platforms/neutral.py b/kiwixbuild/configs/neutral.py similarity index 66% rename from kiwixbuild/platforms/neutral.py rename to kiwixbuild/configs/neutral.py index 7315c3a..f5ae53e 100644 --- a/kiwixbuild/platforms/neutral.py +++ b/kiwixbuild/configs/neutral.py @@ -1,7 +1,7 @@ -from .base import PlatformInfo +from .base import ConfigInfo -class NeutralPlatformInfo(PlatformInfo): +class NeutralConfigInfo(ConfigInfo): name = "neutral" static = "" compatible_hosts = ["fedora", "debian", "Darwin"] diff --git a/kiwixbuild/platforms/wasm.py b/kiwixbuild/configs/wasm.py similarity index 97% rename from kiwixbuild/platforms/wasm.py rename to kiwixbuild/configs/wasm.py index de743d7..ff0503e 100644 --- a/kiwixbuild/platforms/wasm.py +++ b/kiwixbuild/configs/wasm.py @@ -1,10 +1,10 @@ -from .base import PlatformInfo +from .base import ConfigInfo from kiwixbuild.utils import pj from kiwixbuild._global import get_target_step -class WasmPlatformInfo(PlatformInfo): +class WasmConfigInfo(ConfigInfo): name = "wasm" static = True build = "wasm" diff --git a/kiwixbuild/platforms/win32.py b/kiwixbuild/configs/win32.py similarity index 94% rename from kiwixbuild/platforms/win32.py rename to kiwixbuild/configs/win32.py index 4e41ddd..6b665e7 100644 --- a/kiwixbuild/platforms/win32.py +++ b/kiwixbuild/configs/win32.py @@ -1,11 +1,11 @@ import subprocess -from .base import PlatformInfo +from .base import ConfigInfo from kiwixbuild.utils import which, pj from kiwixbuild._global import neutralEnv -class Win32PlatformInfo(PlatformInfo): +class Win32ConfigInfo(ConfigInfo): build = "win32" compatible_hosts = ["fedora", "debian"] arch_full = "i686-w64-mingw32" @@ -89,11 +89,11 @@ class Win32PlatformInfo(PlatformInfo): return env -class Win32Dyn(Win32PlatformInfo): +class Win32Dyn(Win32ConfigInfo): name = "win32_dyn" static = False -class Win32Static(Win32PlatformInfo): +class Win32Static(Win32ConfigInfo): name = "win32_static" static = True diff --git a/kiwixbuild/platforms/win64.py b/kiwixbuild/configs/win64.py similarity index 94% rename from kiwixbuild/platforms/win64.py rename to kiwixbuild/configs/win64.py index 62d9d35..10f215a 100644 --- a/kiwixbuild/platforms/win64.py +++ b/kiwixbuild/configs/win64.py @@ -1,11 +1,11 @@ import subprocess -from .base import PlatformInfo +from .base import ConfigInfo from kiwixbuild.utils import which, pj from kiwixbuild._global import neutralEnv -class Win64PlatformInfo(PlatformInfo): +class Win64ConfigInfo(ConfigInfo): extra_libs = [ "-lmingw32", "-lwinmm", @@ -93,11 +93,11 @@ class Win64PlatformInfo(PlatformInfo): return env -class Win64Dyn(Win64PlatformInfo): +class Win64Dyn(Win64ConfigInfo): name = "win64_dyn" static = False -class Win64Static(Win64PlatformInfo): +class Win64Static(Win64ConfigInfo): name = "win64_static" static = True diff --git a/kiwixbuild/dependencies/all_dependencies.py b/kiwixbuild/dependencies/all_dependencies.py index ab0a889..18cbeb7 100644 --- a/kiwixbuild/dependencies/all_dependencies.py +++ b/kiwixbuild/dependencies/all_dependencies.py @@ -12,8 +12,8 @@ class AllBaseDependencies(Dependency): class Builder(NoopBuilder): @classmethod - def get_dependencies(cls, platformInfo, allDeps): - if platformInfo.build == "wasm" or environ.get("OS_NAME") == "bionic": + def get_dependencies(cls, configInfo, allDeps): + if configInfo.build == "wasm" or environ.get("OS_NAME") == "bionic": return ["zlib", "lzma", "zstd", "icu4c", "xapian-core"] base_deps = [ @@ -28,17 +28,14 @@ class AllBaseDependencies(Dependency): "libmicrohttpd", "zim-testing-suite", ] - # Add specific dependencies depending of the platform - if platformInfo.build not in ("android", "iOS"): + # Add specific dependencies depending of the config + if configInfo.build not in ("android", "iOS"): # For zimtools base_deps += ["docoptcpp"] - if platformInfo.build != "win32": + if configInfo.build != "win32": # zimwriterfs base_deps += ["libmagic", "gumbo"] - if ( - platformInfo.build == "native" - and neutralEnv("distname") != "Darwin" - ): + if configInfo.build == "native" and neutralEnv("distname") != "Darwin": # We compile kiwix-desktop only on native and not on `Darwin` # So we need aria2 only there base_deps += ["aria2"] diff --git a/kiwixbuild/dependencies/apple_xcframework.py b/kiwixbuild/dependencies/apple_xcframework.py index 33c179c..7f8b7f7 100644 --- a/kiwixbuild/dependencies/apple_xcframework.py +++ b/kiwixbuild/dependencies/apple_xcframework.py @@ -2,14 +2,14 @@ import os import shutil from pathlib import Path -from kiwixbuild.platforms import PlatformInfo +from kiwixbuild.configs import ConfigInfo from kiwixbuild.utils import pj, run_command from .base import Dependency, NoopSource, Builder as BaseBuilder class AppleXCFramework(Dependency): name = "apple_xcframework" - subPlatformNames = [ + subConfigNames = [ "macOS_x86_64", "macOS_arm64_static", "iOS_arm64", @@ -20,34 +20,32 @@ class AppleXCFramework(Dependency): class Builder(BaseBuilder): @property - def all_subplatforms(self): - return self.buildEnv.platformInfo.subPlatformNames + def all_subconfigs(self): + return self.buildEnv.configInfo.subConfigNames @property - def macos_subplatforms(self): + def macos_subconfigs(self): return [ - target for target in self.all_subplatforms if target.startswith("macOS") + target for target in self.all_subconfigs if target.startswith("macOS") ] @property - def iossimulator_subplatforms(self): + def iossimulator_subconfigs(self): return [ target - for target in self.all_subplatforms + for target in self.all_subconfigs if target.startswith("iOSSimulator") ] @property - def ios_subplatforms(self): + def ios_subconfigs(self): return [ - target for target in self.all_subplatforms if target.startswith("iOS_") + target for target in self.all_subconfigs if target.startswith("iOS_") ] @classmethod - def get_dependencies(cls, platfomInfo, alldeps): - return [ - (target, "libkiwix") for target in AppleXCFramework.subPlatformNames - ] + def get_dependencies(cls, configInfo, alldeps): + return [(target, "libkiwix") for target in AppleXCFramework.subConfigNames] @property def final_path(self): @@ -62,11 +60,11 @@ class AppleXCFramework(Dependency): def _merge_libs(self, context): """create merged.a in all targets to bundle all static archives""" xcf_libs = [] - for target in self.all_subplatforms: + for target in self.all_subconfigs: static_ars = [] - plt = PlatformInfo.get_platform(target) - lib_dir = pj(plt.buildEnv.install_dir, "lib") + cfg = ConfigInfo.get_config(target) + lib_dir = pj(cfg.buildEnv.install_dir, "lib") static_ars = [str(f) for f in Path(lib_dir).glob("*.a")] # create merged.a from all *.a in install_dir/lib @@ -74,17 +72,17 @@ class AppleXCFramework(Dependency): run_command(command, lib_dir, context) # will be included in xcframework - if target in self.ios_subplatforms: + if target in self.ios_subconfigs: xcf_libs.append(pj(lib_dir, "merged.a")) return xcf_libs - def make_fat_with(self, platforms, folder_name, context): - """create fat merged.a in {folder_name} install/lib with {platforms} archs""" + def make_fat_with(self, configs, folder_name, context): + """create fat merged.a in {folder_name} install/lib with {configs}""" libs = [] - for target in platforms: - plt = PlatformInfo.get_platform(target) - libs.append(pj(plt.buildEnv.install_dir, "lib", "merged.a")) + for target in configs: + cfg = ConfigInfo.get_config(target) + libs.append(pj(cfg.buildEnv.install_dir, "lib", "merged.a")) fat_dir = pj(self.buildEnv.build_dir, folder_name) os.makedirs(fat_dir, exist_ok=True) @@ -97,14 +95,14 @@ class AppleXCFramework(Dependency): def _build_xcframework(self, xcf_libs, context): # create xcframework - ref_plat = PlatformInfo.get_platform(self.macos_subplatforms[0]) + ref_conf = ConfigInfo.get_config(self.macos_subconfigs[0]) command = ["xcodebuild", "-create-xcframework"] for lib in xcf_libs: command += [ "-library", lib, "-headers", - pj(ref_plat.buildEnv.install_dir, "include"), + pj(ref_conf.buildEnv.install_dir, "include"), ] command += ["-output", self.final_path] run_command(command, self.buildEnv.build_dir, context) @@ -116,13 +114,13 @@ class AppleXCFramework(Dependency): xcf_libs += self.command( "make_macos_fat", self.make_fat_with, - self.macos_subplatforms, + self.macos_subconfigs, "macOS_fat", ) xcf_libs += self.command( "make_simulator_fat", self.make_fat_with, - self.iossimulator_subplatforms, + self.iossimulator_subconfigs, "iOS-simulator_fat", ) self.command("build_xcframework", self._build_xcframework, xcf_libs) diff --git a/kiwixbuild/dependencies/base.py b/kiwixbuild/dependencies/base.py index 91e4a21..dbe5ef2 100644 --- a/kiwixbuild/dependencies/base.py +++ b/kiwixbuild/dependencies/base.py @@ -237,7 +237,7 @@ class Builder: self.buildEnv = buildEnv @classmethod - def get_dependencies(cls, platformInfo, allDeps): + def get_dependencies(cls, configInfo, allDeps): return cls.dependencies @property @@ -323,9 +323,9 @@ class Builder: cross_compilers=cross_compilers, cross_path=cross_path, ) - for dep in self.get_dependencies(self.buildEnv.platformInfo, False): + for dep in self.get_dependencies(self.buildEnv.configInfo, False): try: - builder = get_target_step(dep, self.buildEnv.platformInfo.name) + builder = get_target_step(dep, self.buildEnv.configInfo.name) builder.set_env(env) except KeyError: # Some target may be missing (installed by a package, ...) @@ -382,7 +382,7 @@ class MakeBuilder(Builder): @property def make_install_targets(self): - if self.buildEnv.platformInfo.build in ("iOS", "wasm"): + if self.buildEnv.configInfo.build in ("iOS", "wasm"): yield "install" else: yield "install-strip" @@ -390,12 +390,12 @@ class MakeBuilder(Builder): @property def all_configure_options(self): yield from self.configure_options - if self.buildEnv.platformInfo.static: + if self.buildEnv.configInfo.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 self.buildEnv.configInfo.configure_options yield from ("--prefix", self.buildEnv.install_dir) yield from ("--libdir", pj(self.buildEnv.install_dir, self.buildEnv.libprefix)) @@ -532,7 +532,7 @@ class MesonBuilder(Builder): @property def library_type(self): - return "static" if self.buildEnv.platformInfo.static else "shared" + return "static" if self.buildEnv.configInfo.static else "shared" def _configure(self, context): context.try_skip(self.build_path) @@ -569,9 +569,9 @@ class MesonBuilder(Builder): def _test(self, context): context.try_skip(self.build_path) - if self.buildEnv.platformInfo.build == "android" or ( - self.buildEnv.platformInfo.build != "native" - and not self.buildEnv.platformInfo.static + if self.buildEnv.configInfo.build == "android" or ( + self.buildEnv.configInfo.build != "native" + and not self.buildEnv.configInfo.static ): raise SkipCommand() command = [*neutralEnv("mesontest_command"), "--verbose", *self.test_options] diff --git a/kiwixbuild/dependencies/icu4c.py b/kiwixbuild/dependencies/icu4c.py index 816d4e3..20993f4 100644 --- a/kiwixbuild/dependencies/icu4c.py +++ b/kiwixbuild/dependencies/icu4c.py @@ -58,8 +58,8 @@ class Icu(Dependency): make_install_targets = ["install"] @classmethod - def get_dependencies(cls, platformInfo, allDeps): - plt = "native_static" if platformInfo.static else "native_dyn" + def get_dependencies(cls, configInfo, allDeps): + plt = "native_static" if configInfo.static else "native_dyn" return [(plt, "icu4c")] @property @@ -71,14 +71,14 @@ class Icu(Dependency): yield "--enable-rpath" yield "--disable-icuio" yield "--disable-layoutex" - platformInfo = self.buildEnv.platformInfo - if platformInfo.build != "native": + configInfo = self.buildEnv.configInfo + if configInfo.build != "native": icu_native_builder = get_target_step( - "icu4c", "native_static" if platformInfo.static else "native_dyn" + "icu4c", "native_static" if configInfo.static else "native_dyn" ) yield f"--with-cross-build={icu_native_builder.build_path}" yield "--disable-tools" - if platformInfo.build in ("android", "wasm"): + if configInfo.build in ("android", "wasm"): yield "--with-data-packaging=archive" def set_env(self, env): @@ -87,7 +87,7 @@ class Icu(Dependency): ) def _post_configure_script(self, context): - if self.buildEnv.platformInfo.build != "wasm": + if self.buildEnv.configInfo.build != "wasm": context.skip() context.try_skip(self.build_path) for line in fileinput.input(pj(self.build_path, "Makefile"), inplace=True): diff --git a/kiwixbuild/dependencies/ios_fat_lib.py b/kiwixbuild/dependencies/ios_fat_lib.py index 742e339..a0b74f2 100644 --- a/kiwixbuild/dependencies/ios_fat_lib.py +++ b/kiwixbuild/dependencies/ios_fat_lib.py @@ -1,6 +1,6 @@ import os -from kiwixbuild.platforms import PlatformInfo +from kiwixbuild.configs import ConfigInfo from kiwixbuild.utils import pj, copy_tree, run_command from kiwixbuild._global import option from .base import Dependency, NoopSource, Builder as BaseBuilder @@ -18,7 +18,7 @@ class IOSFatLib(Dependency): return [("iOS_{}".format(arch), base_target) for arch in option("ios_arch")] def _copy_headers(self, context): - plt = PlatformInfo.get_platform("iOS_{}".format(option("ios_arch")[0])) + plt = ConfigInfo.get_config("iOS_{}".format(option("ios_arch")[0])) include_src = pj(plt.buildEnv.install_dir, "include") include_dst = pj(self.buildEnv.install_dir, "include") copy_tree(include_src, include_dst) @@ -26,7 +26,7 @@ class IOSFatLib(Dependency): def _merge_libs(self, context): lib_dirs = [] for arch in option("ios_arch"): - plt = PlatformInfo.get_platform("iOS_{}".format(arch)) + plt = ConfigInfo.get_config("iOS_{}".format(arch)) lib_dirs.append(pj(plt.buildEnv.install_dir, "lib")) libs = [] for f in os.listdir(lib_dirs[0]): diff --git a/kiwixbuild/dependencies/kiwix_desktop.py b/kiwixbuild/dependencies/kiwix_desktop.py index 5b1eab5..c72ff59 100644 --- a/kiwixbuild/dependencies/kiwix_desktop.py +++ b/kiwixbuild/dependencies/kiwix_desktop.py @@ -18,11 +18,11 @@ class KiwixDesktop(Dependency): @property def configure_options(self): - if self.buildEnv.platformInfo.name == "flatpak": + if self.buildEnv.configInfo.name == "flatpak": yield "QMAKE_INCDIR+=/app/include/QtWebEngine" yield "QMAKE_INCDIR+=/app/include/QtWebEngineCore" yield "QMAKE_INCDIR+=/app/include/QtWebEngineWidgets" else: yield f"PREFIX={self.buildEnv.install_dir}" - if self.buildEnv.platformInfo.static: + if self.buildEnv.configInfo.static: yield "CONFIG+=static" diff --git a/kiwixbuild/dependencies/kiwix_tools.py b/kiwixbuild/dependencies/kiwix_tools.py index 8895b08..615b749 100644 --- a/kiwixbuild/dependencies/kiwix_tools.py +++ b/kiwixbuild/dependencies/kiwix_tools.py @@ -14,5 +14,5 @@ class KiwixTools(Dependency): @property def configure_options(self): - if self.buildEnv.platformInfo.static: + if self.buildEnv.configInfo.static: yield "-Dstatic-linkage=true" diff --git a/kiwixbuild/dependencies/libkiwix.py b/kiwixbuild/dependencies/libkiwix.py index e97dbff..573cb23 100644 --- a/kiwixbuild/dependencies/libkiwix.py +++ b/kiwixbuild/dependencies/libkiwix.py @@ -29,25 +29,25 @@ class Libkiwix(Dependency): @property def build_type(self): - if self.buildEnv.platformInfo.build == "android": + if self.buildEnv.configInfo.build == "android": return "debug" return super().build_type @property def configure_options(self): - platformInfo = self.buildEnv.platformInfo - if platformInfo.build == "android": + configInfo = self.buildEnv.configInfo + if configInfo.build == "android": yield "-Dstatic-linkage=true" yield "-Dwerror=false" - if platformInfo.build == "iOS": + if configInfo.build == "iOS": yield "-Db_bitcode=true" - if platformInfo.name == "flatpak": + if configInfo.name == "flatpak": yield "--wrap-mode=nodownload" - if platformInfo.mixed and option("target") == "libkiwix": + if configInfo.mixed and option("target") == "libkiwix": yield "-Dstatic-linkage=true" @property def library_type(self): - if self.buildEnv.platformInfo.build == "android": + if self.buildEnv.configInfo.build == "android": return "shared" return super().library_type diff --git a/kiwixbuild/dependencies/libmagic.py b/kiwixbuild/dependencies/libmagic.py index 165f5e9..18d2f9d 100644 --- a/kiwixbuild/dependencies/libmagic.py +++ b/kiwixbuild/dependencies/libmagic.py @@ -31,14 +31,14 @@ class LibMagic(Dependency): yield "--disable-lzlib" @classmethod - def get_dependencies(cls, platformInfo, allDeps): - if platformInfo.build != "native": + def get_dependencies(cls, configInfo, allDeps): + if configInfo.build != "native": return [("native_static", "libmagic")] return [] def _compile(self, context): - platformInfo = self.buildEnv.platformInfo - if platformInfo.build == "native": + configInfo = self.buildEnv.configInfo + if configInfo.build == "native": return super()._compile(context) context.try_skip(self.build_path) command = ["make", "-j4", *self.make_targets, *self.make_options] diff --git a/kiwixbuild/dependencies/libzim.py b/kiwixbuild/dependencies/libzim.py index 48dee52..804cd38 100644 --- a/kiwixbuild/dependencies/libzim.py +++ b/kiwixbuild/dependencies/libzim.py @@ -16,37 +16,37 @@ class Libzim(Dependency): @property def build_type(self): - if self.buildEnv.platformInfo.build == "android": + if self.buildEnv.configInfo.build == "android": return "debug" return super().build_type @classmethod - def get_dependencies(cls, platformInfo, allDeps): + def get_dependencies(cls, configInfo, allDeps): deps = ["lzma", "zstd", "xapian-core", "icu4c"] - if platformInfo.name not in ("flatpak", "wasm"): + if configInfo.name not in ("flatpak", "wasm"): deps.append("zim-testing-suite") return deps @property def configure_options(self): - platformInfo = self.buildEnv.platformInfo - if platformInfo.build == "android": + configInfo = self.buildEnv.configInfo + if configInfo.build == "android": yield "-DUSE_BUFFER_HEADER=false" yield "-Dstatic-linkage=true" - if platformInfo.mixed and option("target") == "libzim": + if configInfo.mixed and option("target") == "libzim": yield "-Dstatic-linkage=true" - if platformInfo.name == "flatpak": + if configInfo.name == "flatpak": yield "--wrap-mode=nodownload" yield "-Dtest_data_dir=none" - if platformInfo.name == "wasm": + if configInfo.name == "wasm": yield "-Dexamples=false" yield "-DUSE_MMAP=false" - if platformInfo.name not in ("flatpak", "wasm"): + if configInfo.name not in ("flatpak", "wasm"): zim_testing_suite = get_target_step("zim-testing-suite", "source") yield "-Dtest_data_dir={}".format(zim_testing_suite.source_path) @property def library_type(self): - if self.buildEnv.platformInfo.build == "android": + if self.buildEnv.configInfo.build == "android": return "shared" return super().library_type diff --git a/kiwixbuild/dependencies/qt.py b/kiwixbuild/dependencies/qt.py index 69e86ef..1a55ae3 100644 --- a/kiwixbuild/dependencies/qt.py +++ b/kiwixbuild/dependencies/qt.py @@ -25,12 +25,12 @@ class Qt(Dependency): @property def all_configure_options(self): yield from self.configure_options - if self.buildEnv.platformInfo.static: + if self.buildEnv.configInfo.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 self.buildEnv.configInfo.configure_options yield from ("-prefix", self.buildEnv.install_dir) yield from ( "-libdir", diff --git a/kiwixbuild/dependencies/tc_android_ndk.py b/kiwixbuild/dependencies/tc_android_ndk.py index 542fca9..3774976 100644 --- a/kiwixbuild/dependencies/tc_android_ndk.py +++ b/kiwixbuild/dependencies/tc_android_ndk.py @@ -34,18 +34,18 @@ class android_ndk(Dependency): return self.target.api @property - def platform(self): + def config(self): return "android-" + self.api @property def arch(self): - return self.buildEnv.platformInfo.arch + return self.buildEnv.configInfo.arch @property def arch_full(self): - return self.buildEnv.platformInfo.arch_full + return self.buildEnv.configInfo.arch_full - def _build_platform(self, context): + def _build_toolchain(self, context): context.try_skip(self.build_path) script = pj(self.source_path, "build/tools/make_standalone_toolchain.py") add_execution_right(script) @@ -85,5 +85,5 @@ class android_ndk(Dependency): add_execution_right(file_path) def build(self): - self.command("build_platform", self._build_platform) + self.command("build_toolchain", self._build_toolchain) self.command("fix_permission_right", self._fix_permission_right) diff --git a/kiwixbuild/dependencies/xapian.py b/kiwixbuild/dependencies/xapian.py index a337f68..aac4fd7 100644 --- a/kiwixbuild/dependencies/xapian.py +++ b/kiwixbuild/dependencies/xapian.py @@ -26,10 +26,10 @@ class Xapian(Dependency): } @classmethod - def get_dependencies(cls, platformInfo, allDeps): + def get_dependencies(cls, configInfo, allDeps): deps = ["zlib", "lzma"] if ( - platformInfo.build in ("win32", "wasm") + configInfo.build in ("win32", "wasm") or neutralEnv("distname") == "Darwin" ): return deps diff --git a/kiwixbuild/dependencies/zim_tools.py b/kiwixbuild/dependencies/zim_tools.py index f44d94c..9e677c8 100644 --- a/kiwixbuild/dependencies/zim_tools.py +++ b/kiwixbuild/dependencies/zim_tools.py @@ -11,16 +11,16 @@ class ZimTools(Dependency): class Builder(MesonBuilder): @classmethod - def get_dependencies(cls, platformInfo, allDeps): + def get_dependencies(cls, configInfo, allDeps): base_deps = ["libzim", "docoptcpp", "mustache"] - if platformInfo.build != "win32": + if configInfo.build != "win32": base_deps += ["libmagic", "gumbo"] return base_deps @property def configure_options(self): # We don't build zimwriterfs on win32, and so we don't have magic - if self.buildEnv.platformInfo.build != "win32": + if self.buildEnv.configInfo.build != "win32": yield f"-Dmagic-install-prefix={self.buildEnv.install_dir}" - if self.buildEnv.platformInfo.static: + if self.buildEnv.configInfo.static: yield "-Dstatic-linkage=true" diff --git a/kiwixbuild/dependencies/zlib.py b/kiwixbuild/dependencies/zlib.py index 7f8539c..b0d712f 100644 --- a/kiwixbuild/dependencies/zlib.py +++ b/kiwixbuild/dependencies/zlib.py @@ -25,14 +25,14 @@ class zlib(Dependency): shutil.copytree(self.source_path, self.build_path) def _configure(self, context): - if self.buildEnv.platformInfo.build == "win32": + if self.buildEnv.configInfo.build == "win32": raise SkipCommand() return super()._configure(context) @property 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 self.static_configure_options if self.buildEnv.configInfo.static else self.dynamic_configure_options yield from ("--prefix", self.buildEnv.install_dir) yield from ( "--libdir", @@ -41,13 +41,13 @@ class zlib(Dependency): @property def make_options(self): - if self.buildEnv.platformInfo.build != "win32": + if self.buildEnv.configInfo.build != "win32": return yield "--makefile" yield "win32/Makefile.gcc" yield "PREFIX=i686-w64-mingw32-", yield "SHARED_MODE={}".format( - "0" if self.buildEnv.platformInfo.static else "1" + "0" if self.buildEnv.configInfo.static else "1" ), yield "INCLUDE_PATH={}".format(pj(self.buildEnv.install_dir, "include")), yield "LIBRARY_PATH={}".format( @@ -57,7 +57,7 @@ class zlib(Dependency): @property def make_targets(self): - if self.buildEnv.platformInfo.static: + if self.buildEnv.configInfo.static: return ["static"] else: return ["shared"] diff --git a/kiwixbuild/flatpak_builder.py b/kiwixbuild/flatpak_builder.py index cb07f62..ea0d934 100644 --- a/kiwixbuild/flatpak_builder.py +++ b/kiwixbuild/flatpak_builder.py @@ -2,7 +2,7 @@ import sys from collections import OrderedDict from .buildenv import * -from .platforms import PlatformInfo +from .configs import ConfigInfo from .utils import remove_duplicates, run_command, StopBuild, Context from .dependencies import Dependency from .packages import PACKAGE_NAME_MAPPERS @@ -77,16 +77,16 @@ GET_REF_URL_API_TEMPLATE = "https://api.github.com/repos{repo}/git/refs/tags/{re class FlatpakBuilder: def __init__(self): self._targets = {} - PlatformInfo.get_platform("neutral", self._targets) - self.platform = PlatformInfo.get_platform("flatpak", self._targets) - if neutralEnv("distname") not in self.platform.compatible_hosts: + ConfigInfo.get_config("neutral", self._targets) + self.config = ConfigInfo.get_config("flatpak", self._targets) + if neutralEnv("distname") not in self.config.compatible_hosts: print( ( - "ERROR: The target platform {} cannot be build on host {}.\n" - "Select another target platform or change your host system." - ).format(self.platform.name, neutralEnv("distname")) + "ERROR: The config {} cannot be build on host {}.\n" + "Select another config or change your host system." + ).format(self.config.name, neutralEnv("distname")) ) - self.targetDefs = self.platform.add_targets(option("target"), self._targets) + self.targetDefs = self.config.add_targets(option("target"), self._targets) def finalize_target_steps(self): steps = [] @@ -94,14 +94,14 @@ class FlatpakBuilder: steps += self.order_steps(targetDef) steps = list(remove_duplicates(steps)) - for pltName in PlatformInfo.all_running_platforms: - plt = PlatformInfo.all_platforms[pltName] - for tlcName in plt.toolchain_names: + for cfgName in ConfigInfo.all_running_configs: + cfg = ConfigInfo.all_configs[cfgName] + for tlcName in cfg.toolchain_names: tlc = Dependency.all_deps[tlcName] - src_plt_step = ("source", tlcName) - add_target_step(src_plt_step, self._targets[src_plt_step]) - blt_plt_step = ("neutral" if tlc.neutral else pltName, tlcName) - add_target_step(blt_plt_step, self._targets[blt_plt_step]) + src_cfg_step = ("source", tlcName) + add_target_step(src_cfg_step, self._targets[src_cfg_step]) + blt_cfg_step = ("neutral" if tlc.neutral else cfgName, tlcName) + add_target_step(blt_cfg_step, self._targets[blt_cfg_step]) for dep in steps: add_target_step(dep, self._targets[dep]) @@ -112,8 +112,8 @@ class FlatpakBuilder: yield from self.order_dependencies(targetDef, _targets) def order_dependencies(self, targetDef, targets): - targetPlatformName, targetName = targetDef - if targetPlatformName == "source": + targetConfigName, targetName = targetDef + if targetConfigName == "source": # Do not try to order sources, they will be added as dep by the # build step two lines later. return @@ -122,27 +122,27 @@ class FlatpakBuilder: except KeyError: return - targetPlatform = PlatformInfo.get_platform(targetPlatformName) - for dep in target.get_dependencies(targetPlatform, True): + targetConfig = ConfigInfo.get_config(targetConfigName) + for dep in target.get_dependencies(targetConfig, True): if isinstance(dep, tuple): - depPlatform, depName = dep + depConfig, depName = dep else: - depPlatform, depName = targetPlatformName, dep - if (depPlatform, depName) in targets: - yield from self.order_dependencies((depPlatform, depName), targets) + depConfig, depName = targetConfigName, dep + if (depConfig, depName) in targets: + yield from self.order_dependencies((depConfig, depName), targets) yield ("source", targetName) yield targetDef def instanciate_steps(self): for stepDef in list(target_steps()): - stepPlatform, stepName = stepDef + stepConfig, stepName = stepDef stepClass = Dependency.all_deps[stepName] - if stepPlatform == "source": + if stepConfig == "source": source = get_target_step(stepDef)(stepClass) add_target_step(stepDef, source) else: source = get_target_step(stepName, "source") - env = PlatformInfo.get_platform(stepPlatform).buildEnv + env = ConfigInfo.get_config(stepConfig).buildEnv builder = get_target_step(stepDef)(stepClass, source, env) add_target_step(stepDef, builder) @@ -206,7 +206,7 @@ class FlatpakBuilder: m["sources"] = temp manifest["modules"] = modules manifest_name = "{}.json".format(MANIFEST["app-id"]) - manifest_path = pj(self.platform.buildEnv.build_dir, manifest_name) + manifest_path = pj(self.config.buildEnv.build_dir, manifest_name) with open(manifest_path, "w") as f: f.write(json.dumps(manifest, indent=4)) @@ -219,13 +219,13 @@ class FlatpakBuilder: for p in source.patches: path = pj(SCRIPT_DIR, "patches", p) os.makedirs( - pj(self.platform.buildEnv.build_dir, "patches"), exist_ok=True + pj(self.config.buildEnv.build_dir, "patches"), exist_ok=True ) - dest = pj(self.platform.buildEnv.build_dir, "patches", p) + dest = pj(self.config.buildEnv.build_dir, "patches", p) copyfile(path, dest) def build(self): - log = pj(self.platform.buildEnv.log_dir, "cmd_build_flatpak.log") + log = pj(self.config.buildEnv.log_dir, "cmd_build_flatpak.log") context = Context("build", log, False) command = [ "flatpak-builder", @@ -241,9 +241,9 @@ class FlatpakBuilder: try: run_command( command, - self.platform.buildEnv.build_dir, + self.config.buildEnv.build_dir, context, - env=self.platform.get_env(), + env=self.config.get_env(), ) context._finalise() except subprocess.CalledProcessError: @@ -252,16 +252,16 @@ class FlatpakBuilder: raise StopBuild() def bundle(self): - log = pj(self.platform.buildEnv.log_dir, "cmd_bundle_flatpak.log") + log = pj(self.config.buildEnv.log_dir, "cmd_bundle_flatpak.log") context = Context("bundle", log, False) app_id = MANIFEST["app-id"] command = ["flatpak", "build-bundle", "repo", f"{app_id}.flatpak", app_id] try: run_command( command, - self.platform.buildEnv.build_dir, + self.config.buildEnv.build_dir, context, - env=self.platform.get_env(), + env=self.config.get_env(), ) context._finalise() except subprocess.CalledProcessError: @@ -274,7 +274,7 @@ class FlatpakBuilder: to_drop = [] for builderDef in self._targets: - platformName, builderName = builderDef + configName, builderName = builderDef packages = package_name_mapper.get(builderName) if packages: to_drop.append(builderDef) @@ -288,16 +288,16 @@ class FlatpakBuilder: # dependencies we already have in the sdk. self._get_packages() self.finalize_target_steps() - print("[SETUP PLATFORMS]") - for platform in PlatformInfo.all_running_platforms.values(): - platform.finalize_setup() - for pltName in PlatformInfo.all_running_platforms: - plt = PlatformInfo.all_platforms[pltName] - for tlcName in plt.toolchain_names: + print("[SETUP TOOLCHAINS]") + for config in ConfigInfo.all_running_configs.values(): + config.finalize_setup() + for cfgName in ConfigInfo.all_running_configs: + cfg = ConfigInfo.all_configs[cfgName] + for tlcName in cfg.toolchain_names: tlc = Dependency.all_deps[tlcName] - builderDef = (pltName, tlcName) + builderDef = (cfgName, tlcName) builder = get_target_step(builderDef) - print("build {} ({}):".format(builder.name, pltName[0])) + print("build {} ({}):".format(builder.name, cfgName[0])) add_target_step(builderDef, builder) builder.build() print("[GENERATE FLATPAK MANIFEST]") @@ -310,8 +310,8 @@ class FlatpakBuilder: # No error, clean intermediate file at end of build if needed. print("[CLEAN]") if option("clean_at_end"): - for platform in PlatformInfo.all_running_platforms.values(): - platform.clean_intermediate_directories() + for config in ConfigInfo.all_running_configs.values(): + config.clean_intermediate_directories() else: print("SKIP") except StopBuild: