Returns the command needed to set an environment variable on the current platform. The variable setting persists through all following commands and is visible in the environment seen by subsequently executed commands. In other words, on Unix systems, the variable is
(variable, value)
| 470 | |
| 471 | # ported from trunk@47281 |
| 472 | def variable_setting_command(variable, value): |
| 473 | """ |
| 474 | Returns the command needed to set an environment variable on the current |
| 475 | platform. The variable setting persists through all following commands and is |
| 476 | visible in the environment seen by subsequently executed commands. In other |
| 477 | words, on Unix systems, the variable is exported, which is consistent with the |
| 478 | only possible behavior on Windows systems. |
| 479 | """ |
| 480 | assert(isinstance(variable, str)) |
| 481 | assert(isinstance(value, str)) |
| 482 | |
| 483 | if os_name() == 'NT': |
| 484 | return "set " + variable + "=" + value + os.linesep |
| 485 | else: |
| 486 | # (todo) |
| 487 | # The following does not work on CYGWIN and needs to be fixed. On |
| 488 | # CYGWIN the $(nl) variable holds a Windows new-line \r\n sequence that |
| 489 | # messes up the executed export command which then reports that the |
| 490 | # passed variable name is incorrect. This is most likely due to the |
| 491 | # extra \r character getting interpreted as a part of the variable name. |
| 492 | # |
| 493 | # Several ideas pop to mind on how to fix this: |
| 494 | # * One way would be to separate the commands using the ; shell |
| 495 | # command separator. This seems like the quickest possible |
| 496 | # solution but I do not know whether this would break code on any |
| 497 | # platforms I I have no access to. |
| 498 | # * Another would be to not use the terminating $(nl) but that would |
| 499 | # require updating all the using code so it does not simply |
| 500 | # prepend this variable to its own commands. |
| 501 | # * I guess the cleanest solution would be to update Boost Jam to |
| 502 | # allow explicitly specifying \n & \r characters in its scripts |
| 503 | # instead of always relying only on the 'current OS native newline |
| 504 | # sequence'. |
| 505 | # |
| 506 | # Some code found to depend on this behaviour: |
| 507 | # * This Boost Build module. |
| 508 | # * __test__ rule. |
| 509 | # * path-variable-setting-command rule. |
| 510 | # * python.jam toolset. |
| 511 | # * xsltproc.jam toolset. |
| 512 | # * fop.jam toolset. |
| 513 | # (todo) (07.07.2008.) (Jurko) |
| 514 | # |
| 515 | # I think that this works correctly in python -- Steven Watanabe |
| 516 | return variable + "=" + value + os.linesep + "export " + variable + os.linesep |
| 517 | |
| 518 | def path_variable_setting_command(variable, paths): |
| 519 | """ |
no test coverage detected