Updating KoreBuild to use kvm/kpm/kre

This commit is contained in:
Louis DeJardin 2014-05-02 14:29:57 -07:00
parent 6cb896dc0f
commit c1e8c7a0f7
6 changed files with 352 additions and 77 deletions

View File

@ -12,4 +12,4 @@
<files>
<file src="build\*.*" target="build" />
</files>
</package>
</package>

View File

@ -18,6 +18,9 @@ copy %CACHED_NUGET% .nuget\nuget.exe > nul
IF EXIST packages\KoreBuild goto run
.nuget\NuGet.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre
.nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion
CALL packages\KoreBuild\build\kvm install -svr50 -x86
CALL packages\KoreBuild\build\kvm install -svrc50 -x86
:run
CALL packages\KoreBuild\build\kvm use default -svr50 -x86
packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %*

View File

@ -4,4 +4,5 @@ k-restore
Restores nuget packages required for k projects. Downloads and executes k sdk tools.
*/}
k command='restore'
exec program='cmd' commandline='/C kpm restore' if='!IsMono'
exec program='kpm' commandline='restore' if='IsMono'

View File

@ -3,82 +3,9 @@
k
Run klr commands in your project. Executes k sdk.
kVersion='0.0.1-pre-30109-087'
May be passed to override the nuget package version holding xunit console runner.
kProgram='...'
May be passed to override the path to the xunit program that will be executed
command=''
prefetch='true'
May be passed if fetching k from nuget is required before running
*/}
default prefetch='${true}'
default mono='${IsMono}'
nuget-install package='ProjectK' outputDir='packages' extra='-pre -nocache' once='ProjectK-NuGet' if='prefetch && !mono'
nuget-install package='ProjectK.Mono' outputDir='packages' extra='-pre -nocache' once='ProjectK-NuGet' if='mono'
@{
Func<string, long> getVersion = version => {
var dash = version.LastIndexOf('-');
if(dash != -1)
{
var lastToken = version.Substring(dash + 1);
if(lastToken.StartsWith("t"))
{
return Int64.Parse(lastToken.Substring(1));
}
return Int64.Parse(lastToken);
}
return Int64.MaxValue;
};
var projectKPrefix = mono ? "ProjectK.Mono" : "ProjectK";
string packagesDir = Path.Combine(Directory.GetCurrentDirectory(), "packages"),
projectKDir = Directory.EnumerateDirectories(packagesDir, projectKPrefix + "*")
.OrderByDescending(getVersion)
.First();
}
default kProgram='${projectKDir}/tools/k.cmd'
exec program='${Path.GetFullPath(kProgram)}' commandline='${command}' if='!mono'
default kMonoProgram='${projectKDir}/tools/net45/klr.mono.managed.dll'
default monoPath='${Environment.GetEnvironmentVariable("MONO_PATH")}'
@{
if(mono)
{
if(string.IsNullOrEmpty(monoPath))
{
monoPath = "mono";
}
var folder = Path.Combine(projectKDir, "tools", "net45");
var kMonoEntryPoint = Path.GetFullPath(kMonoProgram);
if(command.StartsWith("build"))
{
command = kMonoEntryPoint + " --lib " + folder + " Microsoft.Net.Project " + command;
}
else if(command.StartsWith("restore"))
{
command = Path.Combine(projectKDir, "tools", "NuGet.exe") + " " + command;
}
else
{
command = kMonoEntryPoint + " --lib " + folder + " Microsoft.Net.ApplicationHost " + command;
}
}
}
exec program='${monoPath}' commandline='${command}' if='mono'
exec program='cmd' commandline='/C k ${command}' if='!IsMono'
exec program='k' commandline='${command}' if='IsMono'

8
build/kvm.cmd Normal file
View File

@ -0,0 +1,8 @@
@Echo off
PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0kvm.ps1' %*"
IF EXIST "%USERPROFILE%\.kre\run-once.cmd" (
CALL "%USERPROFILE%\.kre\run-once.cmd"
DEL "%USERPROFILE%\.kre\run-once.cmd"
)

336
build/kvm.ps1 Normal file
View File

@ -0,0 +1,336 @@
param(
[parameter(Position=0)]
[string] $command,
[switch] $verbosity = $false,
[alias("g")][switch] $global = $false,
[switch] $x86 = $false,
[switch] $x64 = $false,
[switch] $svr50 = $false,
[switch] $svrc50 = $false,
[parameter(Position=1, ValueFromRemainingArguments=$true)]
[string[]]$args=@()
)
$userKrePath = $env:USERPROFILE + "\.kre"
$globalKrePath = $env:ProgramFiles + "\KRE"
$scriptPath = $myInvocation.MyCommand.Definition
function Kvm-Help {
@"
kvm - K Runtime Environment Version Manager
kvm upgrade
install latest KRE from feed
set 'default' alias
add KRE bin to path of current command line
kvm install <semver>|<alias> [-x86][-x64] [-svr50][-svrc50] [-g|-global]
install requested KRE from feed
kvm list [-g|-global]
list KRE versions installed
kvm use <semver>|<alias> [-x86][-x64] [-svr50][-svrc50] [-g|-global]
add KRE bin to path of current command line
kvm alias
list KRE aliases which have been defined
kvm alias <alias>
display value of named alias
kvm alias <alias> <semver> [-x86][-x64] [-svr50][-svrc50]
set alias to specific version
"@ | Write-Host
}
function Kvm-Upgrade {
$version = Kvm-Find-Latest (Requested-Platform "svr50") (Requested-Architecture "x86")
Kvm-Install $version
Kvm-Alias-Set "default" $version
}
function Kvm-Find-Latest {
param(
[string] $platform,
[string] $architecture
)
Write-Host "Determining latest version"
$url = "https://www.myget.org/F/aspnetvnext/api/v2/GetUpdates()?packageIds=%27KRE-$platform-$architecture%27&versions=%270.0%27&includePrerelease=true&includeAllVersions=false"
$wc = New-Object System.Net.WebClient
$wc.Credentials = new-object System.Net.NetworkCredential("aspnetreadonly", "4d8a2d9c-7b80-4162-9978-47e918c9658c")
[xml]$xml = $wc.DownloadString($url)
$version = Select-Xml "//d:Version" -Namespace @{d='http://schemas.microsoft.com/ado/2007/08/dataservices'} $xml
return $version
}
function Kvm-Install-Latest {
Kvm-Install (Kvm-Find-Latest (Requested-Platform "svr50") (Requested-Architecture "x86"))
}
function Do-Kvm-Download {
param(
[string] $kreFullName,
[string] $kreFolder
)
$parts = $kreFullName.Split(".", 2)
$url = "https://www.myget.org/F/aspnetvnext/api/v2/package/" + $parts[0] + "/" + $parts[1]
$kreFile = "$kreFolder\$kreFullName.nupkg"
If (Test-Path $kreFolder) {
Remove-Item $kreFolder -Force -Recurse
}
Write-Host "Downloading" $kreFullName "from https://www.myget.org/F/aspnetvnext/api/v2/"
md $kreFolder -Force | Out-Null
$wc = New-Object System.Net.WebClient
$wc.Credentials = new-object System.Net.NetworkCredential("aspnetreadonly", "4d8a2d9c-7b80-4162-9978-47e918c9658c")
$wc.DownloadFile($url, $kreFile)
Do-Kvm-Unpack $kreFile $kreFolder
}
function Do-Kvm-Unpack {
param(
[string] $kreFile,
[string] $kreFolder
)
Write-Host "Installing to" $kreFolder
[System.Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem') | Out-Null
[System.IO.Compression.ZipFile]::ExtractToDirectory($kreFile, $kreFolder)
If (Test-Path ($kreFolder + "\[Content_Types].xml")) {
Remove-Item ($kreFolder + "\[Content_Types].xml")
}
If (Test-Path ($kreFolder + "\_rels\")) {
Remove-Item ($kreFolder + "\_rels\") -Force -Recurse
}
If (Test-Path ($kreFolder + "\package\")) {
Remove-Item ($kreFolder + "\package\") -Force -Recurse
}
}
function Kvm-Install {
param(
[string] $versionOrAlias
)
if ($versionOrAlias.EndsWith(".nupkg"))
{
$kreFullName = [System.IO.Path]::GetFileNameWithoutExtension($versionOrAlias)
$kreFolder = "$userKrePath\packages\$kreFullName"
$kreFile = "$kreFolder\$kreFullName.nupkg"
md $kreFolder -Force | Out-Null
copy $versionOrAlias $kreFile
Do-Kvm-Unpack $kreFile $kreFolder
}
else
{
$kreFullName = Requested-VersionOrAlias $versionOrAlias
$kreFolder = "$userKrePath\packages\$kreFullName"
Do-Kvm-Download $kreFullName $kreFolder
Kvm-Use $versionOrAlias
}
}
function Kvm-Global-Install {
param(
[string] $versionOrAlias
)
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{
$arguments = "install -global $versionOrAlias"
if ($x86) {$arguments = "$arguments -x86"}
if ($x64) {$arguments = "$arguments -x64"}
if ($svr50) {$arguments = "$arguments -svr50"}
if ($svrc50) {$arguments = "$arguments -svrc50"}
$arguments = "& '$scriptPath' $arguments"
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments
Kvm-Global-Use $versionOrAlias
break
}
$kreFullName = Requested-VersionOrAlias $versionOrAlias
$kreFolder = $globalKrePath + "\packages\$kreFullName"
Do-Kvm-Download $kreFullName $kreFolder
}
function Kvm-List {
Get-ChildItem ($userKrePath + "\packages\") | Select Name
}
function Kvm-Global-List {
Get-ChildItem ($globalKrePath + "\packages\") | Select Name
}
function Kvm-Use {
param(
[string] $versionOrAlias
)
$kreFullName = Requested-VersionOrAlias $versionOrAlias
$kreBin = $userKrePath + "\packages\" + $kreFullName + "\bin"
Write-Host "Adding" $kreBin "to PATH"
$newPath = $kreBin
foreach($portion in $env:Path.Split(';')) {
if (!$portion.StartsWith($userKrePath) -and !$portion.StartsWith($globalKrePath)) {
$newPath = $newPath + ";" + $portion
}
}
@"
SET "KRE_VERSION=$version"
SET "PATH=$newPath"
"@ | Out-File ($userKrePath + "\run-once.cmd") ascii
}
function Kvm-Global-Use {
param(
[string] $versionOrAlias
)
$kreFullName = Requested-VersionOrAlias $versionOrAlias
$kreBin = "$globalKrePath\packages\$kreFullName\bin"
Write-Host "Adding" $kreBin "to PATH"
$newPath = $kreBin
foreach($portion in $env:Path.Split(';')) {
if (!$portion.StartsWith($userKrePath) -and !$portion.StartsWith($globalKrePath)) {
$newPath = $newPath + ";" + $portion
}
}
@"
SET "KRE_VERSION=$version"
SET "PATH=$newPath"
"@ | Out-File ($userKrePath + "\run-once.cmd") ascii
}
function Kvm-Alias-List {
md ($userKrePath + "\alias\") -Force | Out-Null
Get-ChildItem ($userKrePath + "\alias\") | Select @{label='Alias';expression={$_.BaseName}}, @{label='Name';expression={Get-Content $_.FullName }} | Format-Table -AutoSize
}
function Kvm-Alias-Get {
param(
[string] $name
)
md ($userKrePath + "\alias\") -Force | Out-Null
Write-Host "Alias '$name' is set to" (Get-Content ($userKrePath + "\alias\" + $name + ".txt"))
}
function Kvm-Alias-Set {
param(
[string] $name,
[string] $value
)
$kreFullName = "KRE-" + (Requested-Platform "svr50") + "-" + (Requested-Architecture "x86") + "." + $value
Write-Host "Setting alias '$name' to '$kreFullName'"
md ($userKrePath + "\alias\") -Force | Out-Null
$kreFullName | Out-File ($userKrePath + "\alias\" + $name + ".txt") ascii
}
function Requested-VersionOrAlias() {
param(
[string] $versionOrAlias
)
If (Test-Path ($userKrePath + "\alias\" + $versionOrAlias + ".txt")) {
$aliasValue = Get-Content ($userKrePath + "\alias\" + $versionOrAlias + ".txt")
$parts = $aliasValue.Split('.', 2)
$pkgVersion = $parts[1]
$parts =$parts[0].Split('-', 3)
$pkgPlatform = Requested-Platform $parts[1]
$pkgArchitecture = Requested-Architecture $parts[2]
} else {
$pkgVersion = $versionOrAlias
$pkgPlatform = Requested-Platform "svr50"
$pkgArchitecture = Requested-Architecture "x86"
}
return "KRE-" + $pkgPlatform + "-" + $pkgArchitecture + "." + $pkgVersion
}
function Requested-Platform() {
param(
[string] $default
)
if ($svr50 -and $svrc50) {
Throw "This command cannot accept both -svr50 and -svrc50"
}
if ($svr50) {
return "svr50"
}
if ($svrc50) {
return "svrc50"
}
return $default
}
function Requested-Architecture() {
param(
[string] $default
)
if ($x86 -and $x64) {
Throw "This command cannot accept both -x86 and -x64"
}
if ($x86) {
return "x86"
}
if ($x64) {
return "x64"
}
return $default
}
try {
if ($global) {
switch -wildcard ($command + " " + $args.Count) {
# "upgrade 0" {Kvm-Global-Upgrade}
# "install 0" {Kvm-Global-Install-Latest}
"install 1" {Kvm-Global-Install $args[0]}
"list 0" {Kvm-Global-List}
"use 1" {Kvm-Global-Use $args[0]}
default {Write-Host 'Unknown command, or global switch not supported'; Kvm-Help;}
}
} else {
switch -wildcard ($command + " " + $args.Count) {
"upgrade 0" {Kvm-Upgrade}
"install 0" {Kvm-Install-Latest}
"install 1" {Kvm-Install $args[0]}
"list 0" {Kvm-List}
"use 1" {Kvm-Use $args[0]}
"alias 0" {Kvm-Alias-List}
"alias 1" {Kvm-Alias-Get $args[0]}
"alias 2" {Kvm-Alias-Set $args[0] $args[1]}
"help" {Kvm-Help}
default {Write-Host 'Unknown command'; Kvm-Help;}
}
}
}
catch {
Write-Host $_ -ForegroundColor Red ;
}