aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2022-03-28 14:49:27 -0700
committerEli Schwartz <eschwartz93@gmail.com>2023-03-09 15:03:03 -0500
commit6dc96e7266613d00bfead7ed7b5fed1ae4fa92e8 (patch)
tree5e90ffb1b16c9e95b5c4283976c8993518cd13e7
parent06453ed7a47895fc8dc4db7cf062deb08dae23ef (diff)
downloadmeson-6dc96e7266613d00bfead7ed7b5fed1ae4fa92e8.zip
meson-6dc96e7266613d00bfead7ed7b5fed1ae4fa92e8.tar.gz
meson-6dc96e7266613d00bfead7ed7b5fed1ae4fa92e8.tar.bz2
build: move all Target attributes to dataclass
We'll want to be able to pass all of these to the initializer, so make them all available.
-rw-r--r--mesonbuild/build.py27
1 files changed, 16 insertions, 11 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index 54edb45..40f6f25 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -14,7 +14,7 @@
from __future__ import annotations
from collections import defaultdict, OrderedDict
-from dataclasses import dataclass, field
+from dataclasses import dataclass, field, InitVar
from functools import lru_cache
import abc
import copy
@@ -514,6 +514,10 @@ class Target(HoldableObject, metaclass=abc.ABCMeta):
build_by_default: bool
for_machine: MachineChoice
environment: environment.Environment
+ install: bool = False
+ build_always_stale: bool = False
+ extra_files: T.List[File] = field(default_factory=list)
+ override_options: InitVar[T.Optional[T.Dict[OptionKey, str]]] = None
@abc.abstractproperty
def typename(self) -> str:
@@ -523,18 +527,20 @@ class Target(HoldableObject, metaclass=abc.ABCMeta):
def type_suffix(self) -> str:
pass
- def __post_init__(self) -> None:
+ def __post_init__(self, overrides: T.Optional[T.Dict[OptionKey, str]]) -> None:
+ if overrides:
+ ovr = {k.evolve(machine=self.for_machine) if k.lang else k: v
+ for k, v in overrides.items()}
+ else:
+ ovr = {}
+ self.options = OptionOverrideProxy(ovr, self.environment.coredata.options, self.subproject)
+ # XXX: this should happen in the interpreter
if has_path_sep(self.name):
# Fix failing test 53 when this becomes an error.
mlog.warning(textwrap.dedent(f'''\
Target "{self.name}" has a path separator in its name.
This is not supported, it can cause unexpected failures and will become
- a hard error in the future.
- '''))
- self.install = False
- self.build_always_stale = False
- self.options = OptionOverrideProxy({}, self.environment.coredata.options, self.subproject)
- self.extra_files = [] # type: T.List[File]
+ a hard error in the future.'''))
# dataclass comparators?
def __lt__(self, other: object) -> bool:
@@ -2440,14 +2446,14 @@ class CustomTarget(Target, CommandBase):
backend: T.Optional['Backend'] = None,
):
# TODO expose keyword arg to make MachineChoice.HOST configurable
- super().__init__(name, subdir, subproject, False, MachineChoice.HOST, environment)
+ super().__init__(name, subdir, subproject, False, MachineChoice.HOST, environment,
+ install, build_always_stale)
self.sources = list(sources)
self.outputs = substitute_values(
outputs, get_filenames_templates_dict(
get_sources_string_names(sources, backend),
[]))
self.build_by_default = build_by_default if build_by_default is not None else install
- self.build_always_stale = build_always_stale
self.capture = capture
self.console = console
self.depend_files = list(depend_files or [])
@@ -2458,7 +2464,6 @@ class CustomTarget(Target, CommandBase):
self.env = env or EnvironmentVariables()
self.extra_depends = list(extra_depends or [])
self.feed = feed
- self.install = install
self.install_dir = list(install_dir or [])
self.install_mode = install_mode
self.install_tag = _process_install_tag(install_tag, len(self.outputs))