b2 icon indicating copy to clipboard operation
b2 copied to clipboard

the inner SHELL cross os compatibility between freebsd and windows msys2

Open fasxmut opened this issue 3 years ago • 6 comments

Make sure you completed the following tasks

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!

fasxmut avatar Dec 17 '21 20:12 fasxmut

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.

Kojoley avatar Dec 20 '21 16:12 Kojoley

import print ;
make a.txt : : @write ;
rule write ( target : srcs * : props : ) {
  print.output $(target) ;
  print.text "line1" "line2" : overwrite ;
}

grisumbras avatar Dec 21 '21 06:12 grisumbras

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.

fasxmut avatar Dec 22 '21 17:12 fasxmut

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.

grisumbras avatar Dec 22 '21 18:12 grisumbras

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.

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.

fasxmut avatar Dec 22 '21 20:12 fasxmut

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.

grafikrobot avatar May 04 '22 01:05 grafikrobot