kopia lustrzana https://github.com/espressif/esp-idf
Merge branch 'feature/export_ps1_tools' into 'master'
scripts: updates export.ps1 to export tools' paths See merge request espressif/esp-idf!9725pull/5778/head
commit
01d55b9aea
46
export.ps1
46
export.ps1
|
@ -1,11 +1,13 @@
|
||||||
#!/usr/bin/env pwsh
|
#!/usr/bin/env pwsh
|
||||||
|
$S = [IO.Path]::PathSeparator # path separator. WIN:';', UNIX:":"
|
||||||
|
|
||||||
$IDF_PATH = $PSScriptRoot
|
$IDF_PATH = $PSScriptRoot
|
||||||
|
|
||||||
Write-Output "Setting IDF_PATH: $IDF_PATH"
|
Write-Output "Setting IDF_PATH: $IDF_PATH"
|
||||||
$env:IDF_PATH=$IDF_PATH
|
$env:IDF_PATH = $IDF_PATH
|
||||||
|
|
||||||
Write-Output "Adding ESP-IDF tools to PATH..."
|
Write-Output "Adding ESP-IDF tools to PATH..."
|
||||||
$OLD_PATH=$env:PATH.split([IO.Path]::PathSeparator) | Select-Object -Unique # array without duplicates
|
$OLD_PATH = $env:PATH.split($S) | Select-Object -Unique # array without duplicates
|
||||||
# using idf_tools.py to get $envars_array to set
|
# using idf_tools.py to get $envars_array to set
|
||||||
$envars_raw = python $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
|
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } # if error
|
||||||
|
@ -14,40 +16,46 @@ $envars_array # will be filled like:
|
||||||
# [
|
# [
|
||||||
# [vname1, vval1], [vname2, vval2], ...
|
# [vname1, vval1], [vname2, vval2], ...
|
||||||
# ]
|
# ]
|
||||||
foreach ($line in $envars_raw)
|
foreach ($line in $envars_raw) {
|
||||||
{
|
|
||||||
$pair = $line.split("=") # split in name, val
|
$pair = $line.split("=") # split in name, val
|
||||||
$var_name = $pair[0].Trim() # trim spaces on the ends of the name
|
$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 = $pair[1].Trim() # trim spaces on the ends of the val
|
||||||
$envars_array+=(,($var_name, $var_val))
|
$envars_array += (, ($var_name, $var_val))
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($pair in $envars_array) # setting the values
|
foreach ($pair in $envars_array) {
|
||||||
{
|
# setting the values
|
||||||
$var_name = $pair[0].Trim() # trim spaces on the ends of the name
|
$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 = $pair[1].Trim() # trim spaces on the ends of the val
|
||||||
if ($var_name -eq "PATH"){
|
if ($var_name -eq "PATH") {
|
||||||
# trim "%PATH%" or "`$PATH"
|
# trim "%PATH%" or "`$PATH"
|
||||||
if($IsWindows){
|
if ($IsWindows) {
|
||||||
$var_val = $var_val.Trim([IO.Path]::PathSeparator + "%PATH%")
|
$var_val = $var_val.Trim($S + "%PATH%")
|
||||||
}else{
|
} else {
|
||||||
$var_val = $var_val.Trim([IO.Path]::PathSeparator + "`$PATH")
|
$var_val = $var_val.Trim($S + "`$PATH")
|
||||||
}
|
}
|
||||||
# apply
|
# apply
|
||||||
$env:PATH = $var_val + [IO.Path]::PathSeparator + $env:PATH
|
$env:PATH = $var_val + $S + $env:PATH
|
||||||
} else {
|
} else {
|
||||||
New-Item -Path "env:$var_name" -Value "$var_val"
|
New-Item -Path "env:$var_name" -Value "$var_val" -Force
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Allow calling some IDF python tools without specifying the full path
|
||||||
|
# ${IDF_PATH}/tools is already added by 'idf_tools.py export'
|
||||||
|
$IDF_ADD_PATHS_EXTRAS = [IO.Path]::Combine(${IDF_PATH}, "components", "esptool_py", "esptool")
|
||||||
|
$IDF_ADD_PATHS_EXTRAS += ${S} + [IO.Path]::Combine(${IDF_PATH}, "components", "app_update")
|
||||||
|
$IDF_ADD_PATHS_EXTRAS += ${S} + [IO.Path]::Combine(${IDF_PATH}, "components", "espcoredump")
|
||||||
|
$IDF_ADD_PATHS_EXTRAS += ${S} + [IO.Path]::Combine(${IDF_PATH}, "components", "partition_table")
|
||||||
|
$env:PATH = $IDF_ADD_PATHS_EXTRAS + $S + $env:PATH
|
||||||
|
|
||||||
#Compare Path's OLD vs. NEW
|
#Compare Path's OLD vs. NEW
|
||||||
$NEW_PATH = $env:PATH.split([IO.Path]::PathSeparator) | Select-Object -Unique # array without duplicates
|
$NEW_PATH = $env:PATH.split($S) | Select-Object -Unique # array without duplicates
|
||||||
$dif_Path = Compare-Object -ReferenceObject $OLD_PATH -DifferenceObject $NEW_PATH -PassThru
|
$dif_Path = Compare-Object -ReferenceObject $OLD_PATH -DifferenceObject $NEW_PATH -PassThru
|
||||||
if ($dif_Path -ne $null)
|
if ($dif_Path -ne $null) {
|
||||||
{
|
Write-Output "`nAdded to PATH`n-------------"
|
||||||
Write-Output $dif_Path
|
Write-Output $dif_Path
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Write-Output "No directories added to PATH:"
|
Write-Output "No directories added to PATH:"
|
||||||
Write-Output $OLD_PATH
|
Write-Output $OLD_PATH
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue