From f21aa19d54be924764fc92f2dfda52af6198899c Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 8 May 2021 21:32:25 +0800 Subject: fix psm1 script path --- scripts/installer.nsi | 3 -- scripts/xrepo-hook.psm1 | 105 ------------------------------------------ xmake/actions/update/main.lua | 2 +- xmake/scripts/xrepo-hook.psm1 | 105 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+), 109 deletions(-) delete mode 100644 scripts/xrepo-hook.psm1 create mode 100644 xmake/scripts/xrepo-hook.psm1 diff --git a/scripts/installer.nsi b/scripts/installer.nsi index bd47e463b..a01b6feea 100644 --- a/scripts/installer.nsi +++ b/scripts/installer.nsi @@ -238,10 +238,7 @@ Section "XMake (required)" InstallExeutable File "..\core\build\xmake.exe" File "..\scripts\xrepo.bat" File "..\scripts\xrepo.ps1" - File "..\scripts\xrepo-hook.psm1" File /r /x ".DS_Store" "..\winenv" - CreateDirectory "$InstDir\scripts" - Rename "$InstDir\xrepo-hook.psm1" "$InstDir\scripts\xrepo-hook.psm1" WriteUninstaller "uninstall.exe" diff --git a/scripts/xrepo-hook.psm1 b/scripts/xrepo-hook.psm1 deleted file mode 100644 index 902ef3b16..000000000 --- a/scripts/xrepo-hook.psm1 +++ /dev/null @@ -1,105 +0,0 @@ - -## ENVIRONMENT MANAGEMENT ###################################################### - -<# - .SYNOPSIS - Enter a xrepo environment based on your current project. - - .EXAMPLE - Enter-XrepoEnvironment -#> -function Enter-XrepoEnvironment { - [CmdletBinding()] - param(); - - begin { - $script:xrepoOldEnvs = (Get-ChildItem -Path Env:); - - & $Env:XMAKE_EXE lua private.xrepo.action.env.info config; - if (-not $?) { - Exit 1; - } - - $xmakeColorTermBackup, $Env:XMAKE_COLORTERM = $Env:XMAKE_COLORTERM, "nocolor"; - $xrepoPrompt = (& $Env:XMAKE_EXE lua private.xrepo.action.env.info prompt | Out-String); - $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"; - Invoke-Expression -Command $activateCommand; - - $Env:XMAKE_PROMPT_MODIFIER = $xrepoPrompt.Trim() + " "; - } - process {} - end {} -} - - -<# - .SYNOPSIS - Exit the current xrepo environment, if any. - - .EXAMPLE - Exit-XrepoEnvironment -#> -function Exit-XrepoEnvironment { - [CmdletBinding()] - param(); - - begin { - ForEach ($p in (Get-ChildItem Env:)) { - [Environment]::SetEnvironmentVariable($p.Name, $Null); - } - ForEach ($p in $script:xrepoOldEnvs) { - [Environment]::SetEnvironmentVariable($p.Name, $p.Value); - } - $Env:XMAKE_PROMPT_MODIFIER = ""; - } - process {} - end {} -} - - -if (Test-Path Function:\prompt) { - Rename-Item Function:\prompt XrepoPromptBackup -} else { - function XrepoPromptBackup() { - # Restore a basic prompt if the definition is missing. - "PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "; - } -} - - -<# - .SYNOPSIS - Modifies the current prompt to show the current xmake project. - - .EXAMPLE - Add-XrepoEnvironmentToPrompt - - Causes the current session's prompt to display the current xmake project name. -#> -function Add-XrepoEnvironmentToPrompt() { - function global:prompt() { - if ($Env:XMAKE_PROMPT_MODIFIER) { - $Env:XMAKE_PROMPT_MODIFIER | Write-Host -NoNewline - } - XrepoPromptBackup; - } -} - - -## EXPORTS ################################################################### - -Export-ModuleMember ` - -Alias * ` - -Function ` - Add-XrepoEnvironmentToPrompt, ` - Enter-XrepoEnvironment, ` - Exit-XrepoEnvironment, ` - prompt diff --git a/xmake/actions/update/main.lua b/xmake/actions/update/main.lua index 9ed4f412a..7264d472c 100644 --- a/xmake/actions/update/main.lua +++ b/xmake/actions/update/main.lua @@ -223,7 +223,7 @@ function _install_script(sourcedir) local script_original = path.join(os.programdir(), "scripts", "update-script.bat") local script = os.tmpfile() .. ".bat" os.cp(script_original, script) - local params = { "/c", script, os.programdir(), source } + local params = { "/c", script, os.programdir(), source } os.tryrm(script_original .. ".bak") local access = os.trymv(script_original, script_original .. ".bak") _run_win_v("cmd", params, not access) diff --git a/xmake/scripts/xrepo-hook.psm1 b/xmake/scripts/xrepo-hook.psm1 new file mode 100644 index 000000000..902ef3b16 --- /dev/null +++ b/xmake/scripts/xrepo-hook.psm1 @@ -0,0 +1,105 @@ + +## ENVIRONMENT MANAGEMENT ###################################################### + +<# + .SYNOPSIS + Enter a xrepo environment based on your current project. + + .EXAMPLE + Enter-XrepoEnvironment +#> +function Enter-XrepoEnvironment { + [CmdletBinding()] + param(); + + begin { + $script:xrepoOldEnvs = (Get-ChildItem -Path Env:); + + & $Env:XMAKE_EXE lua private.xrepo.action.env.info config; + if (-not $?) { + Exit 1; + } + + $xmakeColorTermBackup, $Env:XMAKE_COLORTERM = $Env:XMAKE_COLORTERM, "nocolor"; + $xrepoPrompt = (& $Env:XMAKE_EXE lua private.xrepo.action.env.info prompt | Out-String); + $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"; + Invoke-Expression -Command $activateCommand; + + $Env:XMAKE_PROMPT_MODIFIER = $xrepoPrompt.Trim() + " "; + } + process {} + end {} +} + + +<# + .SYNOPSIS + Exit the current xrepo environment, if any. + + .EXAMPLE + Exit-XrepoEnvironment +#> +function Exit-XrepoEnvironment { + [CmdletBinding()] + param(); + + begin { + ForEach ($p in (Get-ChildItem Env:)) { + [Environment]::SetEnvironmentVariable($p.Name, $Null); + } + ForEach ($p in $script:xrepoOldEnvs) { + [Environment]::SetEnvironmentVariable($p.Name, $p.Value); + } + $Env:XMAKE_PROMPT_MODIFIER = ""; + } + process {} + end {} +} + + +if (Test-Path Function:\prompt) { + Rename-Item Function:\prompt XrepoPromptBackup +} else { + function XrepoPromptBackup() { + # Restore a basic prompt if the definition is missing. + "PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "; + } +} + + +<# + .SYNOPSIS + Modifies the current prompt to show the current xmake project. + + .EXAMPLE + Add-XrepoEnvironmentToPrompt + + Causes the current session's prompt to display the current xmake project name. +#> +function Add-XrepoEnvironmentToPrompt() { + function global:prompt() { + if ($Env:XMAKE_PROMPT_MODIFIER) { + $Env:XMAKE_PROMPT_MODIFIER | Write-Host -NoNewline + } + XrepoPromptBackup; + } +} + + +## EXPORTS ################################################################### + +Export-ModuleMember ` + -Alias * ` + -Function ` + Add-XrepoEnvironmentToPrompt, ` + Enter-XrepoEnvironment, ` + Exit-XrepoEnvironment, ` + prompt -- cgit v1.3.1