diff options
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/xrepo-hook.psm1 | 8 | ||||
| -rwxr-xr-x | scripts/xrepo.bat | 58 |
2 files changed, 64 insertions, 2 deletions
diff --git a/scripts/xrepo-hook.psm1 b/scripts/xrepo-hook.psm1 index ca63fb09b..22a726b97 100644 --- a/scripts/xrepo-hook.psm1 +++ b/scripts/xrepo-hook.psm1 @@ -15,6 +15,10 @@ function Enter-XrepoEnvironment { begin { $script:xrepoOldEnvs = (Get-ChildItem -Path Env:); $xrepoPrompt = (& $Env:XMAKE_EXE lua private.xrepo.action.env.info prompt | Out-String); + if (-not $?) { + Write-Host $xrepoPrompt + Exit 1 + } $activateCommand = (& $Env:XMAKE_EXE lua private.xrepo.action.env.info script.powershell | Out-String); Write-Verbose "[xrepo env script.powershell]`n$activateCommand"; @@ -39,7 +43,9 @@ function Exit-XrepoEnvironment { param(); begin { - # Write-Host $script:xrepoOldEnvs; + ForEach ($p in (Get-ChildItem Env:)) { + [Environment]::SetEnvironmentVariable($p.Name, $Null); + } ForEach ($p in $script:xrepoOldEnvs) { [Environment]::SetEnvironmentVariable($p.Name, $p.Value); } diff --git a/scripts/xrepo.bat b/scripts/xrepo.bat index ff95b722a..c59fd53d9 100755 --- a/scripts/xrepo.bat +++ b/scripts/xrepo.bat @@ -1,2 +1,58 @@ @echo off -xmake lua private.xrepo %* + +@set "XMAKE_EXE=%~dp0xmake.exe" +@if [%1]==[env] ( + if [%2]==[quit] ( + if defined XMAKE_PROMPT_BACKUP ( + call %XMAKE_ENV_BACKUP% + setlocal EnableDelayedExpansion + if !errorlevel! neq 0 exit /B !errorlevel! + endlocal + 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% + setlocal EnableDelayedExpansion + if !errorlevel! neq 0 exit /B !errorlevel! + @%XMAKE_EXE% lua private.xrepo.action.env.info prompt 1>nul + if !errorlevel! neq 0 ( + echo error: xmake.lua not found^^! + exit /B !errorlevel! + ) + endlocal + set PROMPT=%XMAKE_PROMPT_BACKUP% + set XMAKE_ENV_BACKUP= + set XMAKE_PROMPT_BACKUP= + echo Please rerun `xrepo env shell` to enter the environment. + exit /B 1 + ) else ( + setlocal EnableDelayedExpansion + @%XMAKE_EXE% lua private.xrepo.action.env.info prompt 1>nul + if !errorlevel! neq 0 ( + echo error: xmake.lua not found^^! + exit /B !errorlevel! + ) + endlocal + for /f %%i in ('@%XMAKE_EXE% lua private.xrepo.action.env.info prompt') do @set "PROMPT=%%i %PROMPT%" + set XMAKE_PROMPT_BACKUP=%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 |
