summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorOpportunityLiu <[email protected]>2019-06-06 18:06:31 +0800
committerOpportunityLiu <[email protected]>2019-06-06 18:06:31 +0800
commit7cac3d417c9eb0218669bc3c3b5ef390ff492c64 (patch)
treeade788a6cce8a896bea1b46e5cc8ad9c69883679 /scripts
parent78fbcdf0ebd350643da2ac8f42589adae9b2a4e0 (diff)
skip self build for ci
Diffstat (limited to 'scripts')
-rw-r--r--scripts/get.ps1225
1 files changed, 118 insertions, 107 deletions
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 writeErrorTip($msg) {
- Write-Host $msg -BackgroundColor Red -ForegroundColor White
- }
-
- function writeLogoLine($msg) {
- Write-Host $msg -BackgroundColor White -ForegroundColor DarkBlue
+function myExit($code) {
+ if ($code -is [int] -and $code -ne 0) {
+ throw $Error[0]
+ } else {
+ break
}
+}
- 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
- }
- }
+function writeErrorTip($msg) {
+ Write-Host $msg -BackgroundColor Red -ForegroundColor White
+}
- 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?'
+function writeLogoLine($msg) {
+ Write-Host $msg -BackgroundColor White -ForegroundColor DarkBlue
+}
- $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) }
- }
- }
+writeLogoLine ' _ '
+writeLogoLine ' __ ___ __ __ __ _| | ______ '
+writeLogoLine ' \ \/ / | \/ |/ _ | |/ / __ \ '
+writeLogoLine ' > < | \__/ | /_| | < ___/ '
+writeLogoLine ' /_/\_\_|_| |_|\__ \|_|\_\____| getter '
+writeLogoLine ' '
+writeLogoLine ' '
- 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 = ($null -ne $env:TMP, $env:TEMP, '.')[0]
+[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"
- 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
}
+}
- if (-not $env:CI) {
- registerTabCompletion
+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
+ }
+ }
+
+ 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
+}
+