extract_all_objects: Add 'recursive' keyword argument

To maintain backward compatibility we cannot add recursive objects by
default. Print a warning when there are recursive objects to be pulled
and the argument is not set. After a while we'll do pull recursive
objects by default.
pull/3404/head
Xavier Claessens 7 years ago
parent 60aaee55d4
commit 9a82b0136a
  1. 6
      docs/markdown/Reference-manual.md
  2. 12
      docs/markdown/snippets/extract-all-objects.md
  3. 3
      mesonbuild/backend/backends.py
  4. 8
      mesonbuild/build.py
  5. 9
      mesonbuild/interpreter.py
  6. 6
      test cases/common/88 extract all/meson.build

@ -1736,7 +1736,11 @@ A build target is either an [executable](#executable),
[shared module](#shared_module).
- `extract_all_objects()` is same as `extract_objects` but returns all
object files generated by this target
object files generated by this target. Since 0.46.0 keyword argument
`recursive` must be set to `true` to also return objects passed to the
`object` argument of this target. By default only objects built for this
target are returned to maintain backward compatibility with previous versions.
The default will eventually be changed to `true` in a future version.
- `extract_objects()` returns an opaque value representing the
generated object files of arguments, usually used to take single

@ -0,0 +1,12 @@
## Recursively extract objects
`recursive` keyword argument has been added to `extract_all_objects`. When set
to `true` it will also return objects passed to the `objects` argument of this
target. By default only objects built for this target are returned to maintain
backward compatibility with previous versions. The default will eventually be
changed to `true` in a future version.
```meson
lib1 = static_library('a', 'source.c', objects : 'prebuilt.o')
lib2 = static_library('b', objects : lib1.extract_all_objects(recursive : true))
```

@ -253,7 +253,8 @@ class Backend:
elif isinstance(obj, mesonlib.File):
obj_list.append(obj.rel_to_builddir(self.build_to_src))
elif isinstance(obj, build.ExtractedObjects):
obj_list += self._flatten_object_list(obj.target, obj.objlist, proj_dir_to_build_root)
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)
else:
raise MesonException('Unknown data type in object list.')

@ -213,8 +213,9 @@ class ExtractedObjects:
'''
Holds a list of sources for which the objects must be extracted
'''
def __init__(self, target, srclist=[], genlist=[], objlist=[]):
def __init__(self, target, srclist=[], genlist=[], objlist=[], recursive=True):
self.target = target
self.recursive = recursive
self.srclist = srclist
self.genlist = genlist
self.objlist = objlist
@ -647,8 +648,9 @@ class BuildTarget(Target):
obj_src.append(src)
return ExtractedObjects(self, obj_src)
def extract_all_objects(self):
return ExtractedObjects(self, self.sources, self.generated, self.objects)
def extract_all_objects(self, recursive=True):
return ExtractedObjects(self, self.sources, self.generated, self.objects,
recursive)
def get_all_link_deps(self):
return self.get_transitive_link_deps()

@ -606,8 +606,15 @@ class BuildTargetHolder(TargetHolder):
gobjs = self.held_object.extract_objects(args)
return GeneratedObjectsHolder(gobjs)
@permittedMethodKwargs({'recursive'})
def extract_all_objects_method(self, args, kwargs):
gobjs = self.held_object.extract_all_objects()
recursive = kwargs.get('recursive', False)
gobjs = self.held_object.extract_all_objects(recursive)
if gobjs.objlist and 'recursive' not in kwargs:
mlog.warning('extract_all_objects called without setting recursive '
'keyword argument. Meson currently defaults to '
'non-recursive to maintain backward compatibility but '
'the default will be changed in the future.')
return GeneratedObjectsHolder(gobjs)
def get_id_method(self, args, kwargs):

@ -3,7 +3,11 @@ project('extract all', 'c')
a = static_library('a', 'one.c', 'two.c')
b = static_library('b', 'three.c', 'four.c')
c = static_library('c', objects : [a.extract_all_objects(), b.extract_all_objects()])
d = static_library('d', objects : [c.extract_all_objects()])
d = static_library('d', objects : [a.extract_all_objects(), b.extract_all_objects(), c.extract_all_objects()])
d_recursive = static_library('d_recursive', objects : [c.extract_all_objects(recursive : true)])
e = executable('proggie', 'prog.c', link_with : d)
test('extall', e)
e = executable('proggie_recursive', 'prog.c', link_with : d_recursive)
test('extall_recursive', e)

Loading…
Cancel
Save