diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2022-03-28 14:42:56 -0700 |
---|---|---|
committer | Eli Schwartz <eschwartz93@gmail.com> | 2023-03-09 15:03:03 -0500 |
commit | 4cf5ad24632bcd11c008e64105ca11fa06c21332 (patch) | |
tree | 38b9336f2f952be344dbbc4362b339fe20b9f039 | |
parent | 853c16cbed6628eee80aa98e74988922518dab29 (diff) | |
download | meson-4cf5ad24632bcd11c008e64105ca11fa06c21332.zip meson-4cf5ad24632bcd11c008e64105ca11fa06c21332.tar.gz meson-4cf5ad24632bcd11c008e64105ca11fa06c21332.tar.bz2 |
build: make Target an abstract properties instead of doing hasattr
checks
-rw-r--r-- | mesonbuild/build.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 62278ce..13491eb 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -16,6 +16,7 @@ from __future__ import annotations from collections import defaultdict, OrderedDict from dataclasses import dataclass, field from functools import lru_cache +import abc import copy import hashlib import itertools, pathlib @@ -505,9 +506,7 @@ class StructuredSources(HoldableObject): @dataclass(eq=False) -class Target(HoldableObject): - - # TODO: should Target be an abc.ABCMeta? +class Target(HoldableObject, metaclass=abc.ABCMeta): name: str subdir: str @@ -516,6 +515,14 @@ class Target(HoldableObject): for_machine: MachineChoice environment: environment.Environment + @abc.abstractproperty + def typename(self) -> str: + pass + + @abc.abstractmethod + def type_suffix(self) -> str: + pass + def __post_init__(self) -> None: if has_path_sep(self.name): # Fix failing test 53 when this becomes an error. @@ -528,8 +535,6 @@ class Target(HoldableObject): self.build_always_stale = False self.options = OptionOverrideProxy({}, self.environment.coredata.options, self.subproject) self.extra_files = [] # type: T.List[File] - if not hasattr(self, 'typename'): - raise RuntimeError(f'Target type is not set for target class "{type(self).__name__}". This is a bug') # dataclass comparators? def __lt__(self, other: object) -> bool: |