1

I'd like to print filename from buildtarget created by executable(). Looking into class Executable I tried ping.name:

ping = executable('ping', [
        'ping.c',
        'ping_common.c',
        'ping6_common.c',
        'node_info.c',
        git_version_h
    ],
    include_directories : inc,
    dependencies : [ 
        cap_dep,
        idn_dep,
        intl_dep,
        m_dep,
        resolv_dep
    ],
    link_with : [libcommon],
    install: true)

message(ping.name))

But it gives an error:

ping/meson.build:23:17: ERROR: Expecting lparen got rparen.

The same is for ping.filename, there is no to_string(). Are these "private" or anyhow hidden?

BuildTarget is documented, but there is no method described. Thus generally howto understand which methods are public and which private for certain meson class?

pevik
  • 4,523
  • 3
  • 33
  • 44

2 Answers2

3

name is actually a method, you missed (

message(ping.name())
pevik
  • 4,523
  • 3
  • 33
  • 44
Elvis Oric
  • 1,289
  • 8
  • 22
  • 1
    I tested various things, including `ping.filename()`, but not `ping.name()`. In the end I'm going to use plain string because `.name()` is from `0.54.0` and I need support for older distros as well. – pevik Jul 28 '21 at 06:06
  • I see now, really missing one char, thus not tested as a function. I also tested it both as attributes `message(ping.name)`. – pevik Jul 30 '21 at 06:54
  • Meson's DSL doesn't have any attributes, FYI, they're always methods. – dcbaker Aug 15 '21 at 16:56
1

Better link to reference is this one since it shows all supported methods. And in your case it also should work full_path() method:

message(ping.full_path())

If you need just target file name and don't have name(), then some string/array manipulation should work:

message(ping.full_path().split('/')[-1])

so, it should split full pathname into array of strings and print the last element of the array.

pevik
  • 4,523
  • 3
  • 33
  • 44
pmod
  • 10,450
  • 1
  • 37
  • 50