backend: always use the same code to compute the files in ExtractedObjects

Instead of asking the ExtractedObjects, but with a hook back into the backend,
use the existing function in the backend itself.  This fixes using the
extract_objects(...) of a generated source file in a custom_target.

It should also fix recursive extract_all_objects with the Xcode backend.

Fixes: #10394
pull/10493/head
Paolo Bonzini 3 years ago committed by Dylan Baker
parent dae986073d
commit e4a8f4dbd6
  1. 14
      mesonbuild/backend/backends.py
  2. 5
      mesonbuild/backend/xcodebackend.py
  3. 8
      mesonbuild/build.py

@ -456,6 +456,10 @@ class Backend:
obj_list = self._flatten_object_list(target, target.get_objects(), proj_dir_to_build_root)
return list(dict.fromkeys(obj_list))
def determine_ext_objs(self, objects: build.ExtractedObjects, proj_dir_to_build_root: str = '') -> T.List[str]:
obj_list = self._flatten_object_list(objects.target, [objects], proj_dir_to_build_root)
return list(dict.fromkeys(obj_list))
def _flatten_object_list(self, target: build.BuildTarget,
objects: T.Sequence[T.Union[str, 'File', build.ExtractedObjects]],
proj_dir_to_build_root: str) -> T.List[str]:
@ -477,7 +481,7 @@ class Backend:
elif isinstance(obj, build.ExtractedObjects):
if obj.recursive:
obj_list += self._flatten_object_list(obj.target, obj.objlist, proj_dir_to_build_root)
obj_list += self.determine_ext_objs(obj, proj_dir_to_build_root)
obj_list += self._determine_ext_objs(obj, proj_dir_to_build_root)
else:
raise MesonException('Unknown data type in object list.')
return obj_list
@ -808,7 +812,7 @@ class Backend:
machine = self.environment.machines[target.for_machine]
return self.canonicalize_filename(gen_source) + '.' + machine.get_object_suffix()
def determine_ext_objs(self, extobj: 'build.ExtractedObjects', proj_dir_to_build_root: str) -> T.List[str]:
def _determine_ext_objs(self, extobj: 'build.ExtractedObjects', proj_dir_to_build_root: str) -> T.List[str]:
result: T.List[str] = []
# Merge sources and generated sources
@ -1297,8 +1301,7 @@ class Backend:
elif isinstance(i, build.GeneratedList):
fname = [os.path.join(self.get_target_private_dir(target), p) for p in i.get_outputs()]
elif isinstance(i, build.ExtractedObjects):
outputs = i.get_outputs(self)
fname = self.get_extracted_obj_paths(i.target, outputs)
fname = self.determine_ext_objs(i)
elif isinstance(i, programs.ExternalProgram):
assert i.found(), "This shouldn't be possible"
assert i.path is not None, 'for mypy'
@ -1310,9 +1313,6 @@ class Backend:
srcs += fname
return srcs
def get_extracted_obj_paths(self, target: build.BuildTarget, outputs: T.List[str]) -> T.List[str]:
return [os.path.join(self.get_target_private_dir(target), p) for p in outputs]
def get_custom_target_depend_files(self, target: build.CustomTarget, absolute_paths: bool = False) -> T.List[str]:
deps: T.List[str] = []
for i in target.depend_files:

@ -259,9 +259,6 @@ class XCodeBackend(backends.Backend):
obj_path = f'{project}.build/{buildtype}/{tname}.build/Objects-normal/{arch}/{stem}.o'
return obj_path
def get_extracted_obj_paths(self, target: build.BuildTarget, outputs: T.List[str]) -> T.List[str]:
return outputs
def generate(self):
self.serialize_tests()
# Cache the result as the method rebuilds the array every time it is called.
@ -1469,7 +1466,7 @@ class XCodeBackend(backends.Backend):
# Add extracted objects to the link line by hand.
if isinstance(o, build.ExtractedObjects):
added_objs = set()
for objname_rel in o.get_outputs(self):
for objname_rel in self.determine_ext_objs(o):
objname_abs = os.path.join(self.environment.get_build_dir(), o.target.subdir, objname_rel)
if objname_abs not in added_objs:
added_objs.add(objname_abs)

@ -447,12 +447,6 @@ class ExtractedObjects(HoldableObject):
'in Unity builds. You can only extract all '
'the object files for each compiler at once.')
def get_outputs(self, backend: 'Backend') -> T.List[str]:
return [
backend.object_filename_from_source(self.target, source)
for source in self.get_sources(self.srclist, self.genlist)
]
@dataclass(eq=False, order=False)
class StructuredSources(HoldableObject):
@ -2878,7 +2872,7 @@ def get_sources_string_names(sources, backend):
elif isinstance(s, (BuildTarget, CustomTarget, CustomTargetIndex, GeneratedList)):
names += s.get_outputs()
elif isinstance(s, ExtractedObjects):
names += s.get_outputs(backend)
names += backend.determine_ext_objs(s)
elif isinstance(s, File):
names.append(s.fname)
else:

Loading…
Cancel
Save