Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support update script #438

Merged
merged 23 commits into from
Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,31 @@ platform:
- Win64

install:
- cmd: echo %CI%
- ps: |
./scripts/get.ps1 -branch $env:APPVEYOR_REPO_BRANCH

build_script:
- ps: Invoke-Command -ScriptBlock ([ScriptBlock]::Create((Invoke-Webrequest "https://raw.githubusercontent.com/xmake-io/xmake/dev/scripts/get.ps1" -UseBasicParsing).Content)) -ArgumentList "dev"
- cmd: xmake --version
- cmd: xmake -P core
- cmd: set XMAKE_PROGRAM_DIR=%cd%\xmake
- cmd: core\build\xmake --version
- ps: Copy-Item -Force core\build\xmake.exe $HOME\xmake
- cmd: xmake lua -D tests\test.lua

#on_success:
# - ps: $env:XMAKE_PROGRAM_DIR=$null
# - ps: Invoke-Expression (Get-Content scripts\getpb.ps1 | Out-String)
- ps: |
Get-Command xmake
xmake --version
xmake build --project=core
Set-AppveyorBuildVariable -Name XMAKE_PROGRAM_DIR -Value $(Join-Path $(Get-Location) "xmake")
.\core\build\xmake.exe --version
Copy-Item -Force core\build\xmake.exe $(Get-Command xmake).Source

after_build:
- ps: Copy-Item core\build\xmake.exe .
- ps: |
Copy-Item .\core\build\xmake.exe .\xmake
Copy-Item .\*.md .\xmake
Compress-Archive -Path .\xmake -DestinationPath .\archive.zip -CompressionLevel Optimal
Push-AppveyorArtifact .\archive.zip -FileName xmake.zip -DeploymentName "xmake-$($env:PLATFORM)"

test_script:
- ps: |
xmake --version
Add-AppveyorTest -Name "tests" -Framework "xmake-test" -FileName ./tests/test.lua -Outcome Running
OpportunityLiu marked this conversation as resolved.
Show resolved Hide resolved
$time = Measure-Command {
$stdout = Invoke-Expression "xmake lua --verbose --diagnosis tests\test.lua" -ErrorVariable stderr
}
Update-AppveyorTest -Name "tests" -Framework "xmake-test" -FileName ./tests/test.lua -Outcome Passed -Duration $time.Milliseconds -StdOut $stdout -StdErr $stderr

artifacts:
- path: xmake.exe
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ core/.config.mak
winenv
xmake-ppa
!xmake/actions/build
.vscode/*
.vscode/
248 changes: 137 additions & 111 deletions scripts/get.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,129 +4,78 @@

param (
[string]$branch = "master",
[string]$version = "v2.2.6"
[string]$version = "v2.2.6",
[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]
} 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 = ($env:TMP, $env:TEMP, '.' -ne $null)[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
throw
}
}

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
throw
}
Write-Host 'Start installation... Hope your antivirus doesn''t trouble'
$installdir = $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
throw
} 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
Expand All @@ -135,40 +84,117 @@ param (
} catch {
writeErrorTip 'Everything is showing installation has finished'
writeErrorTip 'But xmake could not run... Why?'
myExit 1
throw
}
}

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
throw
}
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'
throw
} 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
}
}

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) }
}
}

try {
checkTempAccess
xmakeInstall
} catch {
myExit 1
}


if (-not $env:CI) {
try {
xmakeSelfBuild
} catch { } # continue
registerTabCompletion
} else {
Write-Host "Self bulid and tab completion registration has been skipped for CI"
}

21 changes: 21 additions & 0 deletions tests/modules/devel/git/test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import("devel.git")


function test_asgiturl()
assert(git.asgiturl("http://github.com/a/b") == "https://github.com/a/b.git")
assert(git.asgiturl("http://github.com/a/b/") == "https://github.com/a/b.git")
assert(git.asgiturl("HTTP://github.com//a/b/") == "https://github.com/a/b.git")
assert(git.asgiturl("http://github.com//a/b/s") == nil)
assert(git.asgiturl("https://github.com/a/b") == "https://github.com/a/b.git")
assert(git.asgiturl("https://github.com/a/b.git") == "https://github.com/a/b.git")
assert(git.asgiturl("HTTPS://GITHUB.com/a/b.git.git") == "https://github.com/a/b.git.git")

assert(git.asgiturl("github:a/b") == "https://github.com/a/b.git")
assert(git.asgiturl("github:a/b.git") == "https://github.com/a/b.git.git")
assert(git.asgiturl("GitHub://a/b/") == "https://github.com/a/b.git")
assert(git.asgiturl("github:a/b/c") == nil)
OpportunityLiu marked this conversation as resolved.
Show resolved Hide resolved
end

function main()
test_asgiturl()
end
Loading