[build2] How can I store the result of external commands inside a buildfile

Boris Kolpackov boris at codesynthesis.com
Mon Mar 11 13:53:18 UTC 2019


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'.



More information about the users mailing list