interpreter: add 'name' method to BuildTargetHolder

As any child of BuildTargetHolder might need the name of the object,
provides a method to get object name.
This is useful in gst-build to display the plugin name and not
the filename.
pull/6735/head
Stéphane Cerveau 5 years ago committed by Xavier Claessens
parent 58db8d5e11
commit a46f0a6202
  1. 2
      docs/markdown/Reference-manual.md
  2. 2
      docs/markdown/snippets/build_target_older_name.md
  3. 7
      mesonbuild/interpreter.py
  4. 2
      test cases/common/1 trivial/meson.build
  5. 2
      test cases/common/3 static/meson.build

@ -2268,6 +2268,8 @@ A build target is either an [executable](#executable),
target, usually only needed if an another target needs to access target, usually only needed if an another target needs to access
some generated internal headers of this target some generated internal headers of this target
- `name()` *Since 0.54.0*, returns the target name.
### `configuration` data object ### `configuration` data object

@ -0,0 +1,2 @@
## Added 'name' method
Build target objects (as returned by executable(), library(), ...) now have a name() method.

@ -771,6 +771,7 @@ class BuildTargetHolder(TargetHolder):
super().__init__(target, interp) super().__init__(target, interp)
self.methods.update({'extract_objects': self.extract_objects_method, self.methods.update({'extract_objects': self.extract_objects_method,
'extract_all_objects': self.extract_all_objects_method, 'extract_all_objects': self.extract_all_objects_method,
'name': self.name_method,
'get_id': self.get_id_method, 'get_id': self.get_id_method,
'outdir': self.outdir_method, 'outdir': self.outdir_method,
'full_path': self.full_path_method, 'full_path': self.full_path_method,
@ -825,6 +826,12 @@ class BuildTargetHolder(TargetHolder):
def get_id_method(self, args, kwargs): def get_id_method(self, args, kwargs):
return self.held_object.get_id() return self.held_object.get_id()
@FeatureNew('name', '0.54.0')
@noPosargs
@permittedKwargs({})
def name_method(self, args, kwargs):
return self.held_object.name
class ExecutableHolder(BuildTargetHolder): class ExecutableHolder(BuildTargetHolder):
def __init__(self, target, interp): def __init__(self, target, interp):
super().__init__(target, interp) super().__init__(target, interp)

@ -20,7 +20,7 @@ if meson.is_cross_build()
endif endif
exe = executable('trivialprog', sources : sources) exe = executable('trivialprog', sources : sources)
assert(exe.name() == 'trivialprog')
test('runtest', exe) # This is a comment test('runtest', exe) # This is a comment
has_not_changed = false has_not_changed = false

@ -2,7 +2,7 @@ project('static library test', 'c')
lib = static_library('mylib', get_option('source'), lib = static_library('mylib', get_option('source'),
link_args : '-THISMUSTNOBEUSED') # Static linker needs to ignore all link args. link_args : '-THISMUSTNOBEUSED') # Static linker needs to ignore all link args.
assert(lib.name() == 'mylib')
has_not_changed = false has_not_changed = false
if is_disabler(lib) if is_disabler(lib)
has_not_changed = true has_not_changed = true

Loading…
Cancel
Save