bjam - cannot assign a literal to a variable?

25 views Asked by At

Well, this must be the most stupid and idiotic behavior I've seen from a programming language.

https://www.bfgroup.xyz/b2/manual/release/index.html says:

Syntactically, a Boost.Jam program consists of two kinds of elements—keywords (which have a special meaning to Boost.Jam) and literals. Consider this code:

a = b ;

which assigns the value b to the variable a. Here, = and ; are keywords, while a and b are literals.

⚠ All syntax elements, even keywords, must be separated by spaces. For example, omitting the space character before ; will lead to a syntax error.

If you want to use a literal value that is the same as some keyword, the value can be quoted:

a = "=" ;

OK, so far so good. So I have this in my Jamroot:

import path : basename ;

actions make_mytest_install
{
    echo "make_mytest_install: MY_ROOT_PATH $(MY_ROOT_PATH) PWD $(PWD:E=not_set)" ;
    epath = "$(MY_ROOT_PATH)/projects/mytest/bin/gcc-9/release/qt5client" ;
    ename = basename ( $(epath) ) ;
    echo "epath $(epath) ename $(ename)" ;
}
explicit install-gettext ;
make install-mytest : : @make_mytest_install ;

... and I try this:

bjam install-mytest

...updating 1 target...
Jamfile</home/USER/src/myproject>.make_mytest_install bin/install-mytest
make_mytest_install: MY_ROOT_PATH /home/USER/src/myproject PWD not_set
[ SHELL pstree -s -p 2720269 && echo PID 2720269 PWD /home/USER/src/myproject ]
/bin/sh: 13: epath: not found
/bin/sh: 14: Syntax error: "(" unexpected

   .....

...failed Jamfile</home/USER/src/myproject>.make_mytest_install bin/install-mytest...
...failed updating 1 target...

Now - how come that the SIMPLEST assignment to a string, EXACTLY AS in the manual:

epath = "$(MY_ROOT_PATH)/projects/mytest/bin/gcc-9/release/qt5client" ;

... fails, and this variable cannot be found anymore?

What is the logic in this? How the hell is this supposed to work? I would get it if MY_ROOT_PATH was undefined - but the echo before it, shows that it is not? What is this lunacy?

So I cannot believe I'm asking something this trivial, but:

How do you assign a string to a variable in bjam language?

1

There are 1 answers

0
sdbbs On

Well, the error gives somewhat of a hint: /bin/sh: -> so apparently inside actions, it is sh that runs - then again, if it was really sh I could have assigned variables, but I can't. So best I could do, was to remove the assignments OUT of actions:

import path : basename ;

epath = "$(MY_ROOT_PATH)/projects/mytest/bin/gcc-9/release/qt5client" ;
# ename = basename ( $(epath) ) ; # nope, causes target install-mytest to not be found :(
# calling a shell for basename works - but adds a damn NEWLINE at end!?!?!?!
ename = [ SHELL "basename $(epath)" ] ;

actions make_mytest_install
{
    echo "make_mytest_install: MY_ROOT_PATH $(MY_ROOT_PATH) PWD $(PWD:E=not_set)" ;
    echo "epath $(epath) ename $(ename)" ;
}
explicit install-mytest ;
make install-mytest : : @make_mytest_install ;

So, assignment kind of passes, but you still can't get the basename ?!

I still don't understand, who thought this kind of variable management is a good idea ... I don't even understand, how people managed to build stuff with this system