diff options
| author | ruki <[email protected]> | 2023-05-10 16:41:36 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-05-10 16:41:36 +0800 |
| commit | 643719b7e52a0a2bf458853d2b0381e416bdf433 (patch) | |
| tree | db1886141e5727d2d2990421c964850878ceba0c | |
| parent | 5b258b7996411c674d255ee15194d0c78afee9de (diff) | |
| parent | c8169591343bf62a970b2edffc90e26cfdfb2d31 (diff) | |
Merge pull request #3724 from xq114/dev
use pushd and popd to tackle venv
| -rwxr-xr-x | scripts/xrepo.bat | 27 | ||||
| -rw-r--r-- | xmake/scripts/virtualenvs/register-virtualenvs.sh | 17 | ||||
| -rw-r--r-- | xmake/scripts/xrepo-hook.psm1 | 10 |
3 files changed, 22 insertions, 32 deletions
diff --git a/scripts/xrepo.bat b/scripts/xrepo.bat index 7a5926cdb..8cdd7a5b6 100755 --- a/scripts/xrepo.bat +++ b/scripts/xrepo.bat @@ -1,4 +1,5 @@ -@set "XMAKE_EXE=xmake" +@set "XMAKE_ROOTDIR=%~dp0" +@set "XMAKE_EXE=%XMAKE_ROOTDIR%xmake.exe" @if [%1]==[env] ( if [%2]==[quit] ( @@ -35,18 +36,14 @@ exit /B 1 ) else ( setlocal EnableDelayedExpansion - @%XMAKE_EXE% lua --quiet private.xrepo.action.env | findstr . && ( - echo error: corrupt xmake.lua detected in the current directory^^! - exit /B 1 - ) - @%XMAKE_EXE% lua --quiet private.xrepo.action.env - if !errorlevel! neq 0 ( - exit /B !errorlevel! - ) %XMAKE_EXE% lua private.xrepo.action.env.info config if !errorlevel! neq 0 ( exit /B !errorlevel! ) + @%XMAKE_EXE% lua --quiet private.xrepo.action.env | findstr . && ( + echo error: corrupt xmake.lua detected in the current directory^^! + exit /B 1 + ) @%XMAKE_EXE% lua --quiet private.xrepo.action.env.info prompt 1>nul if !errorlevel! neq 0 ( echo error: xmake.lua not found^^! @@ -88,21 +85,16 @@ echo Please rerun `xrepo env %2 %3 shell` to enter the environment. exit /B 1 ) else ( + pushd %XMAKE_ROOTDIR% setlocal EnableDelayedExpansion - @%XMAKE_EXE% lua --quiet private.xrepo.action.env | findstr . && ( - echo error: corrupt xmake.lua detected in the current directory^^! - exit /B 1 - ) - @%XMAKE_EXE% lua --quiet private.xrepo.action.env - if !errorlevel! neq 0 ( - exit /B !errorlevel! - ) %XMAKE_EXE% lua private.xrepo.action.env.info config %3 if !errorlevel! neq 0 ( + popd exit /B !errorlevel! ) @%XMAKE_EXE% lua --quiet private.xrepo.action.env.info prompt %3 1>nul if !errorlevel! neq 0 ( + popd echo error: environment not found^^! exit /B !errorlevel! ) @@ -120,6 +112,7 @@ @"%XMAKE_EXE%" lua --quiet private.xrepo.action.env.info script.cmd %3 1>"%%i.bat" call "%%i.bat" ) + popd goto :ENDXREPO ) ) diff --git a/xmake/scripts/virtualenvs/register-virtualenvs.sh b/xmake/scripts/virtualenvs/register-virtualenvs.sh index 15ed63bcd..ac82e9b94 100644 --- a/xmake/scripts/virtualenvs/register-virtualenvs.sh +++ b/xmake/scripts/virtualenvs/register-virtualenvs.sh @@ -21,6 +21,7 @@ if test "${XMAKE_ROOTDIR}"; then export XMAKE_EXE=${XMAKE_ROOTDIR}/xmake else + local -i XMAKE_ROOTDIR=~/.local/bin export XMAKE_EXE=xmake fi @@ -35,12 +36,12 @@ function xrepo { unset XMAKE_PROMPT_BACKUP unset XMAKE_ENV_BACKUP fi + "$XMAKE_EXE" lua private.xrepo.action.env.info config || return 1 local currentTest="$("$XMAKE_EXE" lua --quiet private.xrepo.action.env)" || return 1 if [ ! -z "$currentTest" ]; then echo "error: corrupt xmake.lua detected in the current directory!" return 1 fi - "$XMAKE_EXE" lua private.xrepo.action.env.info config || return 1 local prompt="$("$XMAKE_EXE" lua --quiet private.xrepo.action.env.info prompt)" || return 1 if [ -z "${prompt+x}" ]; then return 1 @@ -69,22 +70,20 @@ function xrepo { unset XMAKE_PROMPT_BACKUP unset XMAKE_ENV_BACKUP fi - local currentTest="$("$XMAKE_EXE" lua --quiet private.xrepo.action.env)" || return 1 - if [ ! -z "$currentTest" ]; then - echo "error: corrupt xmake.lua detected in the current directory!" - return 1 - 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 + pushd ${XMAKE_ROOTDIR} 1>/dev/null + "$XMAKE_EXE" lua private.xrepo.action.env.info config $bnd || (popd 1>/dev/null && return 1) + local prompt="$("$XMAKE_EXE" lua --quiet private.xrepo.action.env.info prompt $bnd)" || (popd 1>/dev/null && return 1) if [ -z "${prompt+x}" ]; then + popd 1>/dev/null echo "error: invalid environment!" return 1 fi - local activateCommand="$("$XMAKE_EXE" lua --quiet private.xrepo.action.env.info script.bash $bnd)" || return 1 + local activateCommand="$("$XMAKE_EXE" lua --quiet private.xrepo.action.env.info script.bash $bnd)" || (popd 1>/dev/null && return 1) export XMAKE_ENV_BACKUP="$("$XMAKE_EXE" lua private.xrepo.action.env.info envfile $bnd)" export XMAKE_PROMPT_BACKUP="${PS1}" "$XMAKE_EXE" lua --quiet private.xrepo.action.env.info backup.bash $bnd 1>"$XMAKE_ENV_BACKUP" eval "$activateCommand" + popd 1>/dev/null PS1="${prompt} $PS1" else "$XMAKE_EXE" lua private.xrepo "$@" diff --git a/xmake/scripts/xrepo-hook.psm1 b/xmake/scripts/xrepo-hook.psm1 index b05557efa..c0a6aad94 100644 --- a/xmake/scripts/xrepo-hook.psm1 +++ b/xmake/scripts/xrepo-hook.psm1 @@ -15,12 +15,6 @@ function Enter-XrepoEnvironment { ); begin { - $currentTest = (& $Env:XMAKE_EXE lua --quiet private.xrepo.action.env | Out-String); - if (-not $? -or $currentTest) { - Write-Host "error: corrupt xmake.lua detected in the current directory!"; - Exit 1; - } - $script:xrepoOldEnvs = (Get-ChildItem -Path Env:); if (-not $bnd) { @@ -39,8 +33,10 @@ function Enter-XrepoEnvironment { $activateCommand = (& $Env:XMAKE_EXE lua --quiet private.xrepo.action.env.info script.powershell | Out-String); } else { + Push-Location $Env:XMAKE_ROOTDIR; & $Env:XMAKE_EXE lua private.xrepo.action.env.info config $bnd; if (-not $?) { + Pop-Location; Exit 1; } @@ -48,6 +44,7 @@ function Enter-XrepoEnvironment { $xrepoPrompt = (& $Env:XMAKE_EXE lua --quiet private.xrepo.action.env.info prompt $bnd | Out-String); $Env:XMAKE_COLORTERM = $xmakeColorTermBackup; if (-not $xrepoPrompt.StartsWith("[")) { + Pop-Location; Write-Host "error: invalid environment!"; Exit 1; } @@ -58,6 +55,7 @@ function Enter-XrepoEnvironment { Write-Verbose "[xrepo env script.powershell]`n$activateCommand"; Invoke-Expression -Command $activateCommand; + if ($bnd) { Pop-Location; } $Env:XMAKE_PROMPT_MODIFIER = $xrepoPrompt.Trim() + " "; } process {} |
