summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxq114 <[email protected]>2023-03-23 16:03:11 +0800
committerxq114 <[email protected]>2023-03-23 16:03:11 +0800
commitdf31f7516538cb4049110c89f290c7a398a58f3b (patch)
treeea2e9879d109e22bdfab602dfa367d309f464b71
parent19c31069f6336cb969f9fefc059890f3cc64d2d8 (diff)
detect corrupt xmake.lua for virtual environment
-rwxr-xr-xscripts/xrepo.bat18
-rw-r--r--xmake/scripts/virtualenvs/register-virtualenvs.sh11
-rw-r--r--xmake/scripts/xrepo-hook.psm16
3 files changed, 34 insertions, 1 deletions
diff --git a/scripts/xrepo.bat b/scripts/xrepo.bat
index 0416d4a10..7a5926cdb 100755
--- a/scripts/xrepo.bat
+++ b/scripts/xrepo.bat
@@ -35,6 +35,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!
@@ -77,10 +85,18 @@
set PROMPT=%XMAKE_PROMPT_BACKUP%
set XMAKE_ENV_BACKUP=
set XMAKE_PROMPT_BACKUP=
- echo Please rerun `xrepo env shell` to enter the environment.
+ echo Please rerun `xrepo env %2 %3 shell` to enter the environment.
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 %3
if !errorlevel! neq 0 (
exit /B !errorlevel!
diff --git a/xmake/scripts/virtualenvs/register-virtualenvs.sh b/xmake/scripts/virtualenvs/register-virtualenvs.sh
index e853a54ba..15ed63bcd 100644
--- a/xmake/scripts/virtualenvs/register-virtualenvs.sh
+++ b/xmake/scripts/virtualenvs/register-virtualenvs.sh
@@ -35,6 +35,11 @@ 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 || return 1
local prompt="$("$XMAKE_EXE" lua --quiet private.xrepo.action.env.info prompt)" || return 1
if [ -z "${prompt+x}" ]; then
@@ -64,9 +69,15 @@ 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
if [ -z "${prompt+x}" ]; then
+ echo "error: invalid environment!"
return 1
fi
local activateCommand="$("$XMAKE_EXE" lua --quiet private.xrepo.action.env.info script.bash $bnd)" || return 1
diff --git a/xmake/scripts/xrepo-hook.psm1 b/xmake/scripts/xrepo-hook.psm1
index 8e09c85b9..b05557efa 100644
--- a/xmake/scripts/xrepo-hook.psm1
+++ b/xmake/scripts/xrepo-hook.psm1
@@ -15,6 +15,12 @@ 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) {