Access variable from boost build/b2/bjam from shell script

31 views Asked by At

I would like to be able to access the value of a variable which is computed inside a jamroot (or jamfile) from the shell.

Something like this for CMake.

Example jamroot:

MY_VARIABLE=42

Desired solution:

b2 --print-variable=MY_VARIABLE # running in a directory below the jamroot
1

There are 1 answers

0
Gabriel Devillers On

I did not find a satisfactory solution.

First hackish solution: requires to modify the jamroot

by adding at the end (i.e. after variable is set):

import os ;
local B2_DISPLAY_VARIABLE_AND_EXIT = [ os.environ B2_DISPLAY_VARIABLE_AND_EXIT ] ;
if $(B2_DISPLAY_VARIABLE_AND_EXIT)-not-empty
{
    echo $($(B2_DISPLAY_VARIABLE_AND_EXIT)) ;
    exit ;
}

then run b2 with the environment variable set: B2_DISPLAY_VARIABLE_AND_EXIT=MY_VARIABLE b2

Second hackish solution: requires to generate a custom file below the jamroot

custom.jam (generate it using the shell):

echo $(MY_VARIABLE) ;
exit ;

then run b2 with: b2 -sJAMFILE=custom.jam and then rm custom.jam

JAMFILE is a special variable which for some reason is not mentioned in the new doc.

Remark

These solutions do not work if the variable is set from a jamfile. It may be possible to adapt the first solution using a custom target that would be called on the jamfile.