add find_msvs custom command to the nu_msvs module (#881)

I changed `export-env {}` at the beginning to a custom command to avoid
having `export-env` run when loading the module
  because:
1. I couldn't use `nu_msvs activate` because it depends on env vars
being set that were hidden with `nu_msvs deactivate`
2. It seems that `export-env` executed at `use`, leaves `$env.FILE_PWD`
available in the environment which I think may be
     a bug. So, putting it in a custom command avoids that.
This commit is contained in:
Darren Schroeder 2024-06-18 08:09:04 -05:00 committed by GitHub
parent 92f20ff282
commit ddbebf197d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,5 @@
export-env {
def --env find_msvs [] {
export-env {
$env.MSVS_BASE_PATH = $env.Path
$env.PATH_VAR = (if "Path" in $env { "Path" } else { "PATH" })
@ -58,6 +59,7 @@ export-env {
# print $"MSVS_MSDK_ROOT: ($env.MSVS_MSDK_ROOT)"
# print $"MSVS_MSDK_VER: ($env.MSVS_MSDK_VER)"
# print $"MSVS_INCLUDE_PATH: ($env.MSVS_INCLUDE_PATH)"
}
}
export def --env activate [
@ -65,6 +67,13 @@ export def --env activate [
--target (-t): string = x64, # Target architecture, must be x64 or x86 (case insensitive)
--sdk (-s): string = latest # Version of Windows SDK, must be "latest" or a valid version string
] {
# I changed export-env {} to a custom command to avoid having export-env run when loading the module
# because:
# 1. I couldn't use activate because it depends on env vars being set that were hidden with deactivate
# 2. It seems that export-env executed at `use`, leaves `$env.FILE_PWD` available in the environment
# which I think may be a bug. So, putting it in a custom command avoids that.
find_msvs
if (($env.MSVS_ROOT | is-empty) or ($env.MSVS_MSVC_ROOT | is-empty)) {
print "Either Microsoft Visual Studio or MSVC is valid."
return