Skip to content

Commit 1d04d09

Browse files
committed
build: recreate PerMachine object in copies
Recursively copy the value if it is a collection; this ensures that values are not overwritten until merge() is called. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent d799043 commit 1d04d09

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

mesonbuild/build.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ class StaticLibraryKeywordArguments(BuildTargetKeywordArguments, total=False):
132132
pic: bool
133133
prelink: bool
134134

135+
_T = T.TypeVar('_T')
136+
135137
DEFAULT_STATIC_LIBRARY_NAMES: T.Mapping[str, T.Tuple[str, str]] = {
136138
'unix': ('lib', 'a'),
137139
'windows': ('', 'lib'),
@@ -404,16 +406,26 @@ def get_custom_targets(self) -> OrderedDict[str, CustomTarget]:
404406
return custom_targets
405407

406408
def copy(self) -> Build:
409+
def copy_value(v: _T) -> _T:
410+
if isinstance(v, PerMachine):
411+
return PerMachine(build=copy_value(v.build), host=copy_value(v.host))
412+
if isinstance(v, (list, dict, set, OrderedDict)):
413+
return v.copy()
414+
return v
415+
407416
other = Build.__new__(Build)
408417
for k, v in self.__dict__.items():
409-
if isinstance(v, (list, dict, set, OrderedDict)):
410-
v = v.copy()
411-
setattr(other, k, v)
418+
setattr(other, k, copy_value(v))
412419
return other
413420

414421
def merge(self, other: Build) -> None:
415422
for k, v in other.__dict__.items():
416-
setattr(self, k, v)
423+
if isinstance(v, PerMachine):
424+
dest = getattr(self, k)
425+
dest.build = v.build
426+
dest.host = v.host
427+
else:
428+
setattr(self, k, v)
417429

418430
def get_static_linker(self, for_machine: MachineChoice) -> T.Optional[StaticLinker]:
419431
for_machine = for_machine if self.environment.is_cross_build() else MachineChoice.HOST

mesonbuild/interpreter/dependencyfallbacks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
from .interpreter import Interpreter
2121
from .kwargs import DoSubproject
2222
from ..dependencies.base import DependencyObjectKWs
23+
from ..mesonlib import MachineChoice
2324
from ..options import ElementaryOptionValues, OptionDict
2425
from .interpreterobjects import SubprojectHolder
25-
from .mesonlib import MachineChoice
2626

2727
CandidateType: TypeAlias = T.Tuple[T.Callable[[DependencyObjectKWs, str, DoSubproject], T.Optional[Dependency]], str]
2828

0 commit comments

Comments
 (0)