[build2] How can I store the result of external commands inside a buildfile
Luiz Fernando Afra Brito
luizfernandoafrabrito at gmail.com
Mon Mar 11 16:34:29 UTC 2019
Thanks, I'll check it out.
I'd like other people to adopt build2 in the future. This is a fantastic
tool.
On Mon, Mar 11, 2019 at 10:53 AM Boris Kolpackov <boris at codesynthesis.com>
wrote:
> Luiz Fernando Afra Brito <luizfernandoafrabrito at gmail.com> writes:
>
> > cxx.poptions += -DL1_SIZE=`/bin/getconf LEVEL1_DCACHE_SIZE`
> >
> > Can I get the result of external commands inside a buildfile?
>
> There is a family of $process.run*() functions for that. Quoting from
> build2/functions-process.cxx (proper documentation is coming soon):
>
>
> // $process.run(<prog>[ <args>...])
> //
> // Return trimmed stdout.
>
>
> // $process.run_regex(<prog>[ <args>...], <pat> [, <fmt>])
> //
> // Return stdout lines matched and optionally processed with regex.
> //
> // Each line of stdout (including the customary trailing blank) is matched
> // (as a whole) against <pat> and, if successful, returned, optionally
> // processed with <fmt>, as an element of a list.
>
>
> So you should be able to do something like this:
>
> cxx.poptions += "-DL1_SIZE=$process.run(/bin/getconf LEVEL1_DCACHE_SIZE)"
>
> For completeness, let me also mention the run directive which you can
> use to source output of a program as a buildfile fragment:
>
> run echo 'foo = bar'
> print $foo # Prints 'bar'.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.build2.org/archives/users/attachments/20190311/b3b64f60/attachment.html>
More information about the users
mailing list