From bc42073a8bd1bb14c4d3eb0c2ce4354f7e42066a Mon Sep 17 00:00:00 2001 From: Andrei Gramakov Date: Wed, 13 May 2020 14:00:38 +0200 Subject: [PATCH] fixes for powershell on unix --- export.ps1 | 30 +++++++++++++++++------------- install.ps1 | 11 +++-------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/export.ps1 b/export.ps1 index a2cafd55ae..7d9c66b19d 100644 --- a/export.ps1 +++ b/export.ps1 @@ -1,21 +1,16 @@ -if ($env:MSYSTEM -ne $null) { - Write-Output "This .ps1 file is for Windows Powershell only. When using MSYS, run:`n. ./export.sh." - exit 1 -} - - +#!/usr/bin/env pwsh $IDF_PATH = $PSScriptRoot Write-Output "Setting IDF_PATH: $IDF_PATH" $env:IDF_PATH=$IDF_PATH Write-Output "Adding ESP-IDF tools to PATH..." -$OLD_PATH=$env:Path.split(";") | Select-Object -Unique # array without duplicates +$OLD_PATH=$env:PATH.split([IO.Path]::PathSeparator) | Select-Object -Unique # array without duplicates # using idf_tools.py to get $envars_array to set -$envars_raw = python.exe $IDF_PATH\tools\idf_tools.py export --format key-value +$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], ... # ] @@ -24,8 +19,6 @@ foreach ($line in $envars_raw) $pair = $line.split("=") # split in name, val $var_name = $pair[0].Trim() # trim spaces on the ends of the name $var_val = $pair[1].Trim() # trim spaces on the ends of the val - $var_val = $var_val -replace "%(.+)%", "`$env:`$1" # convert var syntax to PS using RegEx - $var_val = $ExecutionContext.InvokeCommand.ExpandString($var_val) # expand variables to values $envars_array+=(,($var_name, $var_val)) } @@ -33,11 +26,22 @@ foreach ($pair in $envars_array) # setting the values { $var_name = $pair[0].Trim() # trim spaces on the ends of the name $var_val = $pair[1].Trim() # trim spaces on the ends of the val - Set-Item -Path "Env:$var_name" -Value "$var_val" + if ($var_name -eq "PATH"){ + # trim "%PATH%" or "`$PATH" + if($IsWindows){ + $var_val = $var_val.Trim([IO.Path]::PathSeparator + "%PATH%") + }else{ + $var_val = $var_val.Trim([IO.Path]::PathSeparator + "`$PATH") + } + # apply + $env:PATH = $var_val + [IO.Path]::PathSeparator + $env:PATH + } else { + New-Item -Path "env:$var_name" -Value "$var_val" + } } #Compare Path's OLD vs. NEW -$NEW_PATH = $env:Path.split(";") | Select-Object -Unique # array without duplicates +$NEW_PATH = $env:PATH.split([IO.Path]::PathSeparator) | Select-Object -Unique # array without duplicates $dif_Path = Compare-Object -ReferenceObject $OLD_PATH -DifferenceObject $NEW_PATH -PassThru if ($dif_Path -ne $null) { diff --git a/install.ps1 b/install.ps1 index 8067df81ee..df55bd3e2d 100644 --- a/install.ps1 +++ b/install.ps1 @@ -1,18 +1,13 @@ -if ($env:MSYSTEM -ne $null) { - Write-Output "This .ps1 file is for Windows Powershell only. When using MSYS, run:`n. ./export.sh." - exit 1 -} - - +#!/usr/bin/env pwsh $IDF_PATH = $PSScriptRoot Write-Output "Installing ESP-IDF tools" -Start-Process -Wait -NoNewWindow -FilePath "python.exe" -Args "$IDF_PATH/tools/idf_tools.py install" +Start-Process -Wait -NoNewWindow -FilePath "python" -Args "$IDF_PATH/tools/idf_tools.py install" if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } # if error Write-Output "Setting up Python environment" -Start-Process -Wait -NoNewWindow -FilePath "python.exe" -Args "$IDF_PATH/tools/idf_tools.py install-python-env" +Start-Process -Wait -NoNewWindow -FilePath "python" -Args "$IDF_PATH/tools/idf_tools.py install-python-env" if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE} # if error