From 44cb569fd538916f5fe230ef86afe47fbf49b805 Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Sat, 31 Aug 2024 10:01:20 +0300 Subject: [PATCH] Add ability to configure extra opts per project Some users might want to be able to add additional options to the compilation command of each project. With this, we add the `--extra-opts` build option which appends the passed option to a project's build command line. The structure is: `----extra-opts --extra_opts :[;...]` --- gvsbuild/build.py | 17 ++++++++++++++++- gvsbuild/utils/base_builders.py | 9 +++++++++ gvsbuild/utils/base_project.py | 3 ++- gvsbuild/utils/builder.py | 2 ++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/gvsbuild/build.py b/gvsbuild/build.py index 520b41d7b..2986dab5c 100644 --- a/gvsbuild/build.py +++ b/gvsbuild/build.py @@ -15,7 +15,7 @@ from enum import Enum from pathlib import Path -from typing import List +from typing import Dict, List import typer @@ -59,6 +59,14 @@ def __get_projects_to_build(opts): return to_build +def __parse_extra_opts(extra_opts: List[str]) -> Dict[str, List[str]]: + parsed_opts = {} + for eo in extra_opts: + project, opts = eo.split(":") + parsed_opts[project] = opts.split(";") + return parsed_opts + + class Platform(str, Enum): x64 = "x64" x86 = "x86" @@ -311,6 +319,12 @@ def build( help="Command line options to pass to cargo", rich_help_panel="Options to Pass to Build Systems", ), + extra_opts: List[str] = typer.Option( + None, + help="Additional command line options to pass to specific project." + " Example: --extra_opts :[;...]", + rich_help_panel="Options to Pass to Build Systems", + ), git_expand_dir: Path = typer.Option( None, help="The directory where the projects from git are expanded and updated.", @@ -386,6 +400,7 @@ def build( opts.log_single = log_single opts.cargo_opts = cargo_opts opts.ninja_opts = ninja_opts + opts.extra_opts = __parse_extra_opts(extra_opts) opts.capture_out = capture_out opts.print_out = print_out diff --git a/gvsbuild/utils/base_builders.py b/gvsbuild/utils/base_builders.py index 7191c732c..cd193d2dd 100644 --- a/gvsbuild/utils/base_builders.py +++ b/gvsbuild/utils/base_builders.py @@ -68,6 +68,9 @@ def _setup_meson_and_ninja(self, ninja_build, meson_params, add_path): add_opts += f"--buildtype {build_type}" if meson_params: add_opts += f" {meson_params}" + if self.extra_opts: + extra_opts = " ".join(self.extra_opts) + add_opts += f" {extra_opts}" # python meson.py src_dir ninja_build_dir --prefix gtk_bin options meson = Project.get_tool_executable("meson") python = Path(sys.executable) @@ -104,6 +107,9 @@ def build( cmd = f'cmake -G "{cmake_gen}" -DCMAKE_INSTALL_PREFIX="%(pkg_dir)s" -DGTK_DIR="%(gtk_dir)s" -DCMAKE_BUILD_TYPE={cmake_config}' if cmake_params: cmd += f" {cmake_params}" + if self.extra_opts: + extra_opts = " ".join(self.extra_opts) + cmd += f" {extra_opts}" if use_ninja and out_of_source is None: # For ninja the default is build out of source out_of_source = True @@ -167,6 +173,9 @@ def build(self, cargo_params=None, make_tests=False): else: folder = "debug" + if self.extra_opts: + params.extend(self.extra_opts) + cargo_build = os.path.join(self.build_dir, "cargo-build") params.append(f"--target-dir={cargo_build}") diff --git a/gvsbuild/utils/base_project.py b/gvsbuild/utils/base_project.py index 4baa0bd77..ce070bfe5 100644 --- a/gvsbuild/utils/base_project.py +++ b/gvsbuild/utils/base_project.py @@ -73,6 +73,7 @@ def __init__(self): self.log_single = False self.cargo_opts = None self.ninja_opts = None + self.extra_opts = None self.capture_out = False self.print_out = False self.git_expand_dir = None @@ -108,7 +109,7 @@ def __init__(self, name, **kwargs): self.extra_env = {} self.tag = None self.repo_url = None - self.archive_filename = None + self.extra_opts = None for k in kwargs: setattr(self, k, kwargs[k]) diff --git a/gvsbuild/utils/builder.py b/gvsbuild/utils/builder.py index 3d07882a1..5642789d4 100644 --- a/gvsbuild/utils/builder.py +++ b/gvsbuild/utils/builder.py @@ -480,6 +480,8 @@ def preprocess(self): proj.mark_file_calc() if self.opts.clean: proj.clean = True + if self.opts.extra_opts and proj.name in self.opts.extra_opts: + proj.extra_opts = self.opts.extra_opts[proj.name] for proj in Project.list_projects(): self.__compute_deps(proj)