Pull in latest `dnvm` from Home's dev branch

- lots of `dnvm.ps1` fixes
- FreeBSD fixes in `dnvm.sh`
This commit is contained in:
Doug Bunting 2015-06-17 11:28:48 -07:00
parent 00b2daa068
commit f55367597a
2 changed files with 77 additions and 49 deletions

View File

@ -1,4 +1,4 @@
#Requires -Version 3 #Requires -Version 2
if (Test-Path env:WEBSITE_SITE_NAME) if (Test-Path env:WEBSITE_SITE_NAME)
{ {
@ -67,7 +67,7 @@ function _WriteOut {
### Constants ### Constants
$ProductVersion="1.0.0" $ProductVersion="1.0.0"
$BuildVersion="beta5-10378" $BuildVersion="beta6-10390"
$Authors="Microsoft Open Technologies, Inc." $Authors="Microsoft Open Technologies, Inc."
# If the Version hasn't been replaced... # If the Version hasn't been replaced...
@ -87,13 +87,14 @@ Set-Variable -Option Constant "RuntimePackageName" "dnx"
Set-Variable -Option Constant "DefaultFeed" "https://www.myget.org/F/aspnetvnext/api/v2" Set-Variable -Option Constant "DefaultFeed" "https://www.myget.org/F/aspnetvnext/api/v2"
Set-Variable -Option Constant "DefaultUnstableFeed" "https://www.myget.org/F/aspnetvnext/api/v2" Set-Variable -Option Constant "DefaultUnstableFeed" "https://www.myget.org/F/aspnetvnext/api/v2"
Set-Variable -Option Constant "CrossGenCommand" "dnx-crossgen" Set-Variable -Option Constant "CrossGenCommand" "dnx-crossgen"
Set-Variable -Option Constant "OldCrossGenCommand" "k-crossgen"
Set-Variable -Option Constant "CommandPrefix" "dnvm-" Set-Variable -Option Constant "CommandPrefix" "dnvm-"
Set-Variable -Option Constant "DefaultArchitecture" "x86" Set-Variable -Option Constant "DefaultArchitecture" "x86"
Set-Variable -Option Constant "DefaultRuntime" "clr" Set-Variable -Option Constant "DefaultRuntime" "clr"
Set-Variable -Option Constant "AliasExtension" ".txt" Set-Variable -Option Constant "AliasExtension" ".txt"
# These are intentionally using "%" syntax. The environment variables are expanded whenever the value is used. # These are intentionally using "%" syntax. The environment variables are expanded whenever the value is used.
Set-Variable -Option Constant "OldUserHomes" @("%USERPROFILE%\.kre","%USERPROFILE%\.k") Set-Variable -Option Constant "OldUserHomes" @("%USERPROFILE%\.kre", "%USERPROFILE%\.k")
Set-Variable -Option Constant "DefaultUserHome" "%USERPROFILE%\$DefaultUserDirectoryName" Set-Variable -Option Constant "DefaultUserHome" "%USERPROFILE%\$DefaultUserDirectoryName"
Set-Variable -Option Constant "HomeEnvVar" "DNX_HOME" Set-Variable -Option Constant "HomeEnvVar" "DNX_HOME"
@ -252,7 +253,7 @@ function Safe-Filecopy {
} }
function GetArch($Architecture, $FallBackArch = $DefaultArchitecture) { function GetArch($Architecture, $FallBackArch = $DefaultArchitecture) {
if(![String]::IsNullOrWhiteSpace($Architecture)) { if(![String]::IsNullOrEmpty($Architecture)) {
$Architecture $Architecture
} elseif($CompatArch) { } elseif($CompatArch) {
$CompatArch $CompatArch
@ -262,7 +263,7 @@ function GetArch($Architecture, $FallBackArch = $DefaultArchitecture) {
} }
function GetRuntime($Runtime) { function GetRuntime($Runtime) {
if(![String]::IsNullOrWhiteSpace($Runtime)) { if(![String]::IsNullOrEmpty($Runtime)) {
$Runtime $Runtime
} else { } else {
$DefaultRuntime $DefaultRuntime
@ -560,7 +561,7 @@ function Download-Package(
} }
} }
Write-Progress -Activity ("Downloading $RuntimeShortFriendlyName from $url") -Id 2 -ParentId 1 -Completed Write-Progress -Status "Done" -Activity ("Downloading $RuntimeShortFriendlyName from $url") -Id 2 -ParentId 1 -Completed
} }
finally { finally {
Remove-Variable downloadData -Scope "Global" Remove-Variable downloadData -Scope "Global"
@ -632,10 +633,10 @@ function Change-Path() {
$newPath = $prependPath $newPath = $prependPath
foreach($portion in $existingPaths.Split(';')) { foreach($portion in $existingPaths.Split(';')) {
if(![string]::IsNullOrWhiteSpace($portion)) { if(![string]::IsNullOrEmpty($portion)) {
$skip = $portion -eq "" $skip = $portion -eq ""
foreach($removePath in $removePaths) { foreach($removePath in $removePaths) {
if(![string]::IsNullOrWhiteSpace($removePath)) { if(![string]::IsNullOrEmpty($removePath)) {
$removePrefix = if($removePath.EndsWith("\")) { $removePath } else { "$removePath\" } $removePrefix = if($removePath.EndsWith("\")) { $removePath } else { "$removePath\" }
if ($removePath -and (($portion -eq $removePath) -or ($portion.StartsWith($removePrefix)))) { if ($removePath -and (($portion -eq $removePath) -or ($portion.StartsWith($removePrefix)))) {
@ -645,7 +646,7 @@ function Change-Path() {
} }
} }
if (!$skip) { if (!$skip) {
if(![String]::IsNullOrWhiteSpace($newPath)) { if(![String]::IsNullOrEmpty($newPath)) {
$newPath += ";" $newPath += ";"
} }
$newPath += $portion $newPath += $portion
@ -678,7 +679,7 @@ function Ngen-Library(
[Parameter(Mandatory=$true)] [Parameter(Mandatory=$true)]
[string]$runtimeBin, [string]$runtimeBin,
[ValidateSet("x86","x64")] [ValidateSet("x86", "x64")]
[Parameter(Mandatory=$true)] [Parameter(Mandatory=$true)]
[string]$architecture) { [string]$architecture) {
@ -751,8 +752,12 @@ function dnvm-help {
$Script:ExitCodes = $ExitCodes.UnknownCommand $Script:ExitCodes = $ExitCodes.UnknownCommand
return return
} }
$help = Get-Help "dnvm-$Command" if($Host.Version.Major -lt 3) {
if($PassThru) { $help = Get-Help "dnvm-$Command"
} else {
$help = Get-Help "dnvm-$Command" -ShowWindow:$false
}
if($PassThru -Or $Host.Version.Major -lt 3) {
$help $help
} else { } else {
_WriteOut -ForegroundColor $ColorScheme.Help_Header "$CommandName $Command" _WriteOut -ForegroundColor $ColorScheme.Help_Header "$CommandName $Command"
@ -818,7 +823,7 @@ function dnvm-help {
if($help.description) { if($help.description) {
_WriteOut _WriteOut
_WriteOut -ForegroundColor $ColorScheme.Help_Header "remarks:" _WriteOut -ForegroundColor $ColorScheme.Help_Header "remarks:"
$help.description.Text.Split(@("`r","`n"), "RemoveEmptyEntries") | $help.description.Text.Split(@("`r", "`n"), "RemoveEmptyEntries") |
ForEach-Object { _WriteOut " $_" } ForEach-Object { _WriteOut " $_" }
} }
@ -833,7 +838,11 @@ function dnvm-help {
_WriteOut -ForegroundColor $ColorScheme.Help_Header "commands: " _WriteOut -ForegroundColor $ColorScheme.Help_Header "commands: "
Get-Command "$CommandPrefix*" | Get-Command "$CommandPrefix*" |
ForEach-Object { ForEach-Object {
$h = Get-Help $_.Name if($Host.Version.MajorVersion -lt 3) {
$h = Get-Help $_.Name
} else {
$h = Get-Help $_.Name -ShowWindow:$false
}
$name = $_.Name.Substring($CommandPrefix.Length) $name = $_.Name.Substring($CommandPrefix.Length)
if($DeprecatedCommands -notcontains $name) { if($DeprecatedCommands -notcontains $name) {
_WriteOut -NoNewLine " " _WriteOut -NoNewLine " "
@ -896,31 +905,26 @@ function dnvm-list {
function dnvm-alias { function dnvm-alias {
param( param(
[Alias("d")] [Alias("d")]
[Parameter(ParameterSetName="Delete",Mandatory=$true)]
[switch]$Delete, [switch]$Delete,
[Parameter(ParameterSetName="Read",Mandatory=$false,Position=0)]
[Parameter(ParameterSetName="Write",Mandatory=$true,Position=0)]
[Parameter(ParameterSetName="Delete",Mandatory=$true,Position=0)]
[string]$Name, [string]$Name,
[Parameter(ParameterSetName="Write",Mandatory=$true,Position=1)]
[string]$Version, [string]$Version,
[Alias("arch")] [Alias("arch")]
[ValidateSet("", "x86","x64")] [ValidateSet("", "x86", "x64", "arm")]
[Parameter(ParameterSetName="Write", Mandatory=$false)]
[string]$Architecture = "", [string]$Architecture = "",
[Alias("r")] [Alias("r")]
[ValidateSet("", "clr","coreclr")] [ValidateSet("", "clr", "coreclr")]
[Parameter(ParameterSetName="Write")]
[string]$Runtime = "") [string]$Runtime = "")
switch($PSCmdlet.ParameterSetName) { if($Version) {
"Read" { Read-Alias $Name } Write-Alias $Name $Version -Architecture $Architecture -Runtime $Runtime
"Write" { Write-Alias $Name $Version -Architecture $Architecture -Runtime $Runtime } } elseif ($Delete) {
"Delete" { Delete-Alias $Name } Delete-Alias $Name
} else {
Read-Alias $Name
} }
} }
@ -964,12 +968,12 @@ function dnvm-upgrade {
[string]$Alias = "default", [string]$Alias = "default",
[Alias("arch")] [Alias("arch")]
[ValidateSet("", "x86","x64")] [ValidateSet("", "x86", "x64", "arm")]
[Parameter(Mandatory=$false)] [Parameter(Mandatory=$false)]
[string]$Architecture = "", [string]$Architecture = "",
[Alias("r")] [Alias("r")]
[ValidateSet("", "clr","coreclr")] [ValidateSet("", "clr", "coreclr")]
[Parameter(Mandatory=$false)] [Parameter(Mandatory=$false)]
[string]$Runtime = "", [string]$Runtime = "",
@ -1026,12 +1030,12 @@ function dnvm-install {
[string]$VersionNuPkgOrAlias, [string]$VersionNuPkgOrAlias,
[Alias("arch")] [Alias("arch")]
[ValidateSet("", "x86","x64")] [ValidateSet("", "x86", "x64", "arm")]
[Parameter(Mandatory=$false)] [Parameter(Mandatory=$false)]
[string]$Architecture = "", [string]$Architecture = "",
[Alias("r")] [Alias("r")]
[ValidateSet("", "clr","coreclr")] [ValidateSet("", "clr", "coreclr")]
[Parameter(Mandatory=$false)] [Parameter(Mandatory=$false)]
[string]$Runtime = "", [string]$Runtime = "",
@ -1084,7 +1088,7 @@ function dnvm-install {
} }
if ($VersionNuPkgOrAlias -eq "latest") { if ($VersionNuPkgOrAlias -eq "latest") {
Write-Progress -Activity "Installing runtime" "Determining latest runtime" -Id 1 Write-Progress -Status "Determining Latest Runtime" -Activity "Installing runtime" -Id 1
$VersionNuPkgOrAlias = Find-Latest $Runtime $Architecture -Feed:$selectedFeed $VersionNuPkgOrAlias = Find-Latest $Runtime $Architecture -Feed:$selectedFeed
} }
@ -1094,7 +1098,7 @@ function dnvm-install {
if(!(Test-Path $VersionNuPkgOrAlias)) { if(!(Test-Path $VersionNuPkgOrAlias)) {
throw "Unable to locate package file: '$VersionNuPkgOrAlias'" throw "Unable to locate package file: '$VersionNuPkgOrAlias'"
} }
Write-Progress -Activity "Installing runtime" "Parsing package file name" -Id 1 Write-Progress -Activity "Installing runtime" -Status "Parsing package file name" -Id 1
$runtimeFullName = [System.IO.Path]::GetFileNameWithoutExtension($VersionNuPkgOrAlias) $runtimeFullName = [System.IO.Path]::GetFileNameWithoutExtension($VersionNuPkgOrAlias)
$Architecture = Get-PackageArch $runtimeFullName $Architecture = Get-PackageArch $runtimeFullName
$Runtime = Get-PackageRuntime $runtimeFullName $Runtime = Get-PackageRuntime $runtimeFullName
@ -1124,7 +1128,8 @@ function dnvm-install {
else { else {
$Architecture = GetArch $Architecture $Architecture = GetArch $Architecture
$Runtime = GetRuntime $Runtime $Runtime = GetRuntime $Runtime
$UnpackFolder = Join-Path $RuntimesDir "temp" $TempFolder = Join-Path $RuntimesDir "temp"
$UnpackFolder = Join-Path $TempFolder $runtimeFullName
$DownloadFile = Join-Path $UnpackFolder "$runtimeFullName.nupkg" $DownloadFile = Join-Path $UnpackFolder "$runtimeFullName.nupkg"
if(Test-Path $UnpackFolder) { if(Test-Path $UnpackFolder) {
@ -1134,18 +1139,18 @@ function dnvm-install {
New-Item -Type Directory $UnpackFolder | Out-Null New-Item -Type Directory $UnpackFolder | Out-Null
if($IsNuPkg) { if($IsNuPkg) {
Write-Progress -Activity "Installing runtime" "Copying package" -Id 1 Write-Progress -Activity "Installing runtime" -Status "Copying package" -Id 1
_WriteDebug "Copying local nupkg $VersionNuPkgOrAlias to $DownloadFile" _WriteDebug "Copying local nupkg $VersionNuPkgOrAlias to $DownloadFile"
Copy-Item $VersionNuPkgOrAlias $DownloadFile Copy-Item $VersionNuPkgOrAlias $DownloadFile
} else { } else {
# Download the package # Download the package
Write-Progress -Activity "Installing runtime" "Downloading runtime" -Id 1 Write-Progress -Activity "Installing runtime" -Status "Downloading runtime" -Id 1
_WriteDebug "Downloading version $VersionNuPkgOrAlias to $DownloadFile" _WriteDebug "Downloading version $VersionNuPkgOrAlias to $DownloadFile"
Download-Package $PackageVersion $Architecture $Runtime $DownloadFile -Proxy:$Proxy -Feed:$selectedFeed Download-Package $PackageVersion $Architecture $Runtime $DownloadFile -Proxy:$Proxy -Feed:$selectedFeed
} }
Write-Progress -Activity "Installing runtime" "Unpacking runtime" -Id 1 Write-Progress -Activity "Installing runtime" -Status "Unpacking runtime" -Id 1
Unpack-Package $DownloadFile $UnpackFolder Unpack-Package $DownloadFile $UnpackFolder
if(Test-Path $RuntimeFolder) { if(Test-Path $RuntimeFolder) {
@ -1155,7 +1160,19 @@ function dnvm-install {
else { else {
_WriteOut "Installing to $RuntimeFolder" _WriteOut "Installing to $RuntimeFolder"
_WriteDebug "Moving package contents to $RuntimeFolder" _WriteDebug "Moving package contents to $RuntimeFolder"
Move-Item $UnpackFolder $RuntimeFolder try {
Move-Item $UnpackFolder $RuntimeFolder
} catch {
if(Test-Path $RuntimeFolder) {
#Attempt to cleanup the runtime folder if it is there after a fail.
Remove-Item $RuntimeFolder -Recurse -Force
throw
}
}
#If there is nothing left in the temp folder remove it. There could be other installs happening at the same time as this.
if(-Not(Test-Path $(Join-Path $TempFolder "*"))) {
Remove-Item $TempFolder -Recurse
}
} }
dnvm-use $PackageVersion -Architecture:$Architecture -Runtime:$Runtime -Persistent:$Persistent dnvm-use $PackageVersion -Architecture:$Architecture -Runtime:$Runtime -Persistent:$Persistent
@ -1164,7 +1181,7 @@ function dnvm-install {
if (-not $NoNative) { if (-not $NoNative) {
if ((Is-Elevated) -or $Ngen) { if ((Is-Elevated) -or $Ngen) {
$runtimeBin = Get-RuntimePath $runtimeFullName $runtimeBin = Get-RuntimePath $runtimeFullName
Write-Progress -Activity "Installing runtime" "Generating runtime native images" -Id 1 Write-Progress -Activity "Installing runtime" -Status "Generating runtime native images" -Id 1
Ngen-Library $runtimeBin $Architecture Ngen-Library $runtimeBin $Architecture
} }
else { else {
@ -1178,12 +1195,19 @@ function dnvm-install {
} }
else { else {
_WriteOut "Compiling native images for $runtimeFullName to improve startup performance..." _WriteOut "Compiling native images for $runtimeFullName to improve startup performance..."
Write-Progress -Activity "Installing runtime" "Generating runtime native images" -Id 1 Write-Progress -Activity "Installing runtime" -Status "Generating runtime native images" -Id 1
if(Get-Command $CrossGenCommand -ErrorAction SilentlyContinue) {
$crossGenCommand = $CrossGenCommand
} else {
$crossGenCommand = $OldCrossGenCommand
}
if ($DebugPreference -eq 'SilentlyContinue') { if ($DebugPreference -eq 'SilentlyContinue') {
Start-Process $CrossGenCommand -Wait -WindowStyle Hidden Start-Process $crossGenCommand -Wait -WindowStyle Hidden
} }
else { else {
Start-Process $CrossGenCommand -Wait -NoNewWindow Start-Process $crossGenCommand -Wait -NoNewWindow
} }
_WriteOut "Finished native image compilation." _WriteOut "Finished native image compilation."
} }
@ -1198,7 +1222,7 @@ function dnvm-install {
dnvm-alias $Alias $PackageVersion -Architecture:$Architecture -Runtime:$Runtime dnvm-alias $Alias $PackageVersion -Architecture:$Architecture -Runtime:$Runtime
} }
Write-Progress -Activity "Install complete" -Id 1 -Complete Write-Progress -Status "Done" -Activity "Install complete" -Id 1 -Complete
} }
@ -1220,12 +1244,12 @@ function dnvm-use {
[string]$VersionOrAlias, [string]$VersionOrAlias,
[Alias("arch")] [Alias("arch")]
[ValidateSet("", "x86","x64")] [ValidateSet("", "x86", "x64", "arm")]
[Parameter(Mandatory=$false)] [Parameter(Mandatory=$false)]
[string]$Architecture = "", [string]$Architecture = "",
[Alias("r")] [Alias("r")]
[ValidateSet("", "clr","coreclr")] [ValidateSet("", "clr", "coreclr")]
[Parameter(Mandatory=$false)] [Parameter(Mandatory=$false)]
[string]$Runtime = "", [string]$Runtime = "",
@ -1431,7 +1455,11 @@ if(!$cmd) {
try { try {
if(Get-Command -Name "$CommandPrefix$cmd" -ErrorAction SilentlyContinue) { if(Get-Command -Name "$CommandPrefix$cmd" -ErrorAction SilentlyContinue) {
_WriteDebug "& dnvm-$cmd $cmdargs" _WriteDebug "& dnvm-$cmd $cmdargs"
& "dnvm-$cmd" @cmdargs if($host.Version.Major -lt 3) {
Invoke-Command ([ScriptBlock]::Create("dnvm-$cmd $cmdargs"))
} else {
& "dnvm-$cmd" @cmdargs
}
} }
else { else {
_WriteOut "Unknown command: '$cmd'" _WriteOut "Unknown command: '$cmd'"

View File

@ -2,7 +2,7 @@
# Source this file from your .bash-profile or script to use # Source this file from your .bash-profile or script to use
# "Constants" # "Constants"
_DNVM_BUILDNUMBER="beta5-10378" _DNVM_BUILDNUMBER="beta6-10390"
_DNVM_AUTHORS="Microsoft Open Technologies, Inc." _DNVM_AUTHORS="Microsoft Open Technologies, Inc."
_DNVM_RUNTIME_PACKAGE_NAME="dnx" _DNVM_RUNTIME_PACKAGE_NAME="dnx"
_DNVM_RUNTIME_FRIENDLY_NAME=".NET Execution Environment" _DNVM_RUNTIME_FRIENDLY_NAME=".NET Execution Environment"
@ -208,7 +208,7 @@ __dnvm_unpack() {
#Set shell commands as executable #Set shell commands as executable
find "$runtimeFolder/bin/" -type f \ find "$runtimeFolder/bin/" -type f \
-exec sh -c "head -c 11 {} | grep '/bin/bash' > /dev/null" \; -print | xargs chmod 775 -exec sh -c "head -c 20 {} | grep '/usr/bin/env bash\|/bin/bash' > /dev/null" \; -print | xargs chmod 775
#Set dnx to be executable #Set dnx to be executable
chmod 775 "$runtimeFolder/bin/dnx" chmod 775 "$runtimeFolder/bin/dnx"