comparison third_party/emsdk/test/test_path_preservation.ps1 @ 179:8d17f6e6e290

[ThirdParty] Added emsdk bazel rules that can be supported by bazel 9.0.0
author MrJuneJune <me@mrjunejune.com>
date Thu, 22 Jan 2026 21:23:17 -0800
parents
children
comparison
equal deleted inserted replaced
178:94705b5986b3 179:8d17f6e6e290
1 # This test installs emsdk and activates the latest toolchain using `--system` or `--permanent` flags,
2 # and checks if parts of PATH are lost or overwritten. Set $env:SYSTEM_FLAG and $env:PERMANENT_FLAG to test each.
3 # If no flag is provided the process/shell values are tested. See the CI file for an example.
4
5 refreshenv
6
7 $repo_root = [System.IO.Path]::GetDirectoryName((resolve-path "$PSScriptRoot"))
8
9 $PATH_USER_BEFORE = [System.Environment]::GetEnvironmentVariable("PATH", "User")
10 $PATH_MACHINE_BEFORE = [System.Environment]::GetEnvironmentVariable("PATH", "Machine")
11 $PATH_Process_BEFORE = [System.Environment]::GetEnvironmentVariable("PATH", "Process")
12
13 try {
14
15
16 & "$repo_root/emsdk.ps1" install latest
17
18 $esc = '--%'
19 & "$repo_root/emsdk.ps1" activate latest $esc $env:PERMANENT_FLAG $env:SYSTEM_FLAG
20
21 $PATH_USER = [System.Environment]::GetEnvironmentVariable("PATH", "User")
22 $PATH_MACHINE = [System.Environment]::GetEnvironmentVariable("PATH", "Machine")
23 $PATH_Process = [System.Environment]::GetEnvironmentVariable("PATH", "Process")
24
25 if ($env:SYSTEM_FLAG) {
26 echo "--system test............................."
27 $path_before_arr = $PATH_MACHINE_BEFORE.Split(';')
28 $path_arr = $PATH_MACHINE.Split(';')
29 }
30 elseif ($env:PERMANENT_FLAG) {
31 echo "--permanent test.........................."
32 $path_before_arr = $PATH_USER_BEFORE.Split(';')
33 $path_arr = $PATH_USER.Split(';')
34 } else {
35 echo "no flag test (shell/process).............."
36 $path_before_arr = $PATH_Process_BEFORE.Split(';')
37 $path_arr = $PATH_Process.Split(';')
38 }
39
40
41 $EMSDK_Path = $path_arr | Where-Object { $_ -like "$repo_root*" }
42 $EMSDK_NODE_Path = $path_arr | Where-Object { $_ -like "$repo_root\node*" }
43 $EMSDK_PYTHON_Path = $path_arr | Where-Object { $_ -like "$repo_root\python*" }
44 $EMSDK_JAVA_Path = $path_arr | Where-Object { $_ -like "$repo_root\java*" }
45 $EMSDK_UPSTREAM_Path = $path_arr | Where-Object { $_ -like "$repo_root\upstream\emscripten*" }
46
47 $number_of_items = $path_arr.count
48 [System.Collections.ArrayList]$rest_of_path = @()
49 Foreach ($item in $path_arr) {
50 if (
51 ($item -like "$repo_root*") -or
52 ($item -like "$repo_root\node*") -or
53 ($item -like "$repo_root\python*") -or
54 ($item -like "$repo_root\java*") -or
55 ($item -like "$repo_root\upstream\emscripten*")
56 ) {
57 echo "$item is on the PATH"
58 }
59 else {
60 $rest_of_path.add($item) | Out-Null
61 }
62 }
63
64 # compare the PATHs before activation and after activation
65 if (Compare-Object -ReferenceObject $path_before_arr -DifferenceObject $rest_of_path ) {
66 echo "Old path is ............................."
67 echo $path_before_arr
68 echo "Current rest of path is ................."
69 echo $rest_of_path
70 throw "some parts of PATH are removed"
71 }
72
73 # Compare the other untouched PATH
74 if ($env:SYSTEM_FLAG) {
75 if (Compare-Object -ReferenceObject $PATH_USER_BEFORE.Split(';') -DifferenceObject $PATH_USER.Split(';') ) {
76 echo "Old user path is ...................."
77 echo $PATH_USER_BEFORE
78 echo "Current user path is ................"
79 echo $PATH_USER
80 throw "User PATH are changed while --system had been provided"
81 }
82 }
83 elseif ($env:PERMANENT_FLAG) {
84 if (Compare-Object -ReferenceObject $PATH_MACHINE_BEFORE.Split(';') -DifferenceObject $PATH_MACHINE.Split(';') ) {
85 echo "Old machine path is.................."
86 echo $PATH_MACHINE_BEFORE
87 echo "Current machine path is.............."
88 echo $PATH_MACHINE
89 throw "MACHINE PATH are changed while --system was not provided"
90 }
91 } else {
92 if (
93 (Compare-Object -ReferenceObject $PATH_MACHINE_BEFORE.Split(';') -DifferenceObject $PATH_MACHINE.Split(';')) -or
94 (Compare-Object -ReferenceObject $PATH_MACHINE_BEFORE.Split(';') -DifferenceObject $PATH_MACHINE.Split(';'))
95 ) {
96 echo "Old machine path is.................."
97 echo $PATH_MACHINE_BEFORE
98 echo "Current machine path is.............."
99 echo $PATH_MACHINE
100 echo "Old user path is ...................."
101 echo $PATH_USER_BEFORE
102 echo "Current user path is ................"
103 echo $PATH_USER
104 throw "MACHINE/USER PATH are changed while no flag was provided"
105 }
106 }
107
108
109
110
111 }
112 finally {
113 # Recover pre-split PATH
114 refreshenv
115
116 [Environment]::SetEnvironmentVariable("Path", $PATH_USER_BEFORE, "User")
117 try {
118 [Environment]::SetEnvironmentVariable("Path", $PATH_MACHINE_BEFORE, "Machine")
119 }
120 catch {}
121
122 [Environment]::SetEnvironmentVariable("Path", $PATH_Process_BEFORE, "Process")
123
124 # Recover pre activation env variables
125 [Environment]::SetEnvironmentVariable("EMSDK", $null, "User")
126 [Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "User")
127 [Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "User")
128
129 try {
130 [Environment]::SetEnvironmentVariable("EMSDK", $null, "Machine")
131 [Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "Machine")
132 [Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "Machine")
133 } catch {}
134
135
136 [Environment]::SetEnvironmentVariable("EMSDK", $null, "Process")
137 [Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "Process")
138 [Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "Process")
139
140 refreshenv
141
142 }