forked from espressif/esp-idf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
export.ps1
92 lines (76 loc) · 3.47 KB
/
export.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env pwsh
$S = [IO.Path]::PathSeparator # path separator. WIN:';', UNIX:":"
$IDF_PATH = "$PSScriptRoot"
Write-Output "Setting IDF_PATH: $IDF_PATH"
$env:IDF_PATH = "$IDF_PATH"
Write-Output "Checking Python compatibility"
python "$IDF_PATH/tools/python_version_checker.py"
Write-Output "Adding ESP-IDF tools to PATH..."
$OLD_PATH = $env:PATH.split($S) | Select-Object -Unique # array without duplicates
# using idf_tools.py to get $envars_array to set
$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:
# [
# [vname1, vval1], [vname2, vval2], ...
# ]
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
$envars_array += (, ($var_name, $var_val))
}
if ($IsWindows -eq $null) {
# $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
}
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
if ($var_name -eq "PATH") {
# trim "%PATH%" or "`$PATH"
if ($IsWindows) {
$var_val = $var_val.Trim($S + "%PATH%")
} else {
$var_val = $var_val.Trim($S + "`$PATH")
}
# apply
$env:PATH = $var_val + $S + $env:PATH
} else {
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 = ${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
$NEW_PATH = $env:PATH.split($S) | Select-Object -Unique # array without duplicates
$dif_Path = Compare-Object -ReferenceObject $OLD_PATH -DifferenceObject $NEW_PATH -PassThru
if ($dif_Path -ne $null) {
Write-Output "`nAdded to PATH`n-------------"
Write-Output $dif_Path
} else {
Write-Output "No directories added to PATH:"
Write-Output $OLD_PATH
}
Write-Output "Checking if Python packages are up to date..."
Start-Process -Wait -NoNewWindow -FilePath "python" -Args "`"$IDF_PATH/tools/idf_tools.py`" check-python-dependencies"
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } # if error
$uninstall = python "$IDF_PATH/tools/idf_tools.py" uninstall --dry-run
if (![string]::IsNullOrEmpty($uninstall)){
Write-Output ""
Write-Output "Detected installed tools that are not currently used by active ESP-IDF version."
Write-Output "$uninstall"
Write-Output "For free up even more space, remove installation packages of those tools. Use option 'python.exe $IDF_PATH\tools\idf_tools.py uninstall --remove-archives'."
Write-Output ""
}
Write-Output "
Done! You can now compile ESP-IDF projects.
Go to the project directory and run:
idf.py build
"