From 35a949ea66bb0137e187841a82920a10836e8f00 Mon Sep 17 00:00:00 2001 From: Chris Mumford Date: Tue, 2 Nov 2021 19:12:15 -0700 Subject: [PATCH 1/3] Initialize `$envvars_array` to an empty list. With strict debugging, i.e. `Set-PSDebug -strict`, execution of export.ps1 will report the following error: ``` The variable '$envars_array' cannot be retrieved because it has not been set. At C:\path\to\export.ps1:15 char:1 + $envars_array # will be filled like: + ~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (envars_array:String) [], RuntimeException + FullyQualifiedErrorId : VariableIsUndefined ``` Closes https://github.com/espressif/esp-idf/pull/7819 --- export.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/export.ps1 b/export.ps1 index 2daa7575aa..4ecf066eb5 100644 --- a/export.ps1 +++ b/export.ps1 @@ -12,7 +12,7 @@ $OLD_PATH = $env:PATH.split($S) | Select-Object -Unique # array without duplicat $envars_raw = python $IDF_PATH/tools/idf_tools.py export --format key-value if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } # if error -$envars_array # will be filled like: +$envars_array = @() # will be filled like: # [ # [vname1, vval1], [vname2, vval2], ... # ] From ddf79c2be952e08d6bbfdcc47246da05f8ef677f Mon Sep 17 00:00:00 2001 From: Chris Mumford Date: Mon, 8 Nov 2021 18:47:35 -0800 Subject: [PATCH 2/3] Define $IsWindows if not defined. The `$IsWindows` PowerShell variable was added in PowerShell Core 6 and PowerShell 7, and is not present in earlier PowerShell versions. Set to true if undefined. This fixes https://github.com/espressif/esp-idf/issues/7820. The first version to run on non-Windows platforms was PowerShell Core 6.0[^1] which means that IsWindows is guaranteed to be defined on all non-Windows systems. So, if undefined this indicates a Windows platform. [^1]: https://docs.microsoft.com/en-us/powershell/scripting/install/powershell-support-lifecycle?view=powershell-7.2#release-history Closes https://github.com/espressif/esp-idf/pull/7858 Closes https://github.com/espressif/esp-idf/issues/7820 --- export.ps1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/export.ps1 b/export.ps1 index 4ecf066eb5..7efc639ca5 100644 --- a/export.ps1 +++ b/export.ps1 @@ -23,6 +23,11 @@ foreach ($line in $envars_raw) { $envars_array += (, ($var_name, $var_val)) } +if ($IsWindows -eq $null) { + # $IsWindows was added in PowerShell Core 6 and PowerShell 7. + $IsWindows = $true +} + foreach ($pair in $envars_array) { # setting the values $var_name = $pair[0].Trim() # trim spaces on the ends of the name From 896f6f2dfc74755a2b81c9d8f096650b3215cd7e Mon Sep 17 00:00:00 2001 From: Roland Dobai Date: Tue, 9 Nov 2021 11:28:48 +0100 Subject: [PATCH 3/3] Tools: Make clear the used platform in the PowerShell export script --- export.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/export.ps1 b/export.ps1 index 7efc639ca5..ce92c15108 100644 --- a/export.ps1 +++ b/export.ps1 @@ -24,7 +24,8 @@ foreach ($line in $envars_raw) { } if ($IsWindows -eq $null) { - # $IsWindows was added in PowerShell Core 6 and PowerShell 7. + # $IsWindows was added in PowerShell Core 6 and PowerShell 7 together with multi-platform support. # I.E. if this + # internal variable is not set then PowerShell 5 is used and # the platform cannot be # anything else than Windows. $IsWindows = $true }