diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 798e26ba1a66..7c42ffad34bf 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -2082,6 +2082,8 @@ def compile_target_to_generator(self, target: build.CompileTarget) -> build.Gene target.output_templ, target.depends) def is_unity(self, target: build.BuildTarget) -> bool: + if isinstance(target, build.CompileTarget): + return False val = self.get_target_option(target, 'unity') if val == 'on': return True diff --git a/mesonbuild/build.py b/mesonbuild/build.py index fc1d31ef3e1e..81ba48dbae65 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -1014,7 +1014,7 @@ def process_link_depends(self, sources): 'Link_depends arguments must be strings, Files, ' 'or a Custom Target, or lists thereof.') - def extract_objects(self, srclist: T.List[T.Union['FileOrString', 'GeneratedTypes']]) -> ExtractedObjects: + def extract_objects(self, srclist: T.List[T.Union['FileOrString', 'GeneratedTypes']], is_unity: bool) -> ExtractedObjects: sources_set = set(self.sources) generated_set = set(self.generated) @@ -1037,7 +1037,11 @@ def extract_objects(self, srclist: T.List[T.Union['FileOrString', 'GeneratedType obj_gen.append(src) else: raise MesonException(f'Object extraction arguments must be strings, Files or targets (got {type(src).__name__}).') - return ExtractedObjects(self, obj_src, obj_gen) + eobjs = ExtractedObjects(self, obj_src, obj_gen) + if is_unity: + eobjs.check_unity_compatible() + return eobjs + def extract_all_objects(self, recursive: bool = True) -> ExtractedObjects: return ExtractedObjects(self, self.sources, self.generated, self.objects, diff --git a/mesonbuild/interpreter/interpreterobjects.py b/mesonbuild/interpreter/interpreterobjects.py index 87fe13dff658..7f298252bf28 100644 --- a/mesonbuild/interpreter/interpreterobjects.py +++ b/mesonbuild/interpreter/interpreterobjects.py @@ -931,10 +931,10 @@ def extract_objects_method(self, args: T.Tuple[T.List[T.Union[mesonlib.FileOrStr unity_value = self.interpreter.coredata.get_option_for_target(tobj, "unity") if unity_value == 'on' or \ (unity_value == 'subprojects' and tobj.subproject != ''): - raise mesonlib.MesonException(('Single object files cannot be extracted ' - 'in Unity builds. You can only extract all ' - 'the object files for each compiler at once.')) - return tobj.extract_objects(args[0]) + is_unity = True + else: + is_unity = False + return tobj.extract_objects(args[0], is_unity) @noPosargs @typed_kwargs(