Raise InvalidArguments when trying to link against strings

With executable(), if the link_with argument has a string as one of it's
elements, meson ends up throwing an AttributeError exception:

...
  File "/home/lyudess/Projects/meson/mesonbuild/build.py", line 868, in link
    if not t.is_linkable_target():
AttributeError: 'str' object has no attribute 'is_linkable_target'

Which is not very helpful in figuring out where exactly the project is
trying to link against a string instead of an actual link target. So,
fix this by verifying in BuildTarget.link() that each given target is
actually a Target object and not something else.

Additionally, add a simple test case for this in failing tests. At the
moment, this test case just passes unconditionally due to meson throwing
the AttributeError exception and failing as expected. However, this test
case will be useful eventually if we ever end up making failing tests
more strict about failing gracefully (per advice of QuLogic).
pull/2482/merge
Lyude Paul 7 years ago committed by Jussi Pakkanen
parent 6e406ed0db
commit 1a159db8e9
  1. 2
      mesonbuild/build.py
  2. 2
      test cases/failing/66 string as link target/meson.build
  3. 1
      test cases/failing/66 string as link target/prog.c

@ -863,6 +863,8 @@ You probably should put it in link_with instead.''')
def link(self, target): def link(self, target):
for t in listify(target, unholder=True): for t in listify(target, unholder=True):
if not isinstance(t, Target):
raise InvalidArguments('{!r} is not a target.'.format(t))
if not t.is_linkable_target(): if not t.is_linkable_target():
raise InvalidArguments('Link target {!r} is not linkable.'.format(t)) raise InvalidArguments('Link target {!r} is not linkable.'.format(t))
if isinstance(self, SharedLibrary) and isinstance(t, StaticLibrary) and not t.pic: if isinstance(self, SharedLibrary) and isinstance(t, StaticLibrary) and not t.pic:

@ -0,0 +1,2 @@
project('string as link argument', 'c')
executable('myprog', 'prog.c', link_with: [ '' ])

@ -0,0 +1 @@
int main(int argc, char **argv) { return 0; }
Loading…
Cancel
Save