Skip to content

Commit 01d55b9

Browse files
committed
Merge branch 'feature/export_ps1_tools' into 'master'
scripts: updates export.ps1 to export tools' paths See merge request espressif/esp-idf!9725
2 parents 79da52f + f2c6a64 commit 01d55b9

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

export.ps1

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#!/usr/bin/env pwsh
2+
$S = [IO.Path]::PathSeparator # path separator. WIN:';', UNIX:":"
3+
24
$IDF_PATH = $PSScriptRoot
35

46
Write-Output "Setting IDF_PATH: $IDF_PATH"
5-
$env:IDF_PATH=$IDF_PATH
7+
$env:IDF_PATH = $IDF_PATH
68

79
Write-Output "Adding ESP-IDF tools to PATH..."
8-
$OLD_PATH=$env:PATH.split([IO.Path]::PathSeparator) | Select-Object -Unique # array without duplicates
10+
$OLD_PATH = $env:PATH.split($S) | Select-Object -Unique # array without duplicates
911
# using idf_tools.py to get $envars_array to set
1012
$envars_raw = python $IDF_PATH/tools/idf_tools.py export --format key-value
1113
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } # if error
@@ -14,40 +16,46 @@ $envars_array # will be filled like:
1416
# [
1517
# [vname1, vval1], [vname2, vval2], ...
1618
# ]
17-
foreach ($line in $envars_raw)
18-
{
19+
foreach ($line in $envars_raw) {
1920
$pair = $line.split("=") # split in name, val
2021
$var_name = $pair[0].Trim() # trim spaces on the ends of the name
2122
$var_val = $pair[1].Trim() # trim spaces on the ends of the val
22-
$envars_array+=(,($var_name, $var_val))
23+
$envars_array += (, ($var_name, $var_val))
2324
}
2425

25-
foreach ($pair in $envars_array) # setting the values
26-
{
26+
foreach ($pair in $envars_array) {
27+
# setting the values
2728
$var_name = $pair[0].Trim() # trim spaces on the ends of the name
2829
$var_val = $pair[1].Trim() # trim spaces on the ends of the val
29-
if ($var_name -eq "PATH"){
30+
if ($var_name -eq "PATH") {
3031
# trim "%PATH%" or "`$PATH"
31-
if($IsWindows){
32-
$var_val = $var_val.Trim([IO.Path]::PathSeparator + "%PATH%")
33-
}else{
34-
$var_val = $var_val.Trim([IO.Path]::PathSeparator + "`$PATH")
32+
if ($IsWindows) {
33+
$var_val = $var_val.Trim($S + "%PATH%")
34+
} else {
35+
$var_val = $var_val.Trim($S + "`$PATH")
3536
}
3637
# apply
37-
$env:PATH = $var_val + [IO.Path]::PathSeparator + $env:PATH
38+
$env:PATH = $var_val + $S + $env:PATH
3839
} else {
39-
New-Item -Path "env:$var_name" -Value "$var_val"
40+
New-Item -Path "env:$var_name" -Value "$var_val" -Force
4041
}
4142
}
4243

44+
# Allow calling some IDF python tools without specifying the full path
45+
# ${IDF_PATH}/tools is already added by 'idf_tools.py export'
46+
$IDF_ADD_PATHS_EXTRAS = [IO.Path]::Combine(${IDF_PATH}, "components", "esptool_py", "esptool")
47+
$IDF_ADD_PATHS_EXTRAS += ${S} + [IO.Path]::Combine(${IDF_PATH}, "components", "app_update")
48+
$IDF_ADD_PATHS_EXTRAS += ${S} + [IO.Path]::Combine(${IDF_PATH}, "components", "espcoredump")
49+
$IDF_ADD_PATHS_EXTRAS += ${S} + [IO.Path]::Combine(${IDF_PATH}, "components", "partition_table")
50+
$env:PATH = $IDF_ADD_PATHS_EXTRAS + $S + $env:PATH
51+
4352
#Compare Path's OLD vs. NEW
44-
$NEW_PATH = $env:PATH.split([IO.Path]::PathSeparator) | Select-Object -Unique # array without duplicates
53+
$NEW_PATH = $env:PATH.split($S) | Select-Object -Unique # array without duplicates
4554
$dif_Path = Compare-Object -ReferenceObject $OLD_PATH -DifferenceObject $NEW_PATH -PassThru
46-
if ($dif_Path -ne $null)
47-
{
55+
if ($dif_Path -ne $null) {
56+
Write-Output "`nAdded to PATH`n-------------"
4857
Write-Output $dif_Path
49-
}
50-
else {
58+
} else {
5159
Write-Output "No directories added to PATH:"
5260
Write-Output $OLD_PATH
5361
}

0 commit comments

Comments
 (0)