comparison third_party/emsdk/test/test_activation.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 the environment variables and PATH are correctly updated. 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
14 try {
15
16 & "$repo_root/emsdk.ps1" install latest
17
18 & "$repo_root/emsdk.ps1" activate latest $env:PERMANENT_FLAG $env:SYSTEM_FLAG
19
20 if ($env:SYSTEM_FLAG) {
21 $env_type = "Machine"
22 }
23 elseif ($env:PERMANENT_FLAG) {
24 $env_type = "User"
25 } else {
26 $env_type = "Process"
27 }
28
29 $EMSDK = [System.Environment]::GetEnvironmentVariable("EMSDK", $env_type)
30 $EMSDK_NODE = [System.Environment]::GetEnvironmentVariable("EMSDK_NODE", $env_type)
31 $EMSDK_PYTHON = [System.Environment]::GetEnvironmentVariable("EMSDK_PYTHON", $env_type)
32 $PATH = [System.Environment]::GetEnvironmentVariable("PATH", $env_type)
33
34 if (!$EMSDK) {
35 throw "EMSDK is not set for the user"
36 }
37 if (!$EMSDK_NODE) {
38 throw "EMSDK_NODE is not set for the user"
39 }
40 if (!$EMSDK_PYTHON) {
41 throw "EMSDK_PYTHON is not set for the user"
42 }
43
44
45 $path_split = $PATH.Split(';')
46
47 $EMSDK_Path = $path_split | Where-Object { $_ -like "$repo_root*" }
48 if (!$EMSDK_Path) {
49 throw "No path is added!"
50 }
51
52 $EMSDK_UPSTREAM_Path = $path_split | Where-Object { $_ -like "$repo_root\upstream\emscripten*" }
53 if (!$EMSDK_UPSTREAM_Path) {
54 throw "$repo_root\\upstream\emscripten is not added to path."
55 }
56
57
58 }
59 finally {
60 # Recover pre-split PATH
61 refreshenv
62
63 [Environment]::SetEnvironmentVariable("Path", $PATH_USER_BEFORE, "User")
64 try {
65 [Environment]::SetEnvironmentVariable("Path", $PATH_MACHINE_BEFORE, "Machine")
66 }
67 catch {}
68
69 [Environment]::SetEnvironmentVariable("Path", $PATH_Process_BEFORE, "Process")
70
71 # Recover pre activation env variables
72 [Environment]::SetEnvironmentVariable("EMSDK", $null, "User")
73 [Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "User")
74 [Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "User")
75
76 try {
77 [Environment]::SetEnvironmentVariable("EMSDK", $null, "Machine")
78 [Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "Machine")
79 [Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "Machine")
80 } catch {}
81
82
83 [Environment]::SetEnvironmentVariable("EMSDK", $null, "Process")
84 [Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "Process")
85 [Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "Process")
86
87 refreshenv
88 }