diff --git a/kiwixbuild/buildenv.py b/kiwixbuild/buildenv.py index c4bcacb1..281a8fd2 100644 --- a/kiwixbuild/buildenv.py +++ b/kiwixbuild/buildenv.py @@ -21,16 +21,20 @@ def __init__(self): self.log_dir): os.makedirs(d, exist_ok=True) self.detect_platform() - self.ninja_command = self._detect_ninja() - if not self.ninja_command: - sys.exit("ERROR: ninja command not found.") - self.meson_command = self._detect_meson() - if not self.meson_command: - sys.exit("ERROR: meson command not found.") - self.qmake_command = self._detect_qmake() - if not self.qmake_command: - print("WARNING: qmake command not found.", file=sys.stderr) + self.ninja_command = self._detect_command( + 'ninja', + default=[['ninja'], ['ninja-build']]) + self.meson_command = self._detect_command( + 'meson', + default= [['meson.py'], ['meson']]) self.mesontest_command = [*self.meson_command, "test"] + self.patch_command = self._detect_command('patch') + self.git_command = self._detect_command('git') + self.svn_command = self._detect_command('svn') + self.make_command = self._detect_command('make') + self.cmake_command = self._detect_command('cmake') + self.qmake_command = self._detect_command('qmake', required=False) + def detect_platform(self): _platform = platform.system() @@ -49,28 +53,29 @@ def detect_platform(self): def download(self, what, where=None): where = where or self.archive_dir download_remote(what, where) - - def _detect_binary(self, *bin_variants): - for n in bin_variants: + + + def _detect_command(self, name, default=None, options=['--version'], required=True): + if default is None: + default = [[name]] + env_key = 'KBUILD_{}_COMMAND'.format(name.upper()) + if env_key in os.environ: + default = [os.environ[env_key].split()] + default + for command in default: try: - retcode = subprocess.check_call([n, '--version'], + retcode = subprocess.check_call(command + options, stdout=subprocess.DEVNULL) - except (FileNotFoundError, PermissionError): + except (FileNotFoundError, PermissionError, OSError): # Doesn't exist in PATH or isn't executable continue if retcode == 0: - return [n] - - - def _detect_ninja(self): - return self._detect_binary('ninja', 'ninja-build') - - def _detect_meson(self): - return self._detect_binary('meson.py', 'meson') - - def _detect_qmake(self): - return self._detect_binary('qmake-qt5', 'qmake') - + return command + else: + if required: + sys.exit("ERROR: {} command not found".format(name)) + else: + print("WARNING: {} command not found".format(name)) + return ["{}_NOT_FOUND".format(name.upper())] class BuildEnv: def __init__(self, platformInfo): diff --git a/kiwixbuild/dependencies/base.py b/kiwixbuild/dependencies/base.py index 1ead98c9..5b2e8329 100644 --- a/kiwixbuild/dependencies/base.py +++ b/kiwixbuild/dependencies/base.py @@ -71,7 +71,7 @@ def _patch(self, context): context.try_skip(self.source_path) for p in self.patches: patch_file_path = pj(SCRIPT_DIR, 'patches', p) - patch_command = ["patch", "-p1", "-i", patch_file_path] + patch_command = [*neutralEnv('patch_command'), "-p1", "-i", patch_file_path] run_command(patch_command, self.source_path, context) def command(self, name, function, *args): @@ -170,19 +170,19 @@ def git_ref(self): def _git_init(self, context): if option('fast_clone') and self.force_full_clone == False: - command = ["git", "clone" , "--depth=1", "--branch", self.git_ref, self.git_remote, self.source_dir] + command = [*neutralEnv('git_command'), "clone" , "--depth=1", "--branch", self.git_ref, self.git_remote, self.source_dir] run_command(command, neutralEnv('source_dir'), context) else: - command = ["git", "clone", self.git_remote, self.source_dir] + command = [*neutralEnv('git_command'), "clone", self.git_remote, self.source_dir] run_command(command, neutralEnv('source_dir'), context) - command = ["git", "checkout", self.git_ref] + command = [*neutralEnv('git_command'), "checkout", self.git_ref] run_command(command, self.git_path, context) def _git_update(self, context): - command = ["git", "fetch", "origin", self.git_ref] + command = [*neutralEnv('git_command'), "fetch", "origin", self.git_ref] run_command(command, self.git_path, context) try: - command = ["git", "merge", "--ff-only", f"origin/{self.git_ref}"] + command = [*neutralEnv('git_command'), "merge", "--ff-only", f"origin/{self.git_ref}"] run_command(command, self.git_path, context) except subprocess.CalledProcessError: raise WarningMessage("Cannot update, please check log for information") @@ -209,7 +209,7 @@ def _svn_export(self, context): if os.path.exists(self.svn_path): raise SkipCommand() command = [ - "svn", "export", + *neutralEnv('svn_command'), "export", self.svn_remote, self.svn_dir ] run_command(command, neutralEnv('source_dir'), context) @@ -408,7 +408,8 @@ def _compile(self, context): context.try_skip(self.build_path) command = [ *self.buildEnv.make_wrapper, - "make", "-j4", + *neutralEnv('make_command'), + "-j4", *self.make_targets, *self.make_options ] @@ -419,7 +420,7 @@ def _install(self, context): context.try_skip(self.build_path) command = [ *self.buildEnv.make_wrapper, - "make", + *neutralEnv('make_command'), *self.make_install_targets, *self.make_options ] @@ -430,7 +431,8 @@ def _make_dist(self, context): context.try_skip(self.build_path) command = [ *self.buildEnv.make_wrapper, - "make", "dist" + *neutralEnv('make_command'), + "dist" ] env = self.get_env(cross_comp_flags=True, cross_compilers=True, cross_path=True) run_command(command, self.build_path, context, env=env) @@ -445,7 +447,7 @@ def _configure(self, context): if not self.target.force_native_build and self.buildEnv.cmake_crossfile: cross_options += [f"-DCMAKE_TOOLCHAIN_FILE={self.buildEnv.cmake_crossfile}"] command = [ - "cmake", + *neutralEnv('cmake_command'), *self.configure_options, "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON", f"-DCMAKE_INSTALL_PREFIX={self.buildEnv.install_dir}", @@ -476,10 +478,10 @@ def env_options(self): def _configure(self, context): context.try_skip(self.build_path) command = [ - *neutralEnv('qmake_command'), - *self.configure_options, - *self.env_options, - self.source_path, + "qmake", + *self.configure_options, + *self.env_options, + self.source_path ] env = self.get_env(cross_comp_flags=True, cross_compilers=False, cross_path=True) self.set_configure_env(env) @@ -487,7 +489,7 @@ def _configure(self, context): def _make_dist(self, context): command = [ - "git", "archive", + *neutralEnv('git_command'), "archive", "-o", f"{self.build_path}/{self.target_full_name()}.tar.gz", f"--prefix={self.target_full_name()}/", "HEAD"