Skip to content

Commit

Permalink
Merge pull request #1423 from DjLegolas/add-extra-opts-param
Browse files Browse the repository at this point in the history
Add ability to configure extra opts per project
  • Loading branch information
danyeaw authored Jan 8, 2025
2 parents 5f9082a + 9eecd77 commit aa21d8b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
19 changes: 18 additions & 1 deletion gvsbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from enum import Enum
from pathlib import Path
from typing import List
from typing import Dict, List

import typer

Expand Down Expand Up @@ -59,6 +59,16 @@ def __get_projects_to_build(opts):
return to_build


def __parse_extra_opts(extra_opts: List[str]) -> Dict[str, List[str]]:
if extra_opts is None:
return {}
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"
Expand Down Expand Up @@ -304,6 +314,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 <project>:<option1>[;<option1>...]",
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.",
Expand Down Expand Up @@ -379,6 +395,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

Expand Down
9 changes: 9 additions & 0 deletions gvsbuild/utils/base_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}")
Expand Down
3 changes: 2 additions & 1 deletion gvsbuild/utils/base_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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])
Expand Down
2 changes: 2 additions & 0 deletions gvsbuild/utils/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,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)
Expand Down

0 comments on commit aa21d8b

Please sign in to comment.