summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxq114 <[email protected]>2021-04-28 21:48:55 +0800
committerxq114 <[email protected]>2021-04-28 21:48:55 +0800
commit5af95803a04619777fbe69e1193ed0978cb01550 (patch)
treec01b7b537c7802de0ad8b03da23bd8bc136c2be1
parent9597a24c34cd2e47aab93c1a8a21914cff0c18a8 (diff)
improve environment management on cmd
-rwxr-xr-xscripts/xrepo.bat41
-rw-r--r--xmake/modules/private/xrepo/action/env.lua21
2 files changed, 54 insertions, 8 deletions
diff --git a/scripts/xrepo.bat b/scripts/xrepo.bat
index ff95b722a..a58f5ac02 100755
--- a/scripts/xrepo.bat
+++ b/scripts/xrepo.bat
@@ -1,2 +1,39 @@
-@echo off
-xmake lua private.xrepo %*
+@REM @echo off
+
+@set "XMAKE_EXE=%~dp0xmake.exe"
+@if [%1]==[env] (
+ if [%2]==[quit] (
+ if defined XMAKE_PROMPT_BACKUP (
+ call %XMAKE_ENV_BACKUP%
+ if %errorlevel% neq 0 exit /B %errorlevel%
+ set PROMPT=%XMAKE_PROMPT_BACKUP%
+ set XMAKE_ENV_BACKUP=
+ set XMAKE_PROMPT_BACKUP=
+ )
+ goto :ENDXREPO
+ )
+ if [%2]==[shell] (
+ if defined XMAKE_PROMPT_BACKUP (
+ call %XMAKE_ENV_BACKUP%
+ if %errorlevel% neq 0 exit /B %errorlevel%
+ set PROMPT=%XMAKE_PROMPT_BACKUP%
+ for /f %%i in ('%XMAKE_EXE% lua private.xrepo.action.env.info prompt') do @set "PROMPT=%%i %XMAKE_PROMPT_BACKUP%"
+ ) else (
+ set XMAKE_PROMPT_BACKUP=%PROMPT%
+ for /f %%i in ('%XMAKE_EXE% lua private.xrepo.action.env.info prompt') do @set "PROMPT=%%i %PROMPT%"
+ )
+ for /f %%i in ('%XMAKE_EXE% lua private.xrepo.action.env.info envfile') do @(
+ set "XMAKE_ENV_BACKUP=%%i.bat"
+ @"%XMAKE_EXE%" lua private.xrepo.action.env.info backup.cmd 1>"%%i.bat"
+ )
+ for /f %%i in ('%XMAKE_EXE% lua private.xrepo.action.env.info envfile') do @(
+ @"%XMAKE_EXE%" lua private.xrepo.action.env.info script.cmd 1>"%%i.bat"
+ call "%%i.bat"
+ )
+ goto :ENDXREPO
+ )
+)
+
+@call %XMAKE_EXE% lua private.xrepo %*
+
+:ENDXREPO
diff --git a/xmake/modules/private/xrepo/action/env.lua b/xmake/modules/private/xrepo/action/env.lua
index da573ffca..7bd8dbd96 100644
--- a/xmake/modules/private/xrepo/action/env.lua
+++ b/xmake/modules/private/xrepo/action/env.lua
@@ -238,17 +238,21 @@ function _get_env_script(envs, shell)
local prefix = ""
local connector = "="
local suffix = ""
+ local default = ""
if shell == "powershell" or shell == "pwsh" then
prefix = "[Environment]::SetEnvironmentVariable('"
connector = "','"
suffix = "')"
+ default = "$Null"
+ elseif shell == "cmd" then
+ prefix = "@set \""
+ suffix = "\""
end
local ret = ""
- local modified = hashset.of("PATH", "LD_LIBRARY_PATH", "DYLD_LIBRARY_PATH", "ACLOCAL_PATH", "PKG_CONFIG_PATH", "CMAKE_PREFIX_PATH")
- for name, value in pairs(envs) do
- if modified:has(name) then
- ret = ret .. prefix .. name .. connector .. value .. suffix .. "\n"
- end
+ local modified = {"PATH", "LD_LIBRARY_PATH", "DYLD_LIBRARY_PATH", "ACLOCAL_PATH", "PKG_CONFIG_PATH", "CMAKE_PREFIX_PATH"}
+ for _, name in ipairs(modified) do
+ local value = envs[name] or default
+ ret = ret .. prefix .. name .. connector .. value .. suffix .. "\n"
end
return ret
end
@@ -257,9 +261,14 @@ end
function info(key)
if key == "prompt" then
print("[%s]", path.filename(os.projectdir()))
+ elseif key == "envfile" then
+ print("%s", os.tmpfile())
elseif key:startswith("script.") then
local shell = key:match("script%.(.+)")
- print(_get_env_script(envs, shell))
+ print(_get_env_script(_package_getenvs(), shell))
+ elseif key:startswith("backup.") then
+ local shell = key:match("backup%.(.+)")
+ print(_get_env_script(os.getenvs(), shell))
end
end