From 0390a7c5c48c2312b56e27500d20e098ea04d01a Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Tue, 20 Jan 2026 16:41:28 -0600 Subject: [PATCH] Use platform-native separators in environment variables 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). --- .../shell/template/hook_append_value.ps1.em | 3 ++- .../shell/template/hook_prepend_value.ps1.em | 3 ++- colcon_powershell/shell/template/package.ps1.em | 13 +++++++------ .../shell/template/prefix_chain.ps1.em | 5 +++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/colcon_powershell/shell/template/hook_append_value.ps1.em b/colcon_powershell/shell/template/hook_append_value.ps1.em index 8ccb465..1bcc06f 100644 --- a/colcon_powershell/shell/template/hook_append_value.ps1.em +++ b/colcon_powershell/shell/template/hook_append_value.ps1.em @@ -1,8 +1,9 @@ # generated from colcon_powershell/shell/template/hook_append_value.ps1.em @{ +import os value = '$env:COLCON_CURRENT_PREFIX' if subdirectory: - value += '\\' + subdirectory + value += os.sep + subdirectory }@ colcon_append_unique_value @(name) "@(value)" diff --git a/colcon_powershell/shell/template/hook_prepend_value.ps1.em b/colcon_powershell/shell/template/hook_prepend_value.ps1.em index 9de39ac..8cdf034 100644 --- a/colcon_powershell/shell/template/hook_prepend_value.ps1.em +++ b/colcon_powershell/shell/template/hook_prepend_value.ps1.em @@ -1,8 +1,9 @@ # generated from colcon_powershell/shell/template/hook_prepend_value.ps1.em @{ +import os value = '$env:COLCON_CURRENT_PREFIX' if subdirectory: - value += '\\' + subdirectory + value += os.sep + subdirectory }@ colcon_prepend_unique_value @(name) "@(value)" diff --git a/colcon_powershell/shell/template/package.ps1.em b/colcon_powershell/shell/template/package.ps1.em index 61386f3..62bc2d7 100644 --- a/colcon_powershell/shell/template/package.ps1.em +++ b/colcon_powershell/shell/template/package.ps1.em @@ -1,3 +1,4 @@ +@{import os}@ # generated from colcon_powershell/shell/template/package.ps1.em # function to append a value to a variable @@ -22,7 +23,7 @@ function colcon_append_unique_value { $_all_values="" # iterate over existing values in the variable if ($_values) { - $_values.Split(";") | ForEach { + $_values.Split("@(os.pathsep)") | ForEach { # not an empty string if ($_) { # not a duplicate of _value @@ -30,7 +31,7 @@ function colcon_append_unique_value { $_duplicate="1" } if ($_all_values) { - $_all_values="${_all_values};$_" + $_all_values="${_all_values}@(os.pathsep)$_" } else { $_all_values="$_" } @@ -41,7 +42,7 @@ function colcon_append_unique_value { if (!$_duplicate) { # avoid leading separator if ($_all_values) { - $_all_values="${_all_values};${_value}" + $_all_values="${_all_values}@(os.pathsep)${_value}" } else { $_all_values="${_value}" } @@ -72,13 +73,13 @@ function colcon_prepend_unique_value { $_all_values="$_value" # iterate over existing values in the variable if ($_values) { - $_values.Split(";") | ForEach { + $_values.Split("@(os.pathsep)") | ForEach { # not an empty string if ($_) { # not a duplicate of _value if ($_ -ne $_value) { # keep non-duplicate values - $_all_values="${_all_values};$_" + $_all_values="${_all_values}@(os.pathsep)$_" } } } @@ -113,7 +114,7 @@ function colcon_package_source_powershell_script { $env:COLCON_CURRENT_PREFIX=(Get-Item $PSCommandPath).Directory.Parent.Parent.FullName @[end if]@ -colcon_package_source_powershell_script "$env:COLCON_CURRENT_PREFIX\@(hook[0])"@ +colcon_package_source_powershell_script "$env:COLCON_CURRENT_PREFIX@(os.sep)@(hook[0])"@ @[ for hook_arg in hook[1]]@ @(hook_arg)@ @[ end for] diff --git a/colcon_powershell/shell/template/prefix_chain.ps1.em b/colcon_powershell/shell/template/prefix_chain.ps1.em index ec05358..db92ec8 100644 --- a/colcon_powershell/shell/template/prefix_chain.ps1.em +++ b/colcon_powershell/shell/template/prefix_chain.ps1.em @@ -1,3 +1,4 @@ +@{import os} # generated from colcon_powershell/shell/template/prefix_chain.ps1.em # This script extends the environment with the environment of other prefix @@ -24,10 +25,10 @@ function _colcon_prefix_chain_powershell_source_script { # source chained prefixes @[ for prefix in reversed(chained_prefix_path)]@ -_colcon_prefix_chain_powershell_source_script "@(prefix)\@(prefix_script_no_ext).ps1" +_colcon_prefix_chain_powershell_source_script "@(prefix)@(os.sep)@(prefix_script_no_ext).ps1" @[ end for]@ @[end if]@ # source this prefix $env:COLCON_CURRENT_PREFIX=(Split-Path $PSCommandPath -Parent) -_colcon_prefix_chain_powershell_source_script "$env:COLCON_CURRENT_PREFIX\@(prefix_script_no_ext).ps1" +_colcon_prefix_chain_powershell_source_script "$env:COLCON_CURRENT_PREFIX@(os.sep)@(prefix_script_no_ext).ps1"