summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpportunityLiu <[email protected]>2019-06-13 21:37:16 +0800
committerOpportunityLiu <[email protected]>2019-06-13 21:37:16 +0800
commit3ac4190baf80ca6734a35acdfd5ac5f089acbe3e (patch)
tree37b83342c5ac700bf67104b48fb9d2c2e2946a31
parent731e06180fc37f51da797bd58ce01700a4faa32a (diff)
improve win install & update
-rw-r--r--.appveyor.yml4
-rw-r--r--scripts/get.ps1130
-rw-r--r--scripts/getpb.ps192
-rw-r--r--xmake/actions/update/main.lua31
4 files changed, 72 insertions, 185 deletions
diff --git a/.appveyor.yml b/.appveyor.yml
index de90f012d..253c09efe 100644
--- a/.appveyor.yml
+++ b/.appveyor.yml
@@ -11,7 +11,7 @@ platform:
install:
# prepare tools
- ps: Push-Location C:/
- - ps: New-Item ./winenv/bin -ItemType Directory
+ - ps: (New-Item ./winenv/bin -ItemType Directory).FullName
# NSIS
- ps: Invoke-WebRequest "https://svwh.dl.sourceforge.net/project/nsis/NSIS 3/3.04/nsis-3.04.zip" -UseBasicParsing -OutFile ./nsis.zip
- ps: Invoke-WebRequest "https://svwh.dl.sourceforge.net/project/nsis/NSIS 3/3.04/nsis-3.04-strlen_8192.zip" -UseBasicParsing -OutFile ./nsis-longstr.zip
@@ -30,7 +30,7 @@ install:
#
- ps: Pop-Location
# install xmake
- - ps: ./scripts/get.ps1 -branch $env:APPVEYOR_REPO_BRANCH
+ - ps: ./scripts/get.ps1 -branch master
before_build:
- ps: (Get-Command xmake).FileVersionInfo.ProductVersion
diff --git a/scripts/get.ps1 b/scripts/get.ps1
index d471affd5..0a07c8d2e 100644
--- a/scripts/get.ps1
+++ b/scripts/get.ps1
@@ -1,46 +1,66 @@
+#! /usr/bin/pwsh
+#Requires -version 5
+
# xmake getter
# usage: (in powershell)
# Invoke-Expression (Invoke-Webrequest <my location> -UseBasicParsing).Content
param (
- [string]$branch = "master",
- [string]$version = "v2.2.6",
- [string]$installdir = $(Join-Path $(if($HOME) { $HOME } else { "C:\" }) 'xmake')
+ [string]$branch = "master",
+ [string]$installdir = ""
)
-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
-}
-
if (-not $env:CI) {
- writeLogoLine ' _ '
- writeLogoLine ' __ ___ __ __ __ _| | ______ '
- writeLogoLine ' \ \/ / | \/ |/ _ | |/ / __ \ '
- writeLogoLine ' > < | \__/ | /_| | < ___/ '
- writeLogoLine ' /_/\_\_|_| |_|\__ \|_|\_\____| getter '
- writeLogoLine ' '
- writeLogoLine ' '
+ $logo = @(
+ ' _ '
+ ' __ ___ __ __ __ _| | ______ '
+ ' \ \/ / | \/ |/ _ | |/ / __ \ '
+ ' > < | \__/ | /_| | < ___/ '
+ ' /_/\_\_|_| |_|\__ \|_|\_\____| getter '
+ ' '
+ ' ')
+ Write-Host $([string]::Join("`n", $logo)) -BackgroundColor White -ForegroundColor DarkBlue
}
-if ($PSVersionTable.PSVersion.Major -lt 5) {
- writeErrorTip 'Sorry but PowerShell v5+ is required'
- throw 'PowerShell''s version too low'
+if ($IsLinux -or $IsMacOS) {
+ writeErrorTip 'Install on *nix is not supported, try '
+ writeErrorTip '(Use curl) "bash <(curl -fsSL https://raw.githubusercontent.com/xmake-io/xmake/master/scripts/get.sh)"'
+ writeErrorTip 'or'
+ writeErrorTip '(Use wget) "bash <(wget https://raw.githubusercontent.com/xmake-io/xmake/master/scripts/get.sh -O -)"'
+ throw 'Unsupported platform'
}
+
$temppath = ($env:TMP, $env:TEMP, '.' -ne $null)[0]
[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"
+if ($null -eq $installdir -or $installdir -match '^\s*$') {
+ $installdir = & {
+ # Install to old xmake path
+ $oldXmake = Get-Command xmake -CommandType Application -ErrorAction SilentlyContinue
+ if ($oldXmake) {
+ return Split-Path $oldXmake.Path -Parent
+ }
+ if ($HOME) {
+ return Join-Path $HOME 'xmake'
+ }
+ if ($env:APPDATA) {
+ return Join-Path $env:APPDATA 'xmake'
+ }
+ if ($env:ProgramFiles) {
+ return Join-Path $env:ProgramFiles 'xmake'
+ }
+ return 'C:\xmake'
+ }
+}
+
+if ($null -eq $branch -or $branch -match '^\s*$') {
+ $branch = 'master'
+}
+
function checkTempAccess {
$outfile = Join-Path $temppath "$pid.tmp"
try {
@@ -55,9 +75,12 @@ function checkTempAccess {
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 .."
+ $x64arch = @('AMD64', 'IA64', 'ARM64')
+ $arch = if ($env:PROCESSOR_ARCHITECTURE -in $x64arch -or $env:PROCESSOR_ARCHITEW6432 -in $x64arch) { 'x64' } else { 'x86' }
+ $url = "https://ci.appveyor.com/api/projects/waruqi/xmake/artifacts/xmake-installer.exe?branch=$branch&pr=false&job=Image%3A+Visual+Studio+2017%3B+Platform%3A+$arch"
+ Write-Host "Start downloading $url .."
try {
- Invoke-Webrequest "https://github.com/xmake-io/xmake/releases/download/$version/xmake-$branch.exe" -OutFile $outfile
+ Invoke-Webrequest $url -OutFile $outfile -UseBasicParsing
} catch {
writeErrorTip 'Download failed!'
writeErrorTip 'Check your network or... the news of S3 break'
@@ -86,40 +109,6 @@ function xmakeInstall {
}
}
-function xmakeSelfBuild {
- Write-Host "Pulling xmake from branch $branch"
- $outfile = Join-Path $temppath "$pid-xmake-repo.zip"
- try {
- 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'
- throw
- }
- Write-Host 'Expanding archive...'
- $oldpwd = Get-Location
- $repodir = New-Item -Path $temppath -Name "$pid-xmake-repo" -ItemType Directory -Force
- try {
- Expand-Archive -Path $outfile -DestinationPath $repodir -Force
- Write-Host 'Self-building...'
- Set-Location $(Join-Path $repodir "\xmake-$branch\core")
- xmake
- Write-Host 'Copying new files...'
- Copy-Item -Path '.\build\xmake.exe' -Destination $installdir -Force
- Set-Location '..\xmake'
- Copy-Item -Path * -Destination $installdir -Recurse -Force
- xmake --version
- } 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
- Remove-Item $repodir -Recurse -Force -ErrorAction SilentlyContinue
- }
-}
-
function registerTabCompletion {
function writeDataToFile($file) {
@@ -133,12 +122,13 @@ function registerTabCompletion {
$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..."
+ Write-Host "Seems the tab completion of xmake has installed here... skipped"
return
}
}
try {
+ New-Item $(Split-Path $file -Parent) -ItemType Directory -Force | Out-Null
[IO.File]::AppendAllText($file, "`n", $encoding)
} catch {
writeErrorTip "Failed to append to profile!"
@@ -154,6 +144,8 @@ function registerTabCompletion {
}
[IO.File]::AppendAllText($file, $content, $encoding)
[IO.File]::AppendAllText($file, "`n", $encoding)
+ . $file
+ Write-Host "Tab completion installed"
}
$message = 'Tab completion service'
$question = 'Would you like to install tab completion service of xmake to your profile?'
@@ -179,20 +171,12 @@ function registerTabCompletion {
}
}
-try {
- checkTempAccess
- xmakeInstall
-} catch {
- myExit 1
-}
-
+checkTempAccess
+xmakeInstall
if (-not $env:CI) {
- try {
- xmakeSelfBuild
- } catch { } # continue
registerTabCompletion
} else {
- Write-Host "Self bulid and tab completion registration has been skipped for CI"
+ Write-Host "Tab completion registration has been skipped for CI"
}
diff --git a/scripts/getpb.ps1 b/scripts/getpb.ps1
deleted file mode 100644
index 4c4806cb9..000000000
--- a/scripts/getpb.ps1
+++ /dev/null
@@ -1,92 +0,0 @@
-& {
-
-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 Get-AppVeyorArtifacts{
- param(
- [parameter(Mandatory = $true)]
- [string]$Account,
- [parameter(Mandatory = $true)]
- [string]$Project,
- [parameter(Mandatory = $true)]
- [string]$DownloadDirectory)
- $apiUrl = 'https://ci.appveyor.com/api'
- $headers = @{
- 'Content-type' = 'application/json'
- }
- $obj = Invoke-RestMethod -Method Get -Uri "$apiUrl/projects/$Account/$Project/history?recordsNumber=13" -Headers $headers
- $job = $null
- if([environment]::Is64BitOperatingSystem){
- $job = 1
- }else{
- $job = 0
- }
- ForEach($_ in $obj.builds){
- $version = $_.version
- $build = Invoke-RestMethod -Method Get -Uri "$apiUrl/projects/$Account/$Project/build/$version" -Headers $headers
- $jobId = $build.build.jobs[$job].jobId
- $artifacts = Invoke-RestMethod -Method Get -Uri "$apiUrl/buildjobs/$jobId/artifacts" -Headers $headers
- $artifactFileName = $artifacts[0].fileName
- if($artifactFileName -eq "xmake.exe"){
- $localArtifactPath = "$DownloadDirectory\$artifactFileName"
- Invoke-RestMethod -Method Get -Uri "$apiUrl/buildjobs/$jobId/artifacts/$artifactFileName" -OutFile $localArtifactPath
- return
- }
- }
- throw 'artifact not found'
-}
-
-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'
-}
-
-try{
- $installdir="$HOME\xmake"
- try{Remove-Item -Recurse -Force $installdir}catch{}
- New-Item $installdir -ItemType directory
- try{
- Get-AppVeyorArtifacts waruqi xmake $installdir
- }catch{
- Get-AppVeyorArtifacts TitanSnow "xmake-90ua9" $installdir
- }
- if($branch -eq $null){ $branch='master' }
- Invoke-Webrequest "https://github.com/xmake-io/xmake/archive/$branch.zip" -OutFile "$installdir\temp.zip"
- Expand-Archive "$installdir\temp.zip" "$installdir\temp" -Force
- Move-Item "$installdir\temp\xmake-$branch\xmake\*" $installdir
- Remove-Item "$installdir\temp","$installdir\temp.zip" -Recurse -Force
- try{
- xmake --version | Out-Null
- }catch{
- $env:Path+=";$installdir"
- [Environment]::SetEnvironmentVariable("Path",[Environment]::GetEnvironmentVariable("Path",[System.EnvironmentVariableTarget]::User)+";$installdir",[System.EnvironmentVariableTarget]::User)
- }
- xmake --version
-}catch{
- writeErrorTip 'Error!'
- myExit 1
-}
-
-}
diff --git a/xmake/actions/update/main.lua b/xmake/actions/update/main.lua
index cab44adf3..fb463802c 100644
--- a/xmake/actions/update/main.lua
+++ b/xmake/actions/update/main.lua
@@ -30,6 +30,8 @@ import("privilege.sudo")
import("actions.require.impl.environment", {rootdir = os.programdir()})
import("get_version")
+local win_installer_name = "xmake-installer.exe"
+
-- run program with privilege
function _sudo_v(program, params)
@@ -131,7 +133,7 @@ function _uninstall()
end
-- do install
-function _install(sourcedir, version)
+function _install(sourcedir)
-- the install task
local install_task = function ()
@@ -148,26 +150,25 @@ function _install(sourcedir, version)
-- install it
os.cd(sourcedir)
if is_host("windows") then
- local installer = "xmake-" .. version .. ".exe"
- if os.isfile(installer) then
+ if os.isfile(win_installer_name) then
-- /D sets the default installation directory ($INSTDIR), overriding InstallDir and InstallDirRegKey. It must be the last parameter used in the command line and must not contain any quotes, even if the path contains spaces. Only absolute paths are supported.
local params = ("/D=" .. os.programdir()):split("%s", { strict = true })
- if option.get("quiet") then table.insert(params, 1, "/S") end
+ if not option.get("verbose") then table.insert(params, 1, "/S") end
-- need UAC?
if winos:version():gt("winxp") then
- _run_win_v(installer, params, true)
+ _run_win_v(win_installer_name, params, true)
else
- _run_win_v(installer, params, false)
+ _run_win_v(win_installer_name, params, false)
end
else
- raise("the installer(%s) not found!", installer)
+ raise("the installer(%s) not found!", win_installer_name)
end
else
os.vrun("./scripts/get.sh __local__")
end
return true
end,
- catch
+ catch
{
function (errors)
vprint(errors)
@@ -277,14 +278,8 @@ function main()
format("https://qcloud.coding.net/u/waruqi/p/xmake-releases/git/raw/master/xmake-%s.exe", version),
format("https://gitlab.com/xmake-mirror/xmake-releases/raw/master/xmake-%s.exe", version)}
else
- local lastest = semver.select("lastest", tags or {}, tags or {}, {})
- if lastest then
- mainurls = {format("https://github.com/xmake-io/xmake/releases/download/%s/xmake-%s.exe", lastest, version),
- format("https://qcloud.coding.net/u/waruqi/p/xmake-releases/git/raw/master/xmake-%s.exe", version),
- format("https://gitlab.com/xmake-mirror/xmake-releases/raw/master/xmake-%s.exe", version)}
- else
- raise("not support to update %s on windows!", version)
- end
+ -- regard as a git branch, fetch from ci
+ mainurls = {format("https://ci.appveyor.com/api/projects/waruqi/xmake/artifacts/xmake-installer.exe?branch=%s&pr=false&job=Image%%3A+Visual+Studio+2017%%3B+Platform%%3A+%s", version, os.arch())}
end
-- re-sort mainurls
@@ -313,7 +308,7 @@ function main()
-- all user provided urls are considered as git url since check has been performed in get_version
if is_official and not git.checkurl(url) then
os.mkdir(sourcedir)
- http.download(url, path.join(sourcedir, path.filename(url)))
+ http.download(url, path.join(sourcedir, win_installer_name))
else
if version:find('.', 1, true) then
git.clone(url, {outputdir = sourcedir})
@@ -357,7 +352,7 @@ function main()
if script_only then
_install_script(sourcedir)
else
- _install(sourcedir, version)
+ _install(sourcedir)
end
end