From 947cfffa942ec1160a68c614c296830991fc0710 Mon Sep 17 00:00:00 2001 From: xq114 <1140735506@qq.com> Date: Fri, 30 Apr 2021 22:21:10 +0800 Subject: improve envrionment management without xmake cache --- scripts/xrepo-hook.psm1 | 12 +++++++++--- scripts/xrepo.bat | 13 ++++++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/scripts/xrepo-hook.psm1 b/scripts/xrepo-hook.psm1 index 22a726b97..efd3f909e 100644 --- a/scripts/xrepo-hook.psm1 +++ b/scripts/xrepo-hook.psm1 @@ -14,11 +14,17 @@ function Enter-XrepoEnvironment { begin { $script:xrepoOldEnvs = (Get-ChildItem -Path Env:); + + & $Env:XMAKE_EXE config + + $xmakeColorTermBackup, $Env:XMAKE_COLORTERM = $Env:XMAKE_COLORTERM, "nocolor"; $xrepoPrompt = (& $Env:XMAKE_EXE lua private.xrepo.action.env.info prompt | Out-String); - if (-not $?) { - Write-Host $xrepoPrompt - Exit 1 + $Env:XMAKE_COLORTERM = $xmakeColorTermBackup; + if (-not $xrepoPrompt.StartsWith("[")) { + 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"; diff --git a/scripts/xrepo.bat b/scripts/xrepo.bat index c1dde03fe..cbf7a080e 100755 --- a/scripts/xrepo.bat +++ b/scripts/xrepo.bat @@ -1,6 +1,5 @@ -@echo off - @set "XMAKE_EXE=xmake" + @if [%1]==[env] ( if [%2]==[quit] ( if defined XMAKE_PROMPT_BACKUP ( @@ -19,6 +18,7 @@ call %XMAKE_ENV_BACKUP% setlocal EnableDelayedExpansion if !errorlevel! neq 0 exit /B !errorlevel! + %XMAKE_EXE% config @%XMAKE_EXE% lua private.xrepo.action.env.info prompt 1>nul if !errorlevel! neq 0 ( echo error: xmake.lua not found^^! @@ -32,17 +32,20 @@ exit /B 1 ) else ( setlocal EnableDelayedExpansion + %XMAKE_EXE% config @%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 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" + @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 @( -- cgit v1.3.1 From 108410d9151b2ba67b011e858576ab7efdbd2176 Mon Sep 17 00:00:00 2001 From: xq114 <1140735506@qq.com> Date: Fri, 30 Apr 2021 23:05:05 +0800 Subject: run config only in project directories --- scripts/xrepo-hook.psm1 | 2 +- scripts/xrepo.bat | 4 ++-- xmake/modules/private/xrepo/action/env.lua | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/xrepo-hook.psm1 b/scripts/xrepo-hook.psm1 index efd3f909e..5874203fd 100644 --- a/scripts/xrepo-hook.psm1 +++ b/scripts/xrepo-hook.psm1 @@ -15,7 +15,7 @@ function Enter-XrepoEnvironment { begin { $script:xrepoOldEnvs = (Get-ChildItem -Path Env:); - & $Env:XMAKE_EXE config + & $Env:XMAKE_EXE lua private.xrepo.action.env.info config; $xmakeColorTermBackup, $Env:XMAKE_COLORTERM = $Env:XMAKE_COLORTERM, "nocolor"; $xrepoPrompt = (& $Env:XMAKE_EXE lua private.xrepo.action.env.info prompt | Out-String); diff --git a/scripts/xrepo.bat b/scripts/xrepo.bat index cbf7a080e..1a4a230ca 100755 --- a/scripts/xrepo.bat +++ b/scripts/xrepo.bat @@ -18,7 +18,7 @@ call %XMAKE_ENV_BACKUP% setlocal EnableDelayedExpansion if !errorlevel! neq 0 exit /B !errorlevel! - %XMAKE_EXE% config + %XMAKE_EXE% lua private.xrepo.action.env.info config @%XMAKE_EXE% lua private.xrepo.action.env.info prompt 1>nul if !errorlevel! neq 0 ( echo error: xmake.lua not found^^! @@ -32,7 +32,7 @@ exit /B 1 ) else ( setlocal EnableDelayedExpansion - %XMAKE_EXE% config + %XMAKE_EXE% lua private.xrepo.action.env.info config @%XMAKE_EXE% lua private.xrepo.action.env.info prompt 1>nul if !errorlevel! neq 0 ( echo error: xmake.lua not found^^! diff --git a/xmake/modules/private/xrepo/action/env.lua b/xmake/modules/private/xrepo/action/env.lua index 8703a726c..fbce2a566 100644 --- a/xmake/modules/private/xrepo/action/env.lua +++ b/xmake/modules/private/xrepo/action/env.lua @@ -268,6 +268,10 @@ function info(key) print("[%s]", path.filename(os.projectdir())) elseif key == "envfile" then print(os.tmpfile()) + elseif key == "config" then + if os.isfile(os.projectfile()) then + task.run("config", {target = "all"}, {disable_dump = true}) + end elseif key:startswith("script.") then local shell = key:match("script%.(.+)") print(_get_env_script(_package_getenvs(), shell, false)) -- cgit v1.3.1