diff options
| author | ruki <[email protected]> | 2021-11-06 20:39:16 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-11-06 20:39:16 +0800 |
| commit | 736dc4db6368fa4dd1770e768c5577bc8d55255d (patch) | |
| tree | 7909ee3cf27c5bb190fd7f80c7e36dbb07d9ddbc | |
| parent | 95dea5af25edb9f1eda15ad8412342e26ef39525 (diff) | |
| parent | 6bbb5f94c3beadf5d5dfc6db59d05a686647a39b (diff) | |
Merge pull request #1808 from xq114/dev
improve env config
| -rw-r--r-- | scripts/register-virtualenvs.sh | 1 | ||||
| -rwxr-xr-x | scripts/xrepo.bat | 4 | ||||
| -rw-r--r-- | xmake/modules/detect/sdks/find_vstudio.lua | 100 | ||||
| -rw-r--r-- | xmake/modules/private/xrepo/action/env.lua | 8 | ||||
| -rw-r--r-- | xmake/scripts/xrepo-hook.psm1 | 5 | ||||
| -rw-r--r-- | xmake/toolchains/msvc/load.lua | 16 |
6 files changed, 87 insertions, 47 deletions
diff --git a/scripts/register-virtualenvs.sh b/scripts/register-virtualenvs.sh index 8518060f8..cf067d040 100644 --- a/scripts/register-virtualenvs.sh +++ b/scripts/register-virtualenvs.sh @@ -47,6 +47,7 @@ function xrepo { unset XMAKE_PROMPT_BACKUP unset XMAKE_ENV_BACKUP fi + "$XMAKE_EXE" lua private.xrepo.action.env.info config $bnd || return 1 local prompt="$("$XMAKE_EXE" lua --quiet private.xrepo.action.env.info prompt $bnd)" || return 1 if [ -z "${prompt+x}" ]; then return 1 diff --git a/scripts/xrepo.bat b/scripts/xrepo.bat index 82180398a..0416d4a10 100755 --- a/scripts/xrepo.bat +++ b/scripts/xrepo.bat @@ -81,6 +81,10 @@ exit /B 1 ) else ( setlocal EnableDelayedExpansion + %XMAKE_EXE% lua private.xrepo.action.env.info config %3 + if !errorlevel! neq 0 ( + exit /B !errorlevel! + ) @%XMAKE_EXE% lua --quiet private.xrepo.action.env.info prompt %3 1>nul if !errorlevel! neq 0 ( echo error: environment not found^^! diff --git a/xmake/modules/detect/sdks/find_vstudio.lua b/xmake/modules/detect/sdks/find_vstudio.lua index 2934d23c8..0abbb131c 100644 --- a/xmake/modules/detect/sdks/find_vstudio.lua +++ b/xmake/modules/detect/sdks/find_vstudio.lua @@ -28,15 +28,72 @@ local vcvars = {"path", "libpath", "include", "DevEnvdir", - "VSInstallDir", - "VCInstallDir", + "VSINSTALLDIR", + "VCINSTALLDIR", "WindowsSdkDir", "WindowsLibPath", "WindowsSDKVersion", "WindowsSdkBinPath", + "WindowsSdkVerBinPath", + "ExtensionSdkDir", "UniversalCRTSdkDir", "UCRTVersion", - "VCToolsVersion"} + "VCToolsVersion", + "VCIDEInstallDir", + "VCToolsInstallDir", + "VCToolsRedistDir", + "VisualStudioVersion", + "VSCMD_VER", + "VSCMD_ARG_app_plat", + "VSCMD_ARG_HOST_ARCH", + "VSCMD_ARG_TGT_ARCH"} + +-- init vsvers +local vsvers = +{ + ["17.0"] = "2022" +, ["16.0"] = "2019" +, ["15.0"] = "2017" +, ["14.0"] = "2015" +, ["12.0"] = "2013" +, ["11.0"] = "2012" +, ["10.0"] = "2010" +, ["9.0"] = "2008" +, ["8.0"] = "2005" +, ["7.1"] = "2003" +, ["7.0"] = "7.0" +, ["6.0"] = "6.0" +, ["5.0"] = "5.0" +, ["4.2"] = "4.2" +} + +-- init vsenvs +local vsenvs = +{ + ["17.0"] = "VS170COMNTOOLS" +, ["16.0"] = "VS160COMNTOOLS" +, ["15.0"] = "VS150COMNTOOLS" +, ["14.0"] = "VS140COMNTOOLS" +, ["12.0"] = "VS120COMNTOOLS" +, ["11.0"] = "VS110COMNTOOLS" +, ["10.0"] = "VS100COMNTOOLS" +, ["9.0"] = "VS90COMNTOOLS" +, ["8.0"] = "VS80COMNTOOLS" +, ["7.1"] = "VS71COMNTOOLS" +, ["7.0"] = "VS70COMNTOOLS" +, ["6.0"] = "VS60COMNTOOLS" +, ["5.0"] = "VS50COMNTOOLS" +, ["4.2"] = "VS42COMNTOOLS" +} + +-- get all known Visual Studio environment variables +function get_vcvars() + local realvcvars = vcvars + for _, v in pairs(vsenvs) do + table.insert(realvcvars, v) + end + return realvcvars +end -- load vcvarsall environment variables function _load_vcvarsall(vcvarsall, vsver, arch, opt) @@ -59,7 +116,7 @@ function _load_vcvarsall(vcvarsall, vsver, arch, opt) else file:print("call \"%s\" %s %s > nul", vcvarsall, arch, opt.sdkver and opt.sdkver or "") end - for idx, var in ipairs(vcvars) do + for idx, var in ipairs(get_vcvars()) do file:print("echo " .. var .. " = %%" .. var .. "%%") end file:close() @@ -148,41 +205,6 @@ function main(opt) return end - -- init vsvers - local vsvers = - { - ["17.0"] = "2022" - , ["16.0"] = "2019" - , ["15.0"] = "2017" - , ["14.0"] = "2015" - , ["12.0"] = "2013" - , ["11.0"] = "2012" - , ["10.0"] = "2010" - , ["9.0"] = "2008" - , ["8.0"] = "2005" - , ["7.1"] = "2003" - , ["7.0"] = "7.0" - , ["6.0"] = "6.0" - , ["5.0"] = "5.0" - , ["4.2"] = "4.2" - } - - -- init vsenvs - local vsenvs = - { - ["14.0"] = "VS140COMNTOOLS" - , ["12.0"] = "VS120COMNTOOLS" - , ["11.0"] = "VS110COMNTOOLS" - , ["10.0"] = "VS100COMNTOOLS" - , ["9.0"] = "VS90COMNTOOLS" - , ["8.0"] = "VS80COMNTOOLS" - , ["7.1"] = "VS71COMNTOOLS" - , ["7.0"] = "VS70COMNTOOLS" - , ["6.0"] = "VS60COMNTOOLS" - , ["5.0"] = "VS50COMNTOOLS" - , ["4.2"] = "VS42COMNTOOLS" - } - -- init options opt = opt or {} diff --git a/xmake/modules/private/xrepo/action/env.lua b/xmake/modules/private/xrepo/action/env.lua index 18b59c0e6..07709b7bd 100644 --- a/xmake/modules/private/xrepo/action/env.lua +++ b/xmake/modules/private/xrepo/action/env.lua @@ -381,7 +381,13 @@ function info(key, bnd) elseif key == "envfile" then print(os.tmpfile()) elseif key == "config" then - if not bnd and os.isfile(os.projectfile()) then + local boundenv = _get_boundenv({bind = bnd}) + local has_envfile = (boundenv and os.isfile(boundenv)) and true or false + if has_envfile or os.isfile(os.projectfile()) then + if has_envfile then + _enter_project({enteronly = true}) + table.insert(project.rcfiles(), boundenv) + end task.run("config", {target = "all"}, {disable_dump = true}) end elseif key:startswith("script.") then diff --git a/xmake/scripts/xrepo-hook.psm1 b/xmake/scripts/xrepo-hook.psm1 index 2210f10ef..2a2c24c05 100644 --- a/xmake/scripts/xrepo-hook.psm1 +++ b/xmake/scripts/xrepo-hook.psm1 @@ -33,6 +33,11 @@ function Enter-XrepoEnvironment { $activateCommand = (& $Env:XMAKE_EXE lua --quiet private.xrepo.action.env.info script.powershell | Out-String); } else { + & $Env:XMAKE_EXE lua private.xrepo.action.env.info config $bnd; + if (-not $?) { + Exit 1; + } + $xmakeColorTermBackup, $Env:XMAKE_COLORTERM = $Env:XMAKE_COLORTERM, "nocolor"; $xrepoPrompt = (& $Env:XMAKE_EXE lua --quiet private.xrepo.action.env.info prompt $bnd | Out-String); $Env:XMAKE_COLORTERM = $xmakeColorTermBackup; diff --git a/xmake/toolchains/msvc/load.lua b/xmake/toolchains/msvc/load.lua index b6b9175f0..ee61b46ab 100644 --- a/xmake/toolchains/msvc/load.lua +++ b/xmake/toolchains/msvc/load.lua @@ -56,13 +56,15 @@ function main(toolchain) toolchain:set("toolset", "ar", "link.exe") -- add vs environments - _add_vsenv(toolchain, "PATH") - _add_vsenv(toolchain, "LIB") - _add_vsenv(toolchain, "INCLUDE") - _add_vsenv(toolchain, "LIBPATH") - -- find_rc.lua need them - _add_vsenv(toolchain, "WindowsSdkDir") - _add_vsenv(toolchain, "WindowsSDKVersion") + local expect_vars = {"PATH", "LIB", "INCLUDE", "LIBPATH"} + for _, name in ipairs(expect_vars) do + _add_vsenv(toolchain, name) + end + for _, name in ipairs(find_vstudio.get_vcvars()) do + if not table.contains(expect_vars, name:upper()) then + _add_vsenv(toolchain, name) + end + end -- add some default flags toolchain:add("cl.cxxflags", "/EHsc") |
