diff options
| author | xq114 <[email protected]> | 2021-04-28 14:13:38 +0800 |
|---|---|---|
| committer | xq114 <[email protected]> | 2021-04-28 14:13:38 +0800 |
| commit | e98ca4f7d28c12fc1cfead20fd774e30eb7ff52a (patch) | |
| tree | e4a5ba95c20b18277b09e24b5391c9ccb71e642d | |
| parent | 13b88deacc54b60a383ea9c3e3862851d533a042 (diff) | |
improve environment
| -rw-r--r-- | scripts/xrepo-hook.psm1 | 8 | ||||
| -rw-r--r-- | scripts/xrepo.ps1 | 8 | ||||
| -rw-r--r-- | xmake/modules/private/xrepo/action/env.lua | 24 |
3 files changed, 19 insertions, 21 deletions
diff --git a/scripts/xrepo-hook.psm1 b/scripts/xrepo-hook.psm1 index e0a872823..ca63fb09b 100644 --- a/scripts/xrepo-hook.psm1 +++ b/scripts/xrepo-hook.psm1 @@ -3,7 +3,7 @@ <# .SYNOPSIS - Activates a xrepo environment based on your current project. + Enter a xrepo environment based on your current project. .EXAMPLE Enter-XrepoEnvironment @@ -14,8 +14,8 @@ function Enter-XrepoEnvironment { begin { $script:xrepoOldEnvs = (Get-ChildItem -Path Env:); - $xrepoPrompt = (& $Env:XMAKE_EXE lua private.xrepo env --info prompt | Out-String); - $activateCommand = (& $Env:XMAKE_EXE lua private.xrepo env --info script.powershell | Out-String); + $xrepoPrompt = (& $Env:XMAKE_EXE lua private.xrepo.action.env.info prompt | Out-String); + $activateCommand = (& $Env:XMAKE_EXE lua private.xrepo.action.env.info script.powershell | Out-String); Write-Verbose "[xrepo env script.powershell]`n$activateCommand"; Invoke-Expression -Command $activateCommand; @@ -29,7 +29,7 @@ function Enter-XrepoEnvironment { <# .SYNOPSIS - Deactivates the current xrepo environment, if any. + Exit the current xrepo environment, if any. .EXAMPLE Exit-XrepoEnvironment diff --git a/scripts/xrepo.ps1 b/scripts/xrepo.ps1 index d0d3c851e..84bb4f000 100644 --- a/scripts/xrepo.ps1 +++ b/scripts/xrepo.ps1 @@ -11,9 +11,9 @@ if ($Args.Count -eq 0) { if (($Command -eq "env") -and ($Args.Count -ge 2)) { switch ($Args[1]) { "shell" { - if (-not (Test-Path 'Env:XMAKE_ROOT')) { - $Env:XMAKE_ROOT = $BASE_DIR; - Import-Module "$Env:XMAKE_ROOT\scripts\xrepo-hook.psm1"; + if (-not (Test-Path 'Env:XMAKE_ROOTDIR')) { + $Env:XMAKE_ROOTDIR = $BASE_DIR; + Import-Module "$Env:XMAKE_ROOTDIR\scripts\xrepo-hook.psm1"; Add-XrepoEnvironmentToPrompt; } if ((Test-Path 'Env:XMAKE_PROMPT_MODIFIER') -and ($Env:XMAKE_PROMPT_MODIFIER -ne "")) { @@ -22,7 +22,7 @@ if ($Args.Count -eq 0) { Enter-XrepoEnvironment; return; } - "deactivate" { + "quit" { Exit-XrepoEnvironment; return; } diff --git a/xmake/modules/private/xrepo/action/env.lua b/xmake/modules/private/xrepo/action/env.lua index 59822420c..da573ffca 100644 --- a/xmake/modules/private/xrepo/action/env.lua +++ b/xmake/modules/private/xrepo/action/env.lua @@ -53,7 +53,6 @@ function menu_options() " - xrepo env -b \"llvm 11.x\" bash", " $ clang --version", " - xrepo env -p android -b \"zlib,luajit 2.x\" luajit xx.lua"}, - {nil, "info", "k", nil, "Get the information of the virtual environment."}, {}, {nil, "program", "v", nil, "Set the program name to be run", "e.g.", @@ -254,6 +253,16 @@ function _get_env_script(envs, shell) return ret end +-- get information of current virtual environment +function info(key) + if key == "prompt" then + print("[%s]", path.filename(os.projectdir())) + elseif key:startswith("script.") then + local shell = key:match("script%.(.+)") + print(_get_env_script(envs, shell)) + end +end + -- run shell function _run_shell(envs) local shell = os.shell() @@ -284,18 +293,7 @@ end function main() local envs = _package_getenvs() local program = option.get("program") - if option.get("info") then - if program then - if program == "prompt" then - print(format("[%s]", path.filename(os.projectdir()))) - elseif program:startswith("script.") then - local shell = program:match("script%.(.+)") - print(_get_env_script(envs, shell)) - end - else - return - end - elseif program and not option.get("show") then + if program and not option.get("show") then if envs and envs.PATH then os.setenv("PATH", envs.PATH) end |
