b2
b2 copied to clipboard
the inner SHELL cross os compatibility between freebsd and windows msys2
Make sure you completed the following tasks
- [ ] I searched the discussions
- [ ] I searched the closed and open issues
- [ ] I read the contribution guidelines
Environment and version details
- Operating System+version: freebsd 13.0 and windows msys2
- Compiler+version: irrelevant
- Shell: csh, ksh, zsh, bash
- B2 Version: 4.7-git
- B2 Configuration: Output of
b2 --debug-configuration
in your project.
Place output of "b2 --debug-configuration" here.
Brief problem description
(Do not ask me why I want to do it like this. I just make a simple summary code to simplify and describe the problem.)
First, I write the Jamfile on freebsd, it works with no broblem:
Jamfile
var = "something" ;
if "$(var2)" {
echo "var2 is $(var2)" ;
} else {
SHELL "echo \"constant var2 : $(var) ;\" > project-config.jam" ;
}
The project-config.jam
is
constant var2 : something ;
When I copy it to windows msys2 and invoke b2
twice, it reports syntax error. Then I watch project-config.jam
, the content is:
"constant var2 : something ;"
OK. Then I replace \"
with \'
or '
in Jamfile, the project-config.jam
becomes to
'constant var2 : something ;'
Syntax Error Again.
Then I remove \'
(or \"
), the project-config.jam
is:
constant var2 : something ;
No Broblem!
However, I switch back to freebsd, and replace \"
with \'
or '
, the project-config.jam
is
constant var2 : something ;
No Problem.
But if I remove the quotes and invoke b2
twice in freebsd, no syntax error, the project-config.jam
is am empty file!
You are using OS shell and observing OS command parsing differences, that's obviously not SHELL
fault.
I guess you are looking for a cross-platform way to create a file with some content, but unfortunately I don't think B2 provides such an function currently.
import print ;
make a.txt : : @write ;
rule write ( target : srcs * : props : ) {
print.output $(target) ;
print.text "line1" "line2" : overwrite ;
}
import print ; make a.txt : : @write ; rule write ( target : srcs * : props : ) { print.output $(target) ; print.text "line1" "line2" : overwrite ; }
Thanks I tried. But I can't execute your script as it said args error. And it seems that make rule can not pass variables to actions except file names. And it is weird that the print.text only works if the target is console, not works on output file.
My snippet had a typo (a didn't test it when I posted it). The correct jam script that creates a project-config.jam
in current directory is
make project-config.jam : : @write : <location>. ;
rule write ( target : srcs * : props * : ) {
if "$(var2)" {
echo "var2 is $(var2)" ;
} else {
print.output $(target) ;
print.text
"constant var2 : $(var) ;"
""
: overwrite
;
}
}
I did't understand your remarks about passing variables to rules and print.text
not working on files, though.
My snippet had a typo (a didn't test it when I posted it). The correct jam script that creates a
project-config.jam
in current directory ismake project-config.jam : : @write : <location>. ; rule write ( target : srcs * : props * : ) { if "$(var2)" { echo "var2 is $(var2)" ; } else { print.output $(target) ; print.text "constant var2 : $(var) ;" "" : overwrite ; } }
I did't understand your remarks about passing variables to rules and
print.text
not working on files, though.
I try it again this time, your jamfile script has no errors, and the print.text works on files too. The passing variables to rules I mean, the rule or actions take variables from the arguments (just like function parameters), not take variables from global scope.
The passing variables to rules I mean, the rule or actions take variables from the arguments (just like function parameters), not take variables from global scope.
@fasxmut target actions, which is what the print utility module is using for the file output, only take inputs through variables. They can be either global or bound (https://www.bfgroup.xyz/b2/manual/main/index.html#jam.language.rules.action_modifiers). What @grisumbras demonstrated accepting rule arguments like your original example. Can you explain in more details what you are trying to accomplish.