Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to configure extra opts per project #1423

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -311,6 +321,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 @@ -386,6 +402,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 @@ -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)
Expand Down