Skip to content

Commit 2724c2c

Browse files
authored
Use platform-native separators in environment variables (#40)
PowerShell can be used on non-Windows platforms. It appears that when PowerShell is used on Linux, the platform-native separators (forward slash and colon) are used, and not the Windows-style separators (backslash and semicolon).
1 parent 87d1ea2 commit 2724c2c

4 files changed

Lines changed: 14 additions & 10 deletions

File tree

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# generated from colcon_powershell/shell/template/hook_append_value.ps1.em
22

33
@{
4+
import os
45
value = '$env:COLCON_CURRENT_PREFIX'
56
if subdirectory:
6-
value += '\\' + subdirectory
7+
value += os.sep + subdirectory
78
}@
89
colcon_append_unique_value @(name) "@(value)"
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# generated from colcon_powershell/shell/template/hook_prepend_value.ps1.em
22

33
@{
4+
import os
45
value = '$env:COLCON_CURRENT_PREFIX'
56
if subdirectory:
6-
value += '\\' + subdirectory
7+
value += os.sep + subdirectory
78
}@
89
colcon_prepend_unique_value @(name) "@(value)"

colcon_powershell/shell/template/package.ps1.em

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@{import os}@
12
# generated from colcon_powershell/shell/template/package.ps1.em
23

34
# function to append a value to a variable
@@ -22,15 +23,15 @@ function colcon_append_unique_value {
2223
$_all_values=""
2324
# iterate over existing values in the variable
2425
if ($_values) {
25-
$_values.Split(";") | ForEach {
26+
$_values.Split("@(os.pathsep)") | ForEach {
2627
# not an empty string
2728
if ($_) {
2829
# not a duplicate of _value
2930
if ($_ -eq $_value) {
3031
$_duplicate="1"
3132
}
3233
if ($_all_values) {
33-
$_all_values="${_all_values};$_"
34+
$_all_values="${_all_values}@(os.pathsep)$_"
3435
} else {
3536
$_all_values="$_"
3637
}
@@ -41,7 +42,7 @@ function colcon_append_unique_value {
4142
if (!$_duplicate) {
4243
# avoid leading separator
4344
if ($_all_values) {
44-
$_all_values="${_all_values};${_value}"
45+
$_all_values="${_all_values}@(os.pathsep)${_value}"
4546
} else {
4647
$_all_values="${_value}"
4748
}
@@ -72,13 +73,13 @@ function colcon_prepend_unique_value {
7273
$_all_values="$_value"
7374
# iterate over existing values in the variable
7475
if ($_values) {
75-
$_values.Split(";") | ForEach {
76+
$_values.Split("@(os.pathsep)") | ForEach {
7677
# not an empty string
7778
if ($_) {
7879
# not a duplicate of _value
7980
if ($_ -ne $_value) {
8081
# keep non-duplicate values
81-
$_all_values="${_all_values};$_"
82+
$_all_values="${_all_values}@(os.pathsep)$_"
8283
}
8384
}
8485
}
@@ -113,7 +114,7 @@ function colcon_package_source_powershell_script {
113114
$env:COLCON_CURRENT_PREFIX=(Get-Item $PSCommandPath).Directory.Parent.Parent.FullName
114115

115116
@[end if]@
116-
colcon_package_source_powershell_script "$env:COLCON_CURRENT_PREFIX\@(hook[0])"@
117+
colcon_package_source_powershell_script "$env:COLCON_CURRENT_PREFIX@(os.sep)@(hook[0])"@
117118
@[ for hook_arg in hook[1]]@
118119
@(hook_arg)@
119120
@[ end for]

colcon_powershell/shell/template/prefix_chain.ps1.em

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@{import os}
12
# generated from colcon_powershell/shell/template/prefix_chain.ps1.em
23

34
# This script extends the environment with the environment of other prefix
@@ -24,10 +25,10 @@ function _colcon_prefix_chain_powershell_source_script {
2425

2526
# source chained prefixes
2627
@[ for prefix in reversed(chained_prefix_path)]@
27-
_colcon_prefix_chain_powershell_source_script "@(prefix)\@(prefix_script_no_ext).ps1"
28+
_colcon_prefix_chain_powershell_source_script "@(prefix)@(os.sep)@(prefix_script_no_ext).ps1"
2829
@[ end for]@
2930
@[end if]@
3031

3132
# source this prefix
3233
$env:COLCON_CURRENT_PREFIX=(Split-Path $PSCommandPath -Parent)
33-
_colcon_prefix_chain_powershell_source_script "$env:COLCON_CURRENT_PREFIX\@(prefix_script_no_ext).ps1"
34+
_colcon_prefix_chain_powershell_source_script "$env:COLCON_CURRENT_PREFIX@(os.sep)@(prefix_script_no_ext).ps1"

0 commit comments

Comments
 (0)