fix: emsdk swallows/overwrites parts of PATH (#642)
This PR has three changes: 1) Fixing --permanent flag: The previous algorithm looped over the values of PATH 4 times to check conditions while these conditions are the opposite of each other. Also, the result did not include all the parts in the whole_path. I have combined these loops and fixed the algorithm, so no path is lost. Now using --permanent the PATH and Env variables are correctly updated. 2) Fixing --system flag: Now, the system flag does not cause the PATH values to be overwritten/clobbered. The PATH/Env variables are correctly updated. 3) Fixing flagless flag: When no flag is provided the value of process/shell is correctly updated and preserved. This adds the tests for all the situations. Fixes #634 Fixes #645
This commit is contained in:
122
scripts/test_activation.ps1
Normal file
122
scripts/test_activation.ps1
Normal file
@@ -0,0 +1,122 @@
|
||||
# This test installs emsdk and activates the latest toolchain using `--system` or `--permanent` flags,
|
||||
# and checks if the environment variables and PATH are correctly updated. Set $env:SYSTEM_FLAG and $env:PERMANENT_FLAG to test each.
|
||||
# If no flag is provided the process/shell values are tested. See the CI file for an example.
|
||||
|
||||
refreshenv
|
||||
|
||||
$repo_root = [System.IO.Path]::GetDirectoryName((resolve-path "$PSScriptRoot"))
|
||||
|
||||
$PATH_USER_BEFORE = [System.Environment]::GetEnvironmentVariable("PATH", "User")
|
||||
$PATH_MACHINE_BEFORE = [System.Environment]::GetEnvironmentVariable("PATH", "Machine")
|
||||
$PATH_Process_BEFORE = [System.Environment]::GetEnvironmentVariable("PATH", "Process")
|
||||
|
||||
|
||||
try {
|
||||
|
||||
& "$repo_root/emsdk.ps1" install latest
|
||||
|
||||
$esc = '--%'
|
||||
& "$repo_root/emsdk.ps1" activate latest $esc $env:PERMANENT_FLAG $env:SYSTEM_FLAG
|
||||
|
||||
if ($env:SYSTEM_FLAG) {
|
||||
$env_type = "Machine"
|
||||
}
|
||||
elseif ($env:PERMANENT_FLAG) {
|
||||
$env_type = "User"
|
||||
} else {
|
||||
$env_type = "Process"
|
||||
}
|
||||
|
||||
$EMSDK = [System.Environment]::GetEnvironmentVariable("EMSDK", $env_type)
|
||||
$EM_CONFIG = [System.Environment]::GetEnvironmentVariable("EM_CONFIG", $env_type)
|
||||
$EMSDK_NODE = [System.Environment]::GetEnvironmentVariable("EMSDK_NODE", $env_type)
|
||||
$EMSDK_PYTHON = [System.Environment]::GetEnvironmentVariable("EMSDK_PYTHON", $env_type)
|
||||
$JAVA_HOME = [System.Environment]::GetEnvironmentVariable("JAVA_HOME", $env_type)
|
||||
$EM_CACHE = [System.Environment]::GetEnvironmentVariable("EM_CACHE", $env_type)
|
||||
$PATH = [System.Environment]::GetEnvironmentVariable("PATH", $env_type)
|
||||
|
||||
if (!$EMSDK) {
|
||||
throw "EMSDK is not set for the user"
|
||||
}
|
||||
if (!$EM_CONFIG) {
|
||||
throw "EM_CONFIG is not set for the user"
|
||||
}
|
||||
if (!$EMSDK_NODE) {
|
||||
throw "EMSDK_NODE is not set for the user"
|
||||
}
|
||||
if (!$JAVA_HOME) {
|
||||
throw "JAVA_HOME is not set for the user"
|
||||
}
|
||||
if (!$EMSDK_PYTHON) {
|
||||
throw "EMSDK_PYTHON is not set for the user"
|
||||
}
|
||||
if (!$EM_CACHE) {
|
||||
throw "EM_CACHE is not set for the user"
|
||||
}
|
||||
|
||||
|
||||
$path_split = $PATH.Split(';')
|
||||
|
||||
$EMSDK_Path = $path_split | Where-Object { $_ -like "$repo_root*" }
|
||||
if (!$EMSDK_Path) {
|
||||
throw "No path is added!"
|
||||
}
|
||||
$EMSDK_NODE_Path = $path_split | Where-Object { $_ -like "$repo_root\node*" }
|
||||
if (!$EMSDK_NODE_Path) {
|
||||
throw "$repo_root\\node is not added to path."
|
||||
}
|
||||
$EMSDK_PYTHON_Path = $path_split | Where-Object { $_ -like "$repo_root\python*" }
|
||||
if (!$EMSDK_PYTHON_Path) {
|
||||
throw "$repo_root\\python is not added to path."
|
||||
}
|
||||
$EMSDK_JAVA_Path = $path_split | Where-Object { $_ -like "$repo_root\java*" }
|
||||
if (!$EMSDK_JAVA_Path) {
|
||||
throw "$repo_root\\java is not added to path."
|
||||
}
|
||||
|
||||
$EMSDK_UPSTREAM_Path = $path_split | Where-Object { $_ -like "$repo_root\upstream\emscripten*" }
|
||||
if (!$EMSDK_UPSTREAM_Path) {
|
||||
throw "$repo_root\\upstream\emscripten is not added to path."
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
finally {
|
||||
# Recover pre-split PATH
|
||||
refreshenv
|
||||
|
||||
[Environment]::SetEnvironmentVariable("Path", $PATH_USER_BEFORE, "User")
|
||||
try {
|
||||
[Environment]::SetEnvironmentVariable("Path", $PATH_MACHINE_BEFORE, "Machine")
|
||||
}
|
||||
catch {}
|
||||
|
||||
[Environment]::SetEnvironmentVariable("Path", $PATH_Process_BEFORE, "Process")
|
||||
|
||||
# Recover pre activation env variables
|
||||
[Environment]::SetEnvironmentVariable("EMSDK", $null, "User")
|
||||
[Environment]::SetEnvironmentVariable("EM_CONFIG", $null, "User")
|
||||
[Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "User")
|
||||
[Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "User")
|
||||
[Environment]::SetEnvironmentVariable("JAVA_HOME", $null, "User")
|
||||
[Environment]::SetEnvironmentVariable("EM_CACHE", $null, "User")
|
||||
|
||||
try {
|
||||
[Environment]::SetEnvironmentVariable("EMSDK", $null, "Machine")
|
||||
[Environment]::SetEnvironmentVariable("EM_CONFIG", $null, "Machine")
|
||||
[Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "Machine")
|
||||
[Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "Machine")
|
||||
[Environment]::SetEnvironmentVariable("JAVA_HOME", $null, "Machine")
|
||||
[Environment]::SetEnvironmentVariable("EM_CACHE", $null, "Machine")
|
||||
} catch {}
|
||||
|
||||
|
||||
[Environment]::SetEnvironmentVariable("EMSDK", $null, "Process")
|
||||
[Environment]::SetEnvironmentVariable("EM_CONFIG", $null, "Process")
|
||||
[Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "Process")
|
||||
[Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "Process")
|
||||
[Environment]::SetEnvironmentVariable("JAVA_HOME", $null, "Process")
|
||||
[Environment]::SetEnvironmentVariable("EM_CACHE", $null, "Process")
|
||||
|
||||
refreshenv
|
||||
}
|
||||
151
scripts/test_path_preservation.ps1
Normal file
151
scripts/test_path_preservation.ps1
Normal file
@@ -0,0 +1,151 @@
|
||||
# This test installs emsdk and activates the latest toolchain using `--system` or `--permanent` flags,
|
||||
# and checks if parts of PATH are lost or overwritten. Set $env:SYSTEM_FLAG and $env:PERMANENT_FLAG to test each.
|
||||
# If no flag is provided the process/shell values are tested. See the CI file for an example.
|
||||
|
||||
refreshenv
|
||||
|
||||
$repo_root = [System.IO.Path]::GetDirectoryName((resolve-path "$PSScriptRoot"))
|
||||
|
||||
$PATH_USER_BEFORE = [System.Environment]::GetEnvironmentVariable("PATH", "User")
|
||||
$PATH_MACHINE_BEFORE = [System.Environment]::GetEnvironmentVariable("PATH", "Machine")
|
||||
$PATH_Process_BEFORE = [System.Environment]::GetEnvironmentVariable("PATH", "Process")
|
||||
|
||||
try {
|
||||
|
||||
|
||||
& "$repo_root/emsdk.ps1" install latest
|
||||
|
||||
$esc = '--%'
|
||||
& "$repo_root/emsdk.ps1" activate latest $esc $env:PERMANENT_FLAG $env:SYSTEM_FLAG
|
||||
|
||||
$PATH_USER = [System.Environment]::GetEnvironmentVariable("PATH", "User")
|
||||
$PATH_MACHINE = [System.Environment]::GetEnvironmentVariable("PATH", "Machine")
|
||||
$PATH_Process = [System.Environment]::GetEnvironmentVariable("PATH", "Process")
|
||||
|
||||
if ($env:SYSTEM_FLAG) {
|
||||
echo "--system test............................."
|
||||
$path_before_arr = $PATH_MACHINE_BEFORE.Split(';')
|
||||
$path_arr = $PATH_MACHINE.Split(';')
|
||||
}
|
||||
elseif ($env:PERMANENT_FLAG) {
|
||||
echo "--permanent test.........................."
|
||||
$path_before_arr = $PATH_USER_BEFORE.Split(';')
|
||||
$path_arr = $PATH_USER.Split(';')
|
||||
} else {
|
||||
echo "no flag test (shell/process).............."
|
||||
$path_before_arr = $PATH_Process_BEFORE.Split(';')
|
||||
$path_arr = $PATH_Process.Split(';')
|
||||
}
|
||||
|
||||
|
||||
$EMSDK_Path = $path_arr | Where-Object { $_ -like "$repo_root*" }
|
||||
$EMSDK_NODE_Path = $path_arr | Where-Object { $_ -like "$repo_root\node*" }
|
||||
$EMSDK_PYTHON_Path = $path_arr | Where-Object { $_ -like "$repo_root\python*" }
|
||||
$EMSDK_JAVA_Path = $path_arr | Where-Object { $_ -like "$repo_root\java*" }
|
||||
$EMSDK_UPSTREAM_Path = $path_arr | Where-Object { $_ -like "$repo_root\upstream\emscripten*" }
|
||||
|
||||
$number_of_items = $path_arr.count
|
||||
[System.Collections.ArrayList]$rest_of_path = @()
|
||||
Foreach ($item in $path_arr) {
|
||||
if (
|
||||
($item -like "$repo_root*") -or
|
||||
($item -like "$repo_root\node*") -or
|
||||
($item -like "$repo_root\python*") -or
|
||||
($item -like "$repo_root\java*") -or
|
||||
($item -like "$repo_root\upstream\emscripten*")
|
||||
) {
|
||||
echo "$item is on the PATH"
|
||||
}
|
||||
else {
|
||||
$rest_of_path.add($item) | Out-Null
|
||||
}
|
||||
}
|
||||
|
||||
# compare the PATHs before activation and after activation
|
||||
if (Compare-Object -ReferenceObject $path_before_arr -DifferenceObject $rest_of_path ) {
|
||||
echo "Old path is ............................."
|
||||
echo $path_before_arr
|
||||
echo "Current rest of path is ................."
|
||||
echo $rest_of_path
|
||||
throw "some parts of PATH are removed"
|
||||
}
|
||||
|
||||
# Compare the other untouched PATH
|
||||
if ($env:SYSTEM_FLAG) {
|
||||
if (Compare-Object -ReferenceObject $PATH_USER_BEFORE.Split(';') -DifferenceObject $PATH_USER.Split(';') ) {
|
||||
echo "Old user path is ...................."
|
||||
echo $PATH_USER_BEFORE
|
||||
echo "Current user path is ................"
|
||||
echo $PATH_USER
|
||||
throw "User PATH are changed while --system had been provided"
|
||||
}
|
||||
}
|
||||
elseif ($env:PERMANENT_FLAG) {
|
||||
if (Compare-Object -ReferenceObject $PATH_MACHINE_BEFORE.Split(';') -DifferenceObject $PATH_MACHINE.Split(';') ) {
|
||||
echo "Old machine path is.................."
|
||||
echo $PATH_MACHINE_BEFORE
|
||||
echo "Current machine path is.............."
|
||||
echo $PATH_MACHINE
|
||||
throw "MACHINE PATH are changed while --system was not provided"
|
||||
}
|
||||
} else {
|
||||
if (
|
||||
(Compare-Object -ReferenceObject $PATH_MACHINE_BEFORE.Split(';') -DifferenceObject $PATH_MACHINE.Split(';')) -or
|
||||
(Compare-Object -ReferenceObject $PATH_MACHINE_BEFORE.Split(';') -DifferenceObject $PATH_MACHINE.Split(';'))
|
||||
) {
|
||||
echo "Old machine path is.................."
|
||||
echo $PATH_MACHINE_BEFORE
|
||||
echo "Current machine path is.............."
|
||||
echo $PATH_MACHINE
|
||||
echo "Old user path is ...................."
|
||||
echo $PATH_USER_BEFORE
|
||||
echo "Current user path is ................"
|
||||
echo $PATH_USER
|
||||
throw "MACHINE/USER PATH are changed while no flag was provided"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
finally {
|
||||
# Recover pre-split PATH
|
||||
refreshenv
|
||||
|
||||
[Environment]::SetEnvironmentVariable("Path", $PATH_USER_BEFORE, "User")
|
||||
try {
|
||||
[Environment]::SetEnvironmentVariable("Path", $PATH_MACHINE_BEFORE, "Machine")
|
||||
}
|
||||
catch {}
|
||||
|
||||
[Environment]::SetEnvironmentVariable("Path", $PATH_Process_BEFORE, "Process")
|
||||
|
||||
# Recover pre activation env variables
|
||||
[Environment]::SetEnvironmentVariable("EMSDK", $null, "User")
|
||||
[Environment]::SetEnvironmentVariable("EM_CONFIG", $null, "User")
|
||||
[Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "User")
|
||||
[Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "User")
|
||||
[Environment]::SetEnvironmentVariable("JAVA_HOME", $null, "User")
|
||||
[Environment]::SetEnvironmentVariable("EM_CACHE", $null, "User")
|
||||
|
||||
try {
|
||||
[Environment]::SetEnvironmentVariable("EMSDK", $null, "Machine")
|
||||
[Environment]::SetEnvironmentVariable("EM_CONFIG", $null, "Machine")
|
||||
[Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "Machine")
|
||||
[Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "Machine")
|
||||
[Environment]::SetEnvironmentVariable("JAVA_HOME", $null, "Machine")
|
||||
[Environment]::SetEnvironmentVariable("EM_CACHE", $null, "Machine")
|
||||
} catch {}
|
||||
|
||||
|
||||
[Environment]::SetEnvironmentVariable("EMSDK", $null, "Process")
|
||||
[Environment]::SetEnvironmentVariable("EM_CONFIG", $null, "Process")
|
||||
[Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "Process")
|
||||
[Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "Process")
|
||||
[Environment]::SetEnvironmentVariable("JAVA_HOME", $null, "Process")
|
||||
[Environment]::SetEnvironmentVariable("EM_CACHE", $null, "Process")
|
||||
|
||||
refreshenv
|
||||
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
$repo_root = [System.IO.Path]::GetDirectoryName((resolve-path "$PSScriptRoot"))
|
||||
|
||||
& "$repo_root/emsdk.ps1" install latest
|
||||
& "$repo_root/emsdk.ps1" activate latest --permanent
|
||||
|
||||
$EMSDK_USER = [System.Environment]::GetEnvironmentVariable("EMSDK", "User")
|
||||
$EM_CONFIG_USER = [System.Environment]::GetEnvironmentVariable("EM_CONFIG", "User")
|
||||
$EMSDK_NODE_USER = [System.Environment]::GetEnvironmentVariable("EMSDK_NODE", "User")
|
||||
$EMSDK_PYTHON_USER = [System.Environment]::GetEnvironmentVariable("EMSDK_PYTHON", "User")
|
||||
$JAVA_HOME_USER = [System.Environment]::GetEnvironmentVariable("JAVA_HOME", "User")
|
||||
$EM_CACHE_USER = [System.Environment]::GetEnvironmentVariable("EM_CACHE", "User")
|
||||
$PATH_USER = [System.Environment]::GetEnvironmentVariable("PATH", "User")
|
||||
|
||||
if (!$EMSDK_USER) {
|
||||
throw "EMSDK is not set for the user"
|
||||
}
|
||||
if (!$EM_CONFIG_USER) {
|
||||
throw "EM_CONFIG_USER is not set for the user"
|
||||
}
|
||||
if (!$EMSDK_NODE_USER) {
|
||||
throw "EMSDK_NODE is not set for the user"
|
||||
}
|
||||
if (!$JAVA_HOME_USER) {
|
||||
throw "JAVA_HOME is not set for the user"
|
||||
}
|
||||
if (!$EMSDK_PYTHON_USER) {
|
||||
throw "EMSDK_PYTHON is not set for the user"
|
||||
}
|
||||
if (!$EM_CACHE_USER) {
|
||||
throw "EM_CACHE is not set for the user"
|
||||
}
|
||||
|
||||
|
||||
$path_split = $PATH_USER.Split(';')
|
||||
|
||||
$EMSDK_Path_USER = $path_split | Where-Object { $_ -like "$repo_root*" }
|
||||
if (!$EMSDK_Path_USER) {
|
||||
throw "No path is added!"
|
||||
}
|
||||
$EMSDK_NODE_Path_USER = $path_split | Where-Object { $_ -like "$repo_root\node*" }
|
||||
if (!$EMSDK_NODE_Path_USER) {
|
||||
throw "$repo_root\\node is not added to path."
|
||||
}
|
||||
$EMSDK_PYTHON_Path_USER = $path_split | Where-Object { $_ -like "$repo_root\python*" }
|
||||
if (!$EMSDK_PYTHON_Path_USER) {
|
||||
throw "$repo_root\\python is not added to path."
|
||||
}
|
||||
$EMSDK_JAVA_Path_USER = $path_split | Where-Object { $_ -like "$repo_root\java*" }
|
||||
if (!$EMSDK_JAVA_Path_USER) {
|
||||
throw "$repo_root\\java is not added to path."
|
||||
}
|
||||
|
||||
$EMSDK_UPSTREAM_Path_USER = $path_split | Where-Object { $_ -like "$repo_root\upstream\emscripten*" }
|
||||
if (!$EMSDK_UPSTREAM_Path_USER) {
|
||||
throw "$repo_root\\upstream\emscripten is not added to path."
|
||||
}
|
||||
Reference in New Issue
Block a user