Print list of (specified) run_targets from within Meson

14 views
Skip to first unread message

Gerion Entrup

unread,
Jul 26, 2023, 8:05:01 AM7/26/23
to meson...@googlegroups.com
Hi,

I have a question regarding run targets:
I have a fairly large project and part of that project is to call an
included program in a bunch of different ways.

Since the included program itself needs to be build with Meson as well
as some files on which that program operates, it make sense to also use
Meson for calling that program.

For that I see two possibilities: tests() and run_targets(). Since the
calls do not test anything (there is no real success value), run_targets
seem to be better fitted.

A minimal setting would be:
```
project("foo")

foo = executable(...)

some_file = custom_target(...)
some_other_file = custom_target(...)

r1 = run_target('my-run-target1', command: [foo, '-i', some_file])
r23 = run_target('my-run-target23', command: [foo, '-i', some_other_file])

currently_active_targets = [r1, r23]


# does not work:
run_target('meta-target',
depends: currently_active_targets)

# does not print something meaningful:
message('Targets: @0@'.format(currently_active_targets))
```

However, I'm searching a way to let the user know about the currently
existent run_targets (some are only built when certain Meson options are
activated). For tests, I can use suites for that: Put the test in a
specific suite and the user can list all tests of that suite easily.

I tried to print run_targets with
```
message("Run: @0@".format(my_target)).
```
However, the output was not helpful:
```
Message: Run <RunTarget 8e51da9@@my-run-target1@run: /usr/bin/python3.11>
```
I'd like to inform my users (and myself) somehow about the list of
run_targets and am ideally also possible to run them with a single
command. Something like this Meson message:

```
You have enable the meson option "foobar".
Therefore you can run the following targets:
my-run-target1
my-run-target23
my-run-target42
```
I also thought about generating a script that calls Meson with all
run_targets. However, I need to get the targets name as str from within
Meson for that, for which I found no way to do it.

Is this possible at all?


Gerion
signature.asc

Volker Weißmann

unread,
Jul 28, 2023, 5:20:23 PM7/28/23
to meson...@googlegroups.com
Hello,
1.Could you elaborate what "part of that project is to call an included
program in a bunch of different ways" is in your case? I.e. could you
explain your usecase? (Perhaps include a link to your repo.)
2.If you want a message like
```
You have enable the meson option "foobar".
Therefore you can run the following targets:
my-run-target1
my-run-target23
my-run-target42
```
to be printed during `meson setup`, the (afaik) only possible way is this.
```
all_run_targets = []
r1 = run_target('my-run-target1', command: [foo, '-i', 'abc'])
all_run_targets += 'my-run-target1'
if get_option('myfeature').enabled()
r23 = run_target('my-run-target23', command: [foo, '-i', 'def'])
all_run_targets += 'my-run-target23'
endif
message('Therefore you can run the following targets:')
foreach rt : all_run_targets
message(rt)
endforeach
```
3.If another program should print such a message, or if another program
should run all run_targets, `meson introspect path/to/builddir
--targets`gives you what you want.
Reply all
Reply to author
Forward
0 new messages