Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
xuboying opened this issue Jan 29, 2024 · 8 comments
Open

Comments

@xuboying
Copy link

commit: f2baa2f
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
Copy link
Collaborator

sbc100 commented Jan 29, 2024

That seems odd. We do run emsdk.ps1 as part of testing. (see

& "$repo_root/emsdk.ps1" install latest
for example)

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

@sbc100
Copy link
Collaborator

sbc100 commented Jan 29, 2024

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

@sbc100
Copy link
Collaborator

sbc100 commented Jan 29, 2024

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
Copy link
Author

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
Copy link
Collaborator

sbc100 commented Jan 30, 2024

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
Copy link
Author

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
Copy link
Collaborator

sbc100 commented Jan 30, 2024

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
Copy link
Collaborator

sbc100 commented Jan 30, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants