custom_target not run by default?

969 views
Skip to first unread message

Nikolaus Rath

unread,
Jan 6, 2017, 7:19:38 PM1/6/17
to meson...@googlegroups.com
Hello,

I would like to copy some files unchanged into the build directory. I
have tried this in meson.build:

foreach fname : [ 'conftest.py', 'pytest.ini', 'test_examples.py',
'util.py' ]
custom_target(fname, input: fname, output: fname,
command : ['cp', '@INPUT@', '@OUTPUT@'])
endforeach


But no files are getting copied by default. However, I can trigger the
copy by explicitly running eg 'ninja conftest.py'.

How can I tell Meson to build these targets by default?

Thanks!
-Nikolaus

--
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

»Time flies like an arrow, fruit flies like a Banana.«

Igor Gnatenko

unread,
Jan 7, 2017, 5:10:10 AM1/7/17
to meson...@googlegroups.com
You can use configure_file() to copy files into build directory.

--
You received this message because you are subscribed to the Google Groups "The Meson Build System" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mesonbuild+...@googlegroups.com.
To post to this group, send an email to meson...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/mesonbuild/87vatrafhk.fsf%40thinkpad.rath.org.
For more options, visit https://groups.google.com/d/optout.
--

-Igor Gnatenko

Jussi Pakkanen

unread,
Jan 7, 2017, 6:50:12 AM1/7/17
to Igor Gnatenko, The Meson Build System
On Sat, Jan 7, 2017 at 12:09 PM, Igor Gnatenko
<i.gnaten...@gmail.com> wrote:

> You can use configure_file() to copy files into build directory.

Or you can use files() to pass them as arguments to the script that
you want to run so you don't need to copy them at all. There are many
choices and this is mostly a matter of taste.

Nikolaus Rath

unread,
Jan 7, 2017, 3:39:21 PM1/7/17
to meson...@googlegroups.com
On Jan 07 2017, Igor Gnatenko <i.gnaten...@gmail.com> wrote:
> On Sat, Jan 7, 2017 at 1:19 AM Nikolaus Rath <Niko...@rath.org> wrote:
>> I would like to copy some files unchanged into the build directory. I
>> have tried this in meson.build:
>>
>> foreach fname : [ 'conftest.py', 'pytest.ini', 'test_examples.py',
>> 'util.py' ]
>> custom_target(fname, input: fname, output: fname,
>> command : ['cp', '@INPUT@', '@OUTPUT@'])
>> endforeach
>>
>>
>> But no files are getting copied by default. However, I can trigger the
>> copy by explicitly running eg 'ninja conftest.py'.
>>
>> How can I tell Meson to build these targets by default?
>
> You can use configure_file() to copy files into build directory.

In other words, custom_targets are only ever build if an executable(),
test() or a library() depend on them?

Thanks,

Nikolaus Rath

unread,
Jan 7, 2017, 3:42:29 PM1/7/17
to meson...@googlegroups.com
On Jan 07 2017, Jussi Pakkanen <jpak...@gmail.com> wrote:
> On Sat, Jan 7, 2017 at 12:09 PM, Igor Gnatenko
> <i.gnaten...@gmail.com> wrote:
>
>> You can use configure_file() to copy files into build directory.
>
> Or you can use files() to pass them as arguments to the script that
> you want to run so you don't need to copy them at all.

I don't understand. Could you give an example of the latter procedure?

Best,

Jussi Pakkanen

unread,
Jan 8, 2017, 7:22:33 PM1/8/17
to The Meson Build System
On Sat, Jan 7, 2017 at 10:42 PM, Nikolaus Rath <Niko...@rath.org> wrote:

> On Jan 07 2017, Jussi Pakkanen <jpak...@gmail.com> wrote:
>> On Sat, Jan 7, 2017 at 12:09 PM, Igor Gnatenko
>> <i.gnaten...@gmail.com> wrote:
>>
>>> You can use configure_file() to copy files into build directory.
>>
>> Or you can use files() to pass them as arguments to the script that
>> you want to run so you don't need to copy them at all.
>
> I don't understand. Could you give an example of the latter procedure?

pybin = find_program('python')
args = files('foo.py', 'bar.ini')
run_target('name', command : [pybin] + args)

Nikolaus Rath

unread,
Jan 11, 2017, 11:11:17 PM1/11/17
to meson...@googlegroups.com
On Jan 07 2017, Igor Gnatenko <i.gnaten...@gmail.com> wrote:
> You can use configure_file() to copy files into build directory.

Doesn't that parse the file and try to substitute values? And does it
preserve e.g. execute permissions?


Thanks,
Nikolaus

Nikolaus Rath

unread,
Jan 11, 2017, 11:12:04 PM1/11/17
to meson...@googlegroups.com
On Jan 07 2017, Nikolaus Rath <Niko...@rath.org> wrote:
> On Jan 07 2017, Igor Gnatenko <i.gnaten...@gmail.com> wrote:
>> On Sat, Jan 7, 2017 at 1:19 AM Nikolaus Rath <Niko...@rath.org> wrote:
>>> I would like to copy some files unchanged into the build directory. I
>>> have tried this in meson.build:
>>>
>>> foreach fname : [ 'conftest.py', 'pytest.ini', 'test_examples.py',
>>> 'util.py' ]
>>> custom_target(fname, input: fname, output: fname,
>>> command : ['cp', '@INPUT@', '@OUTPUT@'])
>>> endforeach
>>>
>>>
>>> But no files are getting copied by default. However, I can trigger the
>>> copy by explicitly running eg 'ninja conftest.py'.
>>>
>>> How can I tell Meson to build these targets by default?
>>
>> You can use configure_file() to copy files into build directory.
>
> In other words, custom_targets are only ever build if an executable(),
> test() or a library() depend on them?

*ping* Is there really no way to get custom_targets to be build without
explicitly having to call "ninja <target>" for each of them?

Jussi Pakkanen

unread,
Jan 12, 2017, 2:44:22 PM1/12/17
to The Meson Build System
On Thu, Jan 12, 2017 at 6:12 AM, Nikolaus Rath <Niko...@rath.org> wrote:

> *ping* Is there really no way to get custom_targets to be build without
> explicitly having to call "ninja <target>" for each of them?

Except for the ways mentioned above, no. This is a thing that keeps
tripping people up so this could be improved but no-one has come up
with a good solution.

Nikolaus Rath

unread,
Jan 12, 2017, 6:10:55 PM1/12/17
to meson...@googlegroups.com
Why not build them all by default, just like the executable() and
library() targets?


Best,

Jussi Pakkanen

unread,
Jan 13, 2017, 2:56:56 AM1/13/17
to The Meson Build System
On Fri, Jan 13, 2017 at 1:10 AM, Nikolaus Rath <Niko...@rath.org> wrote:

> Why not build them all by default, just like the executable() and
> library() targets?

Because custom targets are often used to build stuff like
documentation and so on which is a lot slower than compiling the
actual code. Running those on every code change yields a poor
developer experience (Meson aims to be as fast and as invisible as
possible so developers can focus on their actual work).

Nikolaus Rath

unread,
Jan 14, 2017, 3:25:04 PM1/14/17
to meson...@googlegroups.com
I see. What about adding a 'build_by_default' keyword argument to all
target functions? It would default to true for executable() and
library(), and to false for custom_target.

Jussi Pakkanen

unread,
Jan 14, 2017, 3:33:04 PM1/14/17
to The Meson Build System
On Sat, Jan 14, 2017 at 10:25 PM, Nikolaus Rath <Niko...@rath.org> wrote:

> I see. What about adding a 'build_by_default' keyword argument to all
> target functions? It would default to true for executable() and
> library(), and to false for custom_target.

Well ...

https://github.com/mesonbuild/meson/pull/1303
Reply all
Reply to author
Forward
0 new messages