emscripten-core / emsdk

Emscripten SDK
http://emscripten.org
Other
2.92k stars 662 forks source link

The variable '$EMSDK_PY' cannot be retrieved because it has not been set. #1337

Open xuboying opened 5 months ago

xuboying commented 5 months ago

commit: f2baa2f56a0c508c33ab2e16ef1efd3d548f42b8 PowerShell version: PowerShell 7.4.0

The installation script for PowerShell: "emsdk.ps1" is missing variable declaration for "$EMSDK_PY". Causing an exception The variable '$EMSDK_PY' cannot be retrieved because it has not been set.

The simplest workaround is to add a statement $EMSDK_PY="" at the beginning of that script.

sbc100 commented 5 months ago

That seems odd. We do run emsdk.ps1 as part of testing. (see https://github.com/emscripten-core/emsdk/blob/f2baa2f56a0c508c33ab2e16ef1efd3d548f42b8/test/test_activation.ps1#L16 for example)

Can you give the exact steps you took to reproduce along with the full output of the commands(s)?

sbc100 commented 5 months ago

perhaps there is some kind of strict mode where powershell requires variables to be declared before they are used?

sbc100 commented 5 months ago

Ah yes, is your powershell running in strict mode perhaps? (https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/set-strictmode?view=powershell-7.4)

xuboying commented 5 months ago

Bingo. I did set it in the profile "Microsoft.PowerShell_profile.ps1" but forgot about that. Looks like Set-StrictMode in the global profile is a bit overwhelming, I shall remove that it.

Thanks a lot for the correct Powershell reference! Would you consider the original workaround in my first post as an robustness improvement with low priority?

sbc100 commented 5 months ago

Yes, I think we should probably make out scripts work in strict mode.

However, I think the idea is that users might have set $EMSDK_PY outside the script.. so setting to empty string on startup doesn't seem right.

xuboying commented 5 months ago

aha. I'm not sure if you mean an environment variable, as I did not find this variable in the public document. If that is environment variable, unlike bash, Powershell has a special syntax

FYI

C:>echo %rapidjson_DIR% C:\usr\lib\rapidjson

C:>pwsh PowerShell 7.4.0

PS C:> Set-StrictMode -Version latest

PS C:> echo ${rapidjson_DIR} InvalidOperation: The variable '$rapidjson_DIR' cannot be retrieved because it has not been set. PS C:> echo ${env:rapidjson_DIR} C:\usr\lib\rapidjson PS C:> echo ${env:NOTEXISTS}

sbc100 commented 5 months ago

Actually it looks like that .bat version of this script does now allow the outside setting of EMDK_PY. So I guess its find that this one doesn't either.

sbc100 commented 5 months ago

Setting it to empty/null at the top makes sense to me. Perhaps we can run our tests in strict mode too.