From 78fbcdf0ebd350643da2ac8f42589adae9b2a4e0 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 6 Jun 2019 17:32:24 +0800 Subject: not for ci --- scripts/get.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/get.ps1 b/scripts/get.ps1 index 4b186c23f..5e8463bc2 100644 --- a/scripts/get.ps1 +++ b/scripts/get.ps1 @@ -169,6 +169,7 @@ param ( Remove-Item "$repodir" -Recurse -Force -ErrorAction SilentlyContinue } - registerTabCompletion - + if (-not $env:CI) { + registerTabCompletion + } } -- cgit v1.3.1 From 7cac3d417c9eb0218669bc3c3b5ef390ff492c64 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 6 Jun 2019 18:06:31 +0800 Subject: skip self build for ci --- scripts/get.ps1 | 225 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 118 insertions(+), 107 deletions(-) (limited to 'scripts') diff --git a/scripts/get.ps1 b/scripts/get.ps1 index 5e8463bc2..968b2e7d4 100644 --- a/scripts/get.ps1 +++ b/scripts/get.ps1 @@ -7,126 +7,71 @@ param ( [string]$version = "v2.2.6" ) -& { - - function myExit($code) { - if ($code -is [int] -and $code -ne 0) { - throw $Error[0] - } else { - break - } +function myExit($code) { + if ($code -is [int] -and $code -ne 0) { + throw $Error[0] + } else { + break } +} - function writeErrorTip($msg) { - Write-Host $msg -BackgroundColor Red -ForegroundColor White - } +function writeErrorTip($msg) { + Write-Host $msg -BackgroundColor Red -ForegroundColor White +} - function writeLogoLine($msg) { - Write-Host $msg -BackgroundColor White -ForegroundColor DarkBlue - } +function writeLogoLine($msg) { + Write-Host $msg -BackgroundColor White -ForegroundColor DarkBlue +} - function registerTabCompletion { - - function writeDataToFile($file) { - $encoding = [text.encoding]::UTF8 - if (Test-Path $file -PathType Leaf) { - #Create a stream reader to get the file's encoding and contents. - $sr = New-Object System.IO.StreamReader($file, $true) - [char[]] $buffer = new-object char[] 3 - $sr.Read($buffer, 0, 3) | Out-Null - $encoding = $sr.CurrentEncoding - $sr.Close() | Out-Null - - if ($(Get-Content $file) -imatch "Register-ArgumentCompleter -Native -CommandName xmake -ScriptBlock") { - Write-Host "Seems the tab completion of xmake has installed here..." - return - } - } +writeLogoLine ' _ ' +writeLogoLine ' __ ___ __ __ __ _| | ______ ' +writeLogoLine ' \ \/ / | \/ |/ _ | |/ / __ \ ' +writeLogoLine ' > < | \__/ | /_| | < ___/ ' +writeLogoLine ' /_/\_\_|_| |_|\__ \|_|\_\____| getter ' +writeLogoLine ' ' +writeLogoLine ' ' - try { - [IO.File]::AppendAllText($file, "`n", $encoding) - } catch { - writeErrorTip "Failed to append to profile!" - writeErrorTip "Please try again as administrator" - return - } - try { - $content = (Invoke-Webrequest 'https://raw.githubusercontent.com/xmake-io/xmake/master/scripts/register-completions.ps1' -UseBasicParsing).Content - } catch { - writeErrorTip 'Download failed!' - writeErrorTip 'Check your network or... the news of S3 break' - return - } - [IO.File]::AppendAllText($file, $content, $encoding) - [IO.File]::AppendAllText($file, "`n", $encoding) - } - $message = 'Tab completion service' - $question = 'Would you like to install tab completion service of xmake to your profile?' - - $choices = @( - (New-Object Management.Automation.Host.ChoiceDescription -ArgumentList @( - 'For &all users', - "Install for all users, writes to $($PROFILE.AllUsersAllHosts), admin privilege is needed.")), - (New-Object Management.Automation.Host.ChoiceDescription -ArgumentList @( - 'Just for &me', - "Install for current user, writes to $($PROFILE.CurrentUserAllHosts).")), - (New-Object Management.Automation.Host.ChoiceDescription -ArgumentList @( - 'Just for this &host', - "Install for current user current host, writes to $($PROFILE.CurrentUserCurrentHost).")), - (New-Object Management.Automation.Host.ChoiceDescription -ArgumentList @( - '&No', - "Do not install xmake's tab completion service.")) - ) - switch ($Host.UI.PromptForChoice($message, $question, $choices, 1)) { - 0 { writeDataToFile($PROFILE.AllUsersAllHosts) } - 1 { writeDataToFile($PROFILE.CurrentUserAllHosts) } - 2 { writeDataToFile($PROFILE.CurrentUserCurrentHost) } - } - } +if ($PSVersionTable.PSVersion.Major -lt 5) { + writeErrorTip 'Sorry but PowerShell v5+ is required' + throw 'PowerShell''s version too low' +} +$temppath = ($null -ne $env:TMP, $env:TEMP, '.')[0] +[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" - writeLogoLine ' _ ' - writeLogoLine ' __ ___ __ __ __ _| | ______ ' - writeLogoLine ' \ \/ / | \/ |/ _ | |/ / __ \ ' - writeLogoLine ' > < | \__/ | /_| | < ___/ ' - writeLogoLine ' /_/\_\_|_| |_|\__ \|_|\_\____| getter ' - writeLogoLine ' ' - writeLogoLine ' ' - - if ($PSVersionTable.PSVersion.Major -lt 5) { - writeErrorTip 'Sorry but PowerShell v5+ is required' - throw 'PowerShell''s version too low' - } - $temppath = ($env:TMP, $env:TEMP, '.' -ne $null)[0] - $outfile = $temppath + "\$pid-xmake-installer.exe" +function checkTempAccess { + $outfile = Join-Path $temppath "$pid.tmp" try { - Write-Output "$pid" | Out-File -FilePath "$outfile" - Remove-Item "$outfile" + Write-Output $pid | Out-File -FilePath $outfile + Remove-Item $outfile } catch { writeErrorTip 'Cannot write to temp path' writeErrorTip 'Please set environment var "TMP" to another path' myExit 1 } +} + +function xmakeInstall { + $outfile = Join-Path $temppath "$pid-xmake-installer.exe" Write-Host "Start downloading https://github.com/xmake-io/xmake/releases/download/$version/xmake-$branch.exe .." try { - [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" - Invoke-Webrequest "https://github.com/xmake-io/xmake/releases/download/$version/xmake-$branch.exe" -OutFile "$outfile" + Invoke-Webrequest "https://github.com/xmake-io/xmake/releases/download/$version/xmake-$branch.exe" -OutFile $outfile } catch { writeErrorTip 'Download failed!' writeErrorTip 'Check your network or... the news of S3 break' myExit 1 } Write-Host 'Start installation... Hope your antivirus doesn''t trouble' - $installdir = $HOME + '\xmake' + $installdir = Join-Path $env:HOME 'xmake' Write-Host "Install to $installdir" try { - Start-Process -FilePath "$outfile" -ArgumentList "/S /D=$installdir" -Wait + Start-Process -FilePath $outfile -ArgumentList "/S /D=$installdir" -Wait } catch { - Remove-Item "$outfile" writeErrorTip 'Install failed!' writeErrorTip 'Close your antivirus then try again' myExit 1 + } finally { + Remove-Item $outfile -ErrorAction SilentlyContinue } - Remove-Item "$outfile" Write-Host 'Adding to PATH... almost done' $env:Path += ";$installdir" [Environment]::SetEnvironmentVariable("Path", [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User) + ";$installdir", [System.EnvironmentVariableTarget]::User) # this step is optional because installer writes path to regedit @@ -137,39 +82,105 @@ param ( writeErrorTip 'But xmake could not run... Why?' myExit 1 } +} + +function xmakeSelfBuild { Write-Host "Pulling xmake from branch $branch" - $outfile = $temppath + "\$pid-xmake-repo.zip" + $outfile = Join-Path $temppath "$pid-xmake-repo.zip" try { - Invoke-Webrequest "https://github.com/xmake-io/xmake/archive/$branch.zip" -OutFile "$outfile" + Invoke-Webrequest "https://github.com/xmake-io/xmake/archive/$branch.zip" -OutFile $outfile } catch { writeErrorTip 'Pull Failed!' writeErrorTip 'xmake is now available but may not be newest' myExit } Write-Host 'Expanding archive...' - New-Item -Path "$temppath" -Name "$pid-xmake-repo" -ItemType "directory" -Force - $oldpwd = $pwd - $repodir = $temppath + "\$pid-xmake-repo" + $oldpwd = Get-Location + $repodir = New-Item -Path $temppath -Name "$pid-xmake-repo" -ItemType Directory -Force try { - Expand-Archive "$outfile" "$repodir" -Force + Expand-Archive -Path $outfile -DestinationPath $repodir -Force Write-Host 'Self-building...' - Set-Location ($repodir + "\xmake-$branch\core") + Set-Location $(Join-Path $repodir "\xmake-$branch\core") xmake Write-Host 'Copying new files...' - Copy-Item 'build\xmake.exe' "$installdir" -Force + Copy-Item -Path '.\build\xmake.exe' -Destination $installdir -Force Set-Location '..\xmake' - Copy-Item * "$installdir" -Recurse -Force + Copy-Item -Path * -Destination $installdir -Recurse -Force xmake --version } catch { writeErrorTip 'Update Failed!' writeErrorTip 'xmake is now available but may not be newest' } finally { - Set-Location "$oldpwd" -ErrorAction SilentlyContinue - Remove-Item "$outfile" -ErrorAction SilentlyContinue - Remove-Item "$repodir" -Recurse -Force -ErrorAction SilentlyContinue + Set-Location $oldpwd -ErrorAction SilentlyContinue + Remove-Item $outfile -ErrorAction SilentlyContinue + Remove-Item $repodir -Recurse -Force -ErrorAction SilentlyContinue } +} + +function registerTabCompletion { + + function writeDataToFile($file) { + $encoding = [text.encoding]::UTF8 + if (Test-Path $file -PathType Leaf) { + #Create a stream reader to get the file's encoding and contents. + $sr = New-Object System.IO.StreamReader($file, $true) + [char[]] $buffer = new-object char[] 3 + $sr.Read($buffer, 0, 3) | Out-Null + $encoding = $sr.CurrentEncoding + $sr.Close() | Out-Null + + if ($(Get-Content $file) -imatch "Register-ArgumentCompleter -Native -CommandName xmake -ScriptBlock") { + Write-Host "Seems the tab completion of xmake has installed here..." + return + } + } - if (-not $env:CI) { - registerTabCompletion + try { + [IO.File]::AppendAllText($file, "`n", $encoding) + } catch { + writeErrorTip "Failed to append to profile!" + writeErrorTip "Please try again as administrator" + return + } + try { + $content = (Invoke-Webrequest 'https://raw.githubusercontent.com/xmake-io/xmake/master/scripts/register-completions.ps1' -UseBasicParsing).Content + } catch { + writeErrorTip 'Download failed!' + writeErrorTip 'Check your network or... the news of S3 break' + return + } + [IO.File]::AppendAllText($file, $content, $encoding) + [IO.File]::AppendAllText($file, "`n", $encoding) + } + $message = 'Tab completion service' + $question = 'Would you like to install tab completion service of xmake to your profile?' + + $choices = @( + (New-Object Management.Automation.Host.ChoiceDescription -ArgumentList @( + 'For &all users', + "Install for all users, writes to $($PROFILE.AllUsersAllHosts), admin privilege is needed.")), + (New-Object Management.Automation.Host.ChoiceDescription -ArgumentList @( + 'Just for &me', + "Install for current user, writes to $($PROFILE.CurrentUserAllHosts).")), + (New-Object Management.Automation.Host.ChoiceDescription -ArgumentList @( + 'Just for this &host', + "Install for current user current host, writes to $($PROFILE.CurrentUserCurrentHost).")), + (New-Object Management.Automation.Host.ChoiceDescription -ArgumentList @( + '&No', + "Do not install xmake's tab completion service.")) + ) + switch ($Host.UI.PromptForChoice($message, $question, $choices, 1)) { + 0 { writeDataToFile($PROFILE.AllUsersAllHosts) } + 1 { writeDataToFile($PROFILE.CurrentUserAllHosts) } + 2 { writeDataToFile($PROFILE.CurrentUserCurrentHost) } } } + +checkTempAccess +xmakeInstall + +if (-not $env:CI) { + xmakeSelfBuild + registerTabCompletion +} + -- cgit v1.3.1 From f626059565d8a99d963b64927800d4d2e0020c73 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 6 Jun 2019 18:11:02 +0800 Subject: fix --- scripts/get.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/get.ps1 b/scripts/get.ps1 index 968b2e7d4..3b31701dc 100644 --- a/scripts/get.ps1 +++ b/scripts/get.ps1 @@ -35,7 +35,7 @@ if ($PSVersionTable.PSVersion.Major -lt 5) { writeErrorTip 'Sorry but PowerShell v5+ is required' throw 'PowerShell''s version too low' } -$temppath = ($null -ne $env:TMP, $env:TEMP, '.')[0] +$temppath = ($env:TMP, $env:TEMP, '.' -ne $null)[0] [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" function checkTempAccess { -- cgit v1.3.1 From 3983a4c766b127cc50c36bb36ad7a779e3ce9432 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 6 Jun 2019 18:18:08 +0800 Subject: improve script --- scripts/get.ps1 | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'scripts') diff --git a/scripts/get.ps1 b/scripts/get.ps1 index 3b31701dc..5dc333c6c 100644 --- a/scripts/get.ps1 +++ b/scripts/get.ps1 @@ -46,7 +46,7 @@ function checkTempAccess { } catch { writeErrorTip 'Cannot write to temp path' writeErrorTip 'Please set environment var "TMP" to another path' - myExit 1 + throw } } @@ -58,7 +58,7 @@ function xmakeInstall { } catch { writeErrorTip 'Download failed!' writeErrorTip 'Check your network or... the news of S3 break' - myExit 1 + throw } Write-Host 'Start installation... Hope your antivirus doesn''t trouble' $installdir = Join-Path $env:HOME 'xmake' @@ -68,7 +68,7 @@ function xmakeInstall { } catch { writeErrorTip 'Install failed!' writeErrorTip 'Close your antivirus then try again' - myExit 1 + throw } finally { Remove-Item $outfile -ErrorAction SilentlyContinue } @@ -80,7 +80,7 @@ function xmakeInstall { } catch { writeErrorTip 'Everything is showing installation has finished' writeErrorTip 'But xmake could not run... Why?' - myExit 1 + throw } } @@ -92,7 +92,7 @@ function xmakeSelfBuild { } catch { writeErrorTip 'Pull Failed!' writeErrorTip 'xmake is now available but may not be newest' - myExit + throw } Write-Host 'Expanding archive...' $oldpwd = Get-Location @@ -110,6 +110,7 @@ function xmakeSelfBuild { } catch { writeErrorTip 'Update Failed!' writeErrorTip 'xmake is now available but may not be newest' + throw } finally { Set-Location $oldpwd -ErrorAction SilentlyContinue Remove-Item $outfile -ErrorAction SilentlyContinue @@ -176,11 +177,18 @@ function registerTabCompletion { } } -checkTempAccess -xmakeInstall +try { + checkTempAccess + xmakeInstall +} catch { + myExit 1 +} + if (-not $env:CI) { - xmakeSelfBuild + try { + xmakeSelfBuild + } catch { } # continue registerTabCompletion } -- cgit v1.3.1 From 9aa7e776e2bd429962f78632e043bba2c728c46c Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 6 Jun 2019 18:19:53 +0800 Subject: fix --- scripts/get.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/get.ps1 b/scripts/get.ps1 index 5dc333c6c..bd706b4d4 100644 --- a/scripts/get.ps1 +++ b/scripts/get.ps1 @@ -4,7 +4,8 @@ param ( [string]$branch = "master", - [string]$version = "v2.2.6" + [string]$version = "v2.2.6", + [string]$installdir = $(Join-Path $env:HOME 'xmake') ) function myExit($code) { @@ -61,7 +62,6 @@ function xmakeInstall { throw } Write-Host 'Start installation... Hope your antivirus doesn''t trouble' - $installdir = Join-Path $env:HOME 'xmake' Write-Host "Install to $installdir" try { Start-Process -FilePath $outfile -ArgumentList "/S /D=$installdir" -Wait -- cgit v1.3.1 From a1b6a1e11a7b0dacbe718b78e80c92107e43203b Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 6 Jun 2019 18:36:21 +0800 Subject: fix script --- .appveyor.yml | 4 ++-- scripts/get.ps1 | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/.appveyor.yml b/.appveyor.yml index 0971f9516..c410b84c8 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -10,13 +10,13 @@ platform: install: - ps: | - Invoke-Command -ScriptBlock ([ScriptBlock]::Create((Invoke-Webrequest "https://raw.githubusercontent.com/xmake-io/xmake/dev/scripts/get.ps1" -UseBasicParsing).Content)) -ArgumentList "dev" + ./scripts/get.ps1 "dev" build_script: - ps: | Get-Command xmake xmake --version - xmake run --project=core + xmake build --project=core .\core\build\xmake.exe --version Set-AppveyorBuildVariable -Name XMAKE_PROGRAM_DIR -Value $(Join-Path $(Get-Location) "xmake") Copy-Item -Force core\build\xmake.exe $HOME\xmake diff --git a/scripts/get.ps1 b/scripts/get.ps1 index bd706b4d4..9b500d44c 100644 --- a/scripts/get.ps1 +++ b/scripts/get.ps1 @@ -190,5 +190,7 @@ if (-not $env:CI) { xmakeSelfBuild } catch { } # continue registerTabCompletion +} else { + Write-Host "Self bulid and tab completion registration has been skipped" } -- cgit v1.3.1 From f564e7dbd980ece14d7e2e15f4499d8c1b7db858 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 6 Jun 2019 18:51:11 +0800 Subject: fix --- .appveyor.yml | 6 ++++-- scripts/get.ps1 | 8 ++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/.appveyor.yml b/.appveyor.yml index c410b84c8..fdcf4db94 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -10,7 +10,7 @@ platform: install: - ps: | - ./scripts/get.ps1 "dev" + ./scripts/get.ps1 -branch $env:APPVEYOR_REPO_BRANCH build_script: - ps: | @@ -24,7 +24,9 @@ build_script: after_build: - ps: | Copy-Item .\core\build\xmake.exe .\xmake - Push-AppveyorArtifact .\xmake -FileName xmake.zip -DeploymentName "xmake-$($env:PLATFORM)" + Copy-Item .\*.md .\xmake + Compress-Archive -Path .\xmake -DestinationPath .\archive.zip + Push-AppveyorArtifact .\archive.zip -FileName xmake.zip -DeploymentName "xmake-$($env:PLATFORM)" test_script: - ps: | diff --git a/scripts/get.ps1 b/scripts/get.ps1 index 9b500d44c..769585ebd 100644 --- a/scripts/get.ps1 +++ b/scripts/get.ps1 @@ -5,9 +5,13 @@ param ( [string]$branch = "master", [string]$version = "v2.2.6", - [string]$installdir = $(Join-Path $env:HOME 'xmake') + [string]$installdir = $(Join-Path $(if($env:HOME) { $env:HOME } else { "C:\" }) 'xmake') ) +echo $branch +echo $version +echo $installdir + function myExit($code) { if ($code -is [int] -and $code -ne 0) { throw $Error[0] @@ -191,6 +195,6 @@ if (-not $env:CI) { } catch { } # continue registerTabCompletion } else { - Write-Host "Self bulid and tab completion registration has been skipped" + Write-Host "Self bulid and tab completion registration has been skipped for CI" } -- cgit v1.3.1 From 625ee243f954265baf280c4130ac96e331bd3e96 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 6 Jun 2019 19:20:56 +0800 Subject: fix --- scripts/get.ps1 | 4 ---- xmake/scripts/update-script.bat | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) (limited to 'scripts') diff --git a/scripts/get.ps1 b/scripts/get.ps1 index 769585ebd..8bce62861 100644 --- a/scripts/get.ps1 +++ b/scripts/get.ps1 @@ -8,10 +8,6 @@ param ( [string]$installdir = $(Join-Path $(if($env:HOME) { $env:HOME } else { "C:\" }) 'xmake') ) -echo $branch -echo $version -echo $installdir - function myExit($code) { if ($code -is [int] -and $code -ne 0) { throw $Error[0] diff --git a/xmake/scripts/update-script.bat b/xmake/scripts/update-script.bat index f0df7c1bd..760db0817 100644 --- a/xmake/scripts/update-script.bat +++ b/xmake/scripts/update-script.bat @@ -1,7 +1,7 @@ @echo off echo Removing old files -cd "%~1" +cd /d "%~1" del actions core includes languages modules platforms plugins repository rules scripts templates themes /S /Q /F >nul echo Copying from temp directory to "%~1" xcopy "%~2" "%~1" /S /Y /Q >nul \ No newline at end of file -- cgit v1.3.1