merge package with master, refactor package.sh to package-dnvm.sh,add package-debian.sh

This commit is contained in:
Bryan Thornbury 2015-10-21 13:01:36 -07:00
commit 35f7be7495
29 changed files with 1733 additions and 413 deletions

View file

@ -10,5 +10,8 @@ if %ERRORLEVEL% neq 0 (
)
:continue
call %~dp0scripts/bootstrap
call %~dp0scripts/bootstrap.cmd
if %errorlevel% neq 0 exit /b %errorlevel%
call %~dp0scripts/package.cmd
if %errorlevel% neq 0 exit /b %errorlevel%

5
build.sh Executable file
View file

@ -0,0 +1,5 @@
#!/usr/bin/env bash
./scripts/bootstrap.sh
./scripts/package.sh

View file

@ -1,11 +0,0 @@
var VERSION='0.1'
var FULL_VERSION='0.1'
var AUTHORS='Microsoft Open Technologies, Inc.'
use-standard-lifecycle
k-standard-goals
#bootstrap
-// Build the compiler and publisher using dnu (kpm == dnu)
kpm-build projectFile='src/Microsoft.DotNet.Tools.Compiler/project.json'
kpm-build projectFile='src/Microsoft.DotNet.Tools.Publish/project.json'

View file

@ -11,14 +11,22 @@ set REPOROOT=%CD%
popd
set RID=win7-x64
set DNX_DIR=%REPOROOT%\artifacts\%RID%\dnx
set STAGE0_DIR=%REPOROOT%\artifacts\%RID%\stage0
set STAGE1_DIR=%REPOROOT%\artifacts\%RID%\stage1
set STAGE2_DIR=%REPOROOT%\artifacts\%RID%\stage2
where dnvm >nul 2>nul
if %errorlevel% == 0 goto have_dnvm
echo DNVM must be installed to bootstrap dotnet
exit /B 1
:have_dnvm
if not exist %DNX_DIR% mkdir %DNX_DIR%
set DNX_HOME=%DNX_DIR%
set DNX_USER_HOME=%DNX_DIR%
set DNX_GLOBAL_HOME=%DNX_DIR%
echo Installing and use-ing the latest CoreCLR x64 DNX ...
call dnvm install -nonative -u latest -r coreclr -arch x64 -alias dotnet_bootstrap
if errorlevel 1 goto fail
@ -35,6 +43,8 @@ if errorlevel 1 goto fail
echo Building basic dotnet tools using older dotnet SDK version
set DOTNET_HOME=%STAGE0_DIR%
set DOTNET_USER_HOME=%STAGE0_DIR%
set DOTNET_GLOBAL_HOME=%STAGE0_DIR%
call %~dp0dnvm2 upgrade
if errorlevel 1 goto fail
@ -93,4 +103,4 @@ goto end
echo Bootstrapping failed...
exit /B 1
:end
:end

View file

@ -25,6 +25,7 @@ if [ -z "$RID" ]; then
fi
OUTPUT_ROOT=$REPOROOT/artifacts/$RID
DNX_DIR=$OUTPUT_ROOT/dnx
STAGE0_DIR=$OUTPUT_ROOT/stage0
STAGE1_DIR=$OUTPUT_ROOT/stage1
STAGE2_DIR=$OUTPUT_ROOT/stage2
@ -32,54 +33,60 @@ STAGE2_DIR=$OUTPUT_ROOT/stage2
echo "Cleaning artifacts folder"
rm -rf $OUTPUT_ROOT
echo "Installing stage0"
# Use a sub-shell to ensure the DNVM gets cleaned up
mkdir -p $STAGE0_DIR
$DIR/install-stage0.sh $STAGE0_DIR $DIR/dnvm2.sh
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
STAGE0_PUBLISH=$REPOROOT/scripts/stage0/dotnet-publish
export PATH=$STAGE0_DIR/bin:$PATH
export DOTNET_CLR_HOSTS_PATH=$REPOROOT/ext/CLRHost/$RID
if ! type dnvm > /dev/null 2>&1; then
curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source ~/.dnx/dnvm/dnvm.sh
if ! type dnx > /dev/null 2>&1; then
echo "Installing and use-ing the latest CoreCLR x64 DNX ..."
mkdir -p $DNX_DIR
export DNX_HOME=$DNX_DIR
export DNX_USER_HOME=$DNX_DIR
export DNX_GLOBAL_HOME=$DNX_DIR
if ! type dnvm > /dev/null 2>&1; then
curl -o $DNX_DIR/dnvm.sh https://raw.githubusercontent.com/aspnet/Home/dev/dnvm.sh
source $DNX_DIR/dnvm.sh
fi
dnvm install latest -u -r coreclr
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
# Make sure we got a DNX
if ! type dnx > /dev/null 2>&1; then
echo "DNX is required to bootstrap stage1" 1>&2
exit 1
fi
fi
echo "Installing and use-ing the latest CoreCLR x64 DNX ..."
dnvm install latest -u -r coreclr -alias dotnet_bootstrap
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
dnvm use dotnet_bootstrap -r coreclr -arch x64
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
type -p dnx >/dev/null
if [ ! $? ]; then
echo "DNX is required to bootstrap stage1" 1>&2
exit 1
fi
echo "Running 'dnu restore' to restore packages for DNX-hosted projects"
echo "Running 'dnu restore' to restore packages"
dnu restore "$REPOROOT" --runtime osx.10.10-x64 --runtime ubuntu.14.04-x64 --runtime osx.10.11-x64
# symlink mcs to csc for bootstrapping (requires mono :()
mkdir -p $STAGE0_DIR
ln -s `(which mcs)` $STAGE0_DIR/csc
export PATH=$PATH:$STAGE0_DIR
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
# Clean up stage1
[ -d "$STAGE1_DIR" ] && rm -Rf "$STAGE1_DIR"
echo "Building basic dotnet tools using Stage 0 (DNX hosted)"
$STAGE0_PUBLISH --framework dnxcore50 --runtime $RID --output "$STAGE1_DIR" "$REPOROOT/src/Microsoft.DotNet.Cli"
echo "Building basic dotnet tools using Stage 0"
dotnet publish --framework dnxcore50 --runtime $RID --output "$STAGE1_DIR" "$REPOROOT/src/Microsoft.DotNet.Cli"
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
$STAGE0_PUBLISH --framework dnxcore50 --runtime $RID --output "$STAGE1_DIR" "$REPOROOT/src/Microsoft.DotNet.Tools.Compiler"
dotnet publish --framework dnxcore50 --runtime $RID --output "$STAGE1_DIR" "$REPOROOT/src/Microsoft.DotNet.Tools.Compiler"
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
$STAGE0_PUBLISH --framework dnxcore50 --runtime $RID --output "$STAGE1_DIR" "$REPOROOT/src/Microsoft.DotNet.Tools.Compiler.Csc"
dotnet publish --framework dnxcore50 --runtime $RID --output "$STAGE1_DIR" "$REPOROOT/src/Microsoft.DotNet.Tools.Compiler.Csc"
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
$STAGE0_PUBLISH --framework dnxcore50 --runtime $RID --output "$STAGE1_DIR" "$REPOROOT/src/Microsoft.DotNet.Tools.Publish"
dotnet publish --framework dnxcore50 --runtime $RID --output "$STAGE1_DIR" "$REPOROOT/src/Microsoft.DotNet.Tools.Publish"
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
$STAGE0_PUBLISH --framework dnxcore50 --runtime $RID --output "$STAGE1_DIR" "$REPOROOT/src/Microsoft.DotNet.Tools.Resgen"
dotnet publish --framework dnxcore50 --runtime $RID --output "$STAGE1_DIR" "$REPOROOT/src/Microsoft.DotNet.Tools.Resgen"
# Add stage1 to the path and use it to build stage2
export PATH=$STAGE1_DIR:$PATH
rm $STAGE0_DIR/csc
echo "Building stage2 dotnet using stage1 ..."
dotnet publish --framework dnxcore50 --runtime $RID --output "$STAGE2_DIR" "$REPOROOT/src/Microsoft.DotNet.Cli"

View file

@ -82,7 +82,7 @@ $FullVersion="$ProductVersion-$BuildVersion"
Set-Variable -Option Constant "CommandName" ([IO.Path]::GetFileNameWithoutExtension($ScriptPath))
Set-Variable -Option Constant "CommandFriendlyName" ".NET Version Manager"
Set-Variable -Option Constant "DefaultUserDirectoryName" ".dotnet"
Set-Variable -Option Constant "DefaultGlobalDirectoryName" "Microsoft DNX"
Set-Variable -Option Constant "DefaultGlobalDirectoryName" "dotnet"
Set-Variable -Option Constant "OldUserDirectoryNames" @(".kre", ".k")
Set-Variable -Option Constant "RuntimePackageName" "dotnet"
Set-Variable -Option Constant "DefaultFeed" "https://aspdist.blob.core.windows.net/assets/dnvm/"
@ -96,6 +96,7 @@ Set-Variable -Option Constant "DefaultArchitecture" "x64"
Set-Variable -Option Constant "DefaultRuntime" "coreclr"
Set-Variable -Option Constant "AliasExtension" ".txt"
Set-Variable -Option Constant "DefaultOperatingSystem" "win"
Set-Variable -Option Constant "InstallSubfolder" "sdks"
# These are intentionally using "%" syntax. The environment variables are expanded whenever the value is used.
Set-Variable -Option Constant "OldUserHomes" @("%USERPROFILE%\.kre", "%USERPROFILE%\.k")
@ -181,7 +182,7 @@ if($CmdPathFile) {
_WriteDebug "Using CMD PATH file: $CmdPathFile"
}
# Determine where runtimes can exist (RuntimeHomes)
# Determine where SDKs can exist (RuntimeHomes)
if(!$RuntimeHomes) {
# Set up a default value for the runtime home
$UnencodedHomes = "$env:USERPROFILE\$DefaultUserDirectoryName;$GlobalHome\$DefaultGlobalDirectoryName"
@ -204,7 +205,7 @@ if(!$GlobalHome) {
$UnencodedHomes = $UnencodedHomes.Split(";")
$RuntimeHomes = $UnencodedHomes | ForEach-Object { [Environment]::ExpandEnvironmentVariables($_) }
$RuntimeDirs = $RuntimeHomes | ForEach-Object { Join-Path $_ "runtimes" }
$RuntimeDirs = $RuntimeHomes | ForEach-Object { Join-Path $_ $InstallSubFolder }
# Determine the default installation directory (UserHome)
if(!$UserHome) {
@ -235,8 +236,8 @@ _WriteDebug "=== Running $CommandName ==="
_WriteDebug "Runtime Homes: $RuntimeHomes"
_WriteDebug "User Home: $UserHome"
$AliasesDir = Join-Path $UserHome "alias"
$RuntimesDir = Join-Path $UserHome "runtimes"
$GlobalRuntimesDir = Join-Path $GlobalHome "runtimes"
$RuntimesDir = Join-Path $UserHome $InstallSubFolder
$GlobalRuntimesDir = Join-Path $GlobalHome $InstallSubFolder
$Aliases = $null
### Helper Functions
@ -251,7 +252,7 @@ function Safe-Filecopy {
# Make sure the destination folder is created if it doesn't already exist.
if(!(Test-Path $DestinationFolder)) {
_WriteOut "Creating destination folder '$DestinationFolder' ... "
New-Item -Type Directory $Destination | Out-Null
}
@ -273,55 +274,34 @@ function Safe-Filecopy {
}
}
$OSRuntimeDefaults = @{
"win"="coreclr";
"linux"="coreclr";
"darwin"="coreclr";
}
$RuntimeBitnessDefaults = @{
"clr"="x86";
"coreclr"="x64";
}
function GetRuntimeInfo($Architecture, $Runtime, $OS, $Version) {
function GetRuntimeInfo($Architecture, $OS, $Version) {
$runtimeInfo = @{
"Architecture"="$Architecture";
"Runtime"="$Runtime";
"OS"="$OS";
"Version"="$Version";
}
if([String]::IsNullOrEmpty($runtimeInfo.OS)) {
if($runtimeInfo.Runtime -eq "mono"){
#If OS is empty and you are asking for mono, i.e `dnvm install latest -os mono` then we don't know what OS to pick. It could be Linux or Darwin.
#we could just arbitrarily pick one but it will probably be wrong as often as not.
#If Mono can run on Windows then this error doesn't make sense anymore.
throw "Unable to determine an operating system for a $($runtimeInfo.Runtime) runtime. You must specify which OS to use with the OS parameter."
}
$runtimeInfo.OS = $DefaultOperatingSystem
$runtimeInfo.OS = "win"
}
if($runtimeInfo.OS -eq "osx") {
$runtimeInfo.OS = "darwin"
# Normalization
if($runtimeInfo.OS -eq "darwin") {
$runtimeInfo.OS = "osx"
}
if([String]::IsNullOrEmpty($runtimeInfo.Runtime)) {
$runtimeInfo.Runtime = $OSRuntimeDefaults.Get_Item($runtimeInfo.OS)
if($runtimeInfo.OS -eq "windows") {
$runtimeInfo.OS = "win"
}
if([String]::IsNullOrEmpty($runtimeInfo.Architecture)) {
$runtimeInfo.Architecture = $RuntimeBitnessDefaults.Get_Item($RuntimeInfo.Runtime)
}
$runtimeInfo.Architecture = "x64"
}
$runtimeObject = New-Object PSObject -Property $runtimeInfo
$runtimeObject | Add-Member -MemberType ScriptProperty -Name RuntimeId -Value {
if($this.Runtime -eq "mono") {
"$RuntimePackageName-$($this.Runtime)".ToLowerInvariant()
} else {
"$RuntimePackageName-$($this.Runtime)-$($this.OS)-$($this.Architecture)".ToLowerInvariant()
}
"$RuntimePackageName-$($this.OS)-$($this.Architecture)".ToLowerInvariant()
}
$runtimeObject | Add-Member -MemberType ScriptProperty -Name RuntimeName -Value {
@ -409,19 +389,19 @@ function Get-RuntimeAliasOrRuntimeInfo(
$Version = Get-PackageVersion $BaseName
$OS = Get-PackageOS $BaseName
}
GetRuntimeInfo $Architecture $Runtime $OS $Version
GetRuntimeInfo $Architecture $OS $Version
}
filter List-Parts {
param($aliases, $items)
$location = ""
$location = ""
if ((Test-Path $_.FullName)) {
if ((Test-Path $_.FullName)) {
$location = $_.Parent.FullName
}
$active = IsOnPath $_.FullName
$active = IsOnPath $_.FullName
$fullAlias=""
$delim=""
@ -434,17 +414,12 @@ filter List-Parts {
}
$parts1 = $_.Name.Split('.', 2)
$parts2 = $parts1[0].Split('-', 4)
if($parts1[0] -eq "$RuntimePackageName-mono") {
$parts2 += "linux/osx"
$parts2 += "x86/x64"
}
$parts2 = $parts1[0].Split('-', 3)
$aliasUsed = ""
if($items) {
$aliasUsed = $items | ForEach-Object {
if($_.Architecture -eq $parts2[3] -and $_.Runtime -eq $parts2[1] -and $_.OperatingSystem -eq $parts2[2] -and $_.Version -eq $parts1[1]) {
if($_.Architecture -eq $parts2[2] -and $_.OperatingSystem -eq $parts2[1] -and $_.Version -eq $parts1[1]) {
return $true;
}
return $false;
@ -458,8 +433,8 @@ filter List-Parts {
return New-Object PSObject -Property @{
Active = $active
Version = $parts1[1]
OperatingSystem = $parts2[2]
Architecture = $parts2[3]
OperatingSystem = $parts2[1]
Architecture = $parts2[2]
Location = $location
Alias = $fullAlias
}
@ -498,7 +473,7 @@ function Write-Alias {
$aliasFilePath = Join-Path $AliasesDir "$Name.txt"
$action = if (Test-Path $aliasFilePath) { "Updating" } else { "Setting" }
if(!(Test-Path $AliasesDir)) {
_WriteDebug "Creating alias directory: $AliasesDir"
New-Item -Type Directory $AliasesDir | Out-Null
@ -583,7 +558,7 @@ function Find-Package {
} else {
$version = $runtimeInfo.Version
}
if($version) {
$urlPart = $index | ?{$_ -match "Filename: (?<url>.+?$RuntimeId.$version.zip)"} | %{$matches["url"]}
_WriteDebug "Found Package Path: $urlPart"
@ -591,7 +566,7 @@ function Find-Package {
_WriteDebug "Found $version at $downloadUrl"
@{ Version = $version; DownloadUrl = $downloadUrl }
} else {
throw "Thre are no runtimes matching the name $RuntimeId on channel $channel."
throw "There are no SDKs matching the name $RuntimeId on channel '$channel'."
}
}
@ -602,25 +577,18 @@ function Get-PackageVersion() {
return $runtimeFullName -replace '[^.]*.(.*)', '$1'
}
function Get-PackageRuntime() {
param(
[string] $runtimeFullName
)
return $runtimeFullName -replace "$RuntimePackageName-([^-]*).*", '$1'
}
function Get-PackageArch() {
param(
[string] $runtimeFullName
)
return $runtimeFullName -replace "$RuntimePackageName-[^-]*-[^-]*-([^.]*).*", '$1'
return $runtimeFullName -replace "$RuntimePackageName-[^-]*-([^.]*).*", '$1'
}
function Get-PackageOS() {
param(
[string] $runtimeFullName
)
$runtimeFullName -replace "$RuntimePackageName-[^-]*-([^-]*)-[^.]*.*", '$1'
$runtimeFullName -replace "$RuntimePackageName-([^-]*)-[^.]*.*", '$1'
}
function Download-Package() {
@ -633,11 +601,11 @@ function Download-Package() {
[string]$Feed,
[string]$Proxy
)
_WriteOut "Downloading $($runtimeInfo.RuntimeName) from $feed"
$wc = New-Object System.Net.WebClient
try {
Apply-Proxy $wc -Proxy:$Proxy
Apply-Proxy $wc -Proxy:$Proxy
_WriteDebug "Downloading $DownloadUrl ..."
Register-ObjectEvent $wc DownloadProgressChanged -SourceIdentifier WebClient.ProgressChanged -action {
@ -717,7 +685,7 @@ function Unpack-Package([string]$DownloadFile, [string]$UnpackFolder) {
function Get-RuntimePath($runtimeFullName) {
_WriteDebug "Resolving $runtimeFullName"
foreach($RuntimeHome in $RuntimeHomes) {
$runtimeBin = "$RuntimeHome\runtimes\$runtimeFullName"
$runtimeBin = "$RuntimeHome\$InstallSubfolder\$runtimeFullName"
_WriteDebug " Candidate $runtimeBin"
if (Test-Path $runtimeBin) {
_WriteDebug " Found in $runtimeBin"
@ -734,7 +702,7 @@ function Change-Path() {
[string[]] $removePaths
)
_WriteDebug "Updating value to prepend '$prependPath' and remove '$removePaths'"
$newPath = $prependPath
foreach($portion in $existingPaths.Split(';')) {
if(![string]::IsNullOrEmpty($portion)) {
@ -832,7 +800,7 @@ function dnvm-update-self {
_WriteOut "Updating $CommandName from $DNVMUpgradeUrl"
$wc = New-Object System.Net.WebClient
Apply-Proxy $wc -Proxy:$Proxy
$dnvmFile = Join-Path $PSScriptRoot "dnvm.ps1"
$tempDnvmFile = Join-Path $PSScriptRoot "temp"
$backupFilePath = Join-Path $PSSCriptRoot "dnvm.ps1.bak"
@ -891,7 +859,7 @@ function dnvm-help {
}
_WriteOut -NoNewLine " "
if($_.required -ne "true") {
_WriteOut -NoNewLine -ForegroundColor $ColorScheme.Help_Optional "["
}
@ -923,9 +891,9 @@ function dnvm-help {
if($cmdParam.Aliases.Length -gt 0) {
$name = $cmdParam.Aliases | Sort-Object | Select-Object -First 1
}
_WriteOut -NoNewLine " "
if($_.position -eq "Named") {
_WriteOut -NoNewLine -ForegroundColor $ColorScheme.Help_Switch "-$name".PadRight($OptionPadding)
} else {
@ -982,15 +950,15 @@ filter ColorActive {
<#
.SYNOPSIS
Displays the DNVM version.
Displays the DNVM version.
#>
function dnvm-version {
_WriteOut "$FullVersion"
_WriteOut "$FullVersion"
}
<#
.SYNOPSIS
Lists available runtimes
Lists available SDKs
.PARAMETER Detailed
Display more detailed information on each runtime
.PARAMETER PassThru
@ -1008,15 +976,15 @@ function dnvm-list {
$items = @()
$RuntimeHomes | ForEach-Object {
_WriteDebug "Scanning $_ for runtimes..."
if (Test-Path "$_\runtimes") {
$items += Get-ChildItem "$_\runtimes\$RuntimePackageName-*" | List-Parts $aliases $items
_WriteDebug "Scanning $_ for SDKs..."
if (Test-Path "$_\$InstallSubfolder") {
$items += Get-ChildItem "$_\$InstallSubfolder\$RuntimePackageName-*" | List-Parts $aliases $items
}
}
$aliases | Where-Object {$_.Orphan} | ForEach-Object {
$items += $_ | Select-Object @{label='Name';expression={$_.Name}}, @{label='FullName';expression={Join-Path $RuntimesDir $_.Name}} | List-Parts $aliases
}
$aliases | Where-Object {$_.Orphan} | ForEach-Object {
$items += $_ | Select-Object @{label='Name';expression={$_.Name}}, @{label='FullName';expression={Join-Path $RuntimesDir $_.Name}} | List-Parts $aliases
}
if($PassThru) {
$items
@ -1033,7 +1001,7 @@ function dnvm-list {
Format-Table -AutoSize -Property @{name="Active";expression={if($_.Active) { "*" } else { "" }};alignment="center"}, "Version", "Alias" | Out-String | ColorActive
}
} else {
_WriteOut "No runtimes installed. You can run `dnvm install latest` or `dnvm upgrade` to install a runtime."
_WriteOut "No SDKs installed. You can run 'dnvm install latest' or 'dnvm upgrade' to install a runtime."
}
}
}
@ -1047,8 +1015,6 @@ function dnvm-list {
The version to assign to the new alias
.PARAMETER Architecture
The architecture of the runtime to assign to this alias
.PARAMETER Runtime
The flavor of the runtime to assign to this alias
.PARAMETER OS
The operating system that the runtime targets
.PARAMETER Delete
@ -1060,7 +1026,7 @@ function dnvm-list {
(defaults to 'x86') and <Runtime> (defaults to 'clr').
Finally, if the '-d' switch is provided, the alias <Name> is deleted, if it exists.
NOTE: You cannot create an alias for a non-windows runtime. The intended use case for
an alias to help make it easier to switch the runtime, and you cannot use a non-windows
runtime on a windows machine.
@ -1080,12 +1046,7 @@ function dnvm-alias {
[ValidateSet("", "x86", "x64", "arm")]
[string]$Architecture = "",
[Alias("r")]
[ValidateSet("", "clr","coreclr", "mono")]
[Parameter(ParameterSetName="Write")]
[string]$Runtime = "",
[ValidateSet("win", "osx", "darwin", "linux")]
[ValidateSet("win", "osx", "linux")]
[Parameter(Mandatory=$false,ParameterSetName="Write")]
[string]$OS = "")
@ -1097,7 +1058,7 @@ function dnvm-alias {
}
if($Version) {
Write-Alias $Name $Version -Architecture $Architecture -Runtime $Runtime -OS:$OS
Write-Alias $Name $Version -Architecture $Architecture -OS:$OS
} elseif ($Delete) {
Delete-Alias $Name
} else {
@ -1105,19 +1066,6 @@ function dnvm-alias {
}
}
<#
.SYNOPSIS
[DEPRECATED] Removes an alias
.PARAMETER Name
The name of the alias to remove
#>
function dnvm-unalias {
param(
[Parameter(Mandatory=$true,Position=0)][string]$Name)
_WriteOut "This command has been deprecated. Use '$CommandName alias -d' instead"
dnvm-alias -Delete -Name $Name
}
<#
.SYNOPSIS
Installs the latest version of the runtime and reassigns the specified alias to point at it
@ -1125,8 +1073,6 @@ function dnvm-unalias {
The alias to upgrade (default: 'default')
.PARAMETER Architecture
The processor architecture of the runtime to install (default: x86)
.PARAMETER Runtime
The runtime flavor to install (default: clr)
.PARAMETER OS
The operating system that the runtime targets (default: win)
.PARAMETER Force
@ -1153,12 +1099,7 @@ function dnvm-upgrade {
[Parameter(Mandatory=$false)]
[string]$Architecture = "",
[Alias("r")]
[ValidateSet("", "clr", "coreclr")]
[Parameter(Mandatory=$false)]
[string]$Runtime = "",
[ValidateSet("", "win", "osx", "darwin", "linux")]
[ValidateSet("", "win", "osx", "linux")]
[Parameter(Mandatory=$false)]
[string]$OS = "",
@ -1177,7 +1118,7 @@ function dnvm-upgrade {
[Parameter(Mandatory=$false)]
[switch]$Unstable,
[Parameter(Mandatory=$false)]
[switch]$Global)
@ -1189,7 +1130,7 @@ function dnvm-upgrade {
return
}
dnvm-install "latest" -Alias:$Alias -Architecture:$Architecture -Runtime:$Runtime -OS:$OS -Force:$Force -Proxy:$Proxy -NoNative:$NoNative -Ngen:$Ngen -Unstable:$Unstable -Persistent:$true -Global:$Global
dnvm-install "latest" -Alias:$Alias -Architecture:$Architecture -OS:$OS -Force:$Force -Proxy:$Proxy -NoNative:$NoNative -Ngen:$Ngen -Unstable:$Unstable -Persistent:$true -Global:$Global
}
<#
@ -1201,8 +1142,6 @@ function dnvm-upgrade {
runtime or architecture flavor of the specified alias.
.PARAMETER Architecture
The processor architecture of the runtime to install (default: x86)
.PARAMETER Runtime
The runtime flavor to install (default: clr)
.PARAMETER OS
The operating system that the runtime targets (default: win)
.PARAMETER Alias
@ -1234,12 +1173,7 @@ function dnvm-install {
[Parameter(Mandatory=$false)]
[string]$Architecture = "",
[Alias("r")]
[ValidateSet("", "clr","coreclr","mono")]
[Parameter(Mandatory=$false)]
[string]$Runtime = "",
[ValidateSet("", "win", "osx", "darwin", "linux")]
[ValidateSet("", "win", "osx", "linux")]
[Parameter(Mandatory=$false)]
[string]$OS = "",
@ -1306,7 +1240,6 @@ function dnvm-install {
Write-Progress -Activity "Installing runtime" -Status "Parsing package file name" -Id 1
$runtimeFullName = [System.IO.Path]::GetFileNameWithoutExtension($VersionNuPkgOrAlias)
$Architecture = Get-PackageArch $runtimeFullName
$Runtime = Get-PackageRuntime $runtimeFullName
$OS = Get-PackageOS $runtimeFullName
$Version = Get-PackageVersion $runtimeFullName
} else {
@ -1317,15 +1250,11 @@ function dnvm-install {
if([String]::IsNullOrEmpty($Architecture)) {
$Architecture = Get-PackageArch $BaseName
}
if([String]::IsNullOrEmpty($Runtime)) {
$Runtime = Get-PackageRuntime $BaseName
}
if([String]::IsNullOrEmpty($Version)) {
$Version = Get-PackageVersion $BaseName
}
if([String]::IsNullOrEmpty($OS)) {
$OS = Get-PackageOS $BaseName
}
@ -1334,7 +1263,7 @@ function dnvm-install {
}
}
$runtimeInfo = GetRuntimeInfo $Architecture $Runtime $OS $Version
$runtimeInfo = GetRuntimeInfo $Architecture $OS $Version
if (!$IsNuPkg) {
$findPackageResult = Find-Package -runtimeInfo:$runtimeInfo -Feed:$selectedFeed -Channel:$activeChannel
@ -1350,7 +1279,6 @@ function dnvm-install {
_WriteDebug "Preparing to install runtime '$($runtimeInfo.RuntimeName)'"
_WriteDebug "Architecture: $($runtimeInfo.Architecture)"
_WriteDebug "Runtime: $($runtimeInfo.Runtime)"
_WriteDebug "Version: $($runtimeInfo.Version)"
_WriteDebug "OS: $($runtimeInfo.OS)"
@ -1380,18 +1308,16 @@ function dnvm-install {
if($installed -ne "") {
_WriteOut "'$($runtimeInfo.RuntimeName)' is already installed in $installed."
if($runtimeInfo.OS -eq "win") {
dnvm-use $runtimeInfo.Version -Architecture:$runtimeInfo.Architecture -Runtime:$runtimeInfo.Runtime -Persistent:$Persistent -OS:$runtimeInfo.OS
dnvm-use $runtimeInfo.Version -Architecture:$runtimeInfo.Architecture -Persistent:$Persistent -OS:$runtimeInfo.OS
}
}
else {
$Architecture = $runtimeInfo.Architecture
$Runtime = $runtimeInfo.Runtime
$OS = $runtimeInfo.OS
$TempFolder = Join-Path $installDir "temp"
$UnpackFolder = Join-Path $TempFolder $runtimeFullName
$DownloadFile = Join-Path $UnpackFolder "$runtimeFullName.nupkg"
$UnpackFolder = Join-Path $TempFolder $runtimeInfo.RuntimeName
$DownloadFile = Join-Path $UnpackFolder "$($runtimeInfo.RuntimeName).nupkg"
if(Test-Path $UnpackFolder) {
_WriteDebug "Cleaning temporary directory $UnpackFolder"
@ -1436,55 +1362,16 @@ function dnvm-install {
}
if($runtimeInfo.OS -eq "win") {
dnvm-use $runtimeInfo.Version -Architecture:$runtimeInfo.Architecture -Runtime:$runtimeInfo.Runtime -Persistent:$Persistent -OS:$runtimeInfo.OS
}
if ($runtimeInfo.Runtime -eq "clr") {
if (-not $NoNative) {
if ((Is-Elevated) -or $Ngen) {
$runtimeBin = Get-RuntimePath $runtimeInfo.RuntimeName
Write-Progress -Activity "Installing runtime" -Status "Generating runtime native images" -Id 1
Ngen-Library $runtimeBin $runtimeInfo.Architecture
}
else {
_WriteOut "Native image generation (ngen) is skipped. Include -Ngen switch to turn on native image generation to improve application startup time."
}
}
}
elseif ($runtimeInfo.Runtime -eq "coreclr") {
if ($NoNative -or $runtimeInfo.OS -ne "win") {
_WriteOut "Skipping native image compilation."
}
else {
_WriteOut "Compiling native images for $($runtimeInfo.RuntimeName) to improve startup performance..."
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') {
Start-Process $crossGenCommand -Wait -WindowStyle Hidden
}
else {
Start-Process $crossGenCommand -Wait -NoNewWindow
}
_WriteOut "Finished native image compilation."
}
}
else {
_WriteOut "Unexpected platform: $($runtimeInfo.Runtime). No optimization would be performed on the package installed."
dnvm-use $runtimeInfo.Version -Architecture:$runtimeInfo.Architecture -Persistent:$Persistent -OS:$runtimeInfo.OS
}
}
if($Alias) {
if($runtimeInfo.OS -eq "win") {
_WriteDebug "Aliasing installed runtime to '$Alias'"
dnvm-alias $Alias $runtimeInfo.Version -Architecture:$RuntimeInfo.Architecture -Runtime:$RuntimeInfo.Runtime -OS:$RuntimeInfo.OS
dnvm-alias $Alias $runtimeInfo.Version -Architecture:$RuntimeInfo.Architecture -OS:$RuntimeInfo.OS
} else {
_WriteOut "Unable to set an alias for a non-windows runtime. Installing non-windows runtimes on Windows are meant only for publishing, not running."
_WriteOut "Unable to set an alias for a non-windows runtime. Installing non-windows SDKs on Windows are meant only for publishing, not running."
}
}
@ -1499,8 +1386,6 @@ function dnvm-install {
The version or alias of the runtime to place on the PATH
.PARAMETER Architecture
The processor architecture of the runtime to place on the PATH (default: x86, or whatever the alias specifies in the case of use-ing an alias)
.PARAMETER Runtime
The runtime flavor of the runtime to place on the PATH (default: clr, or whatever the alias specifies in the case of use-ing an alias)
.PARAMETER OS
The operating system that the runtime targets (default: win)
.PARAMETER Persistent
@ -1516,11 +1401,6 @@ function dnvm-use {
[Parameter(Mandatory=$false)]
[string]$Architecture = "",
[Alias("r")]
[ValidateSet("", "clr", "coreclr")]
[Parameter(Mandatory=$false)]
[string]$Runtime = "",
[ValidateSet("", "win", "osx", "darwin", "linux")]
[Parameter(Mandatory=$false)]
[string]$OS = "",
@ -1530,19 +1410,13 @@ function dnvm-use {
[switch]$Persistent)
if ($versionOrAlias -eq "none") {
_WriteOut "Removing all runtimes from process PATH"
_WriteOut "Removing all SDKs from process PATH"
Set-Path (Change-Path $env:Path "" ($RuntimeDirs))
#if ($Persistent) {
# _WriteOut "Removing all runtimes from user PATH"
# $userPath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User)
# $userPath = Change-Path $userPath "" ($RuntimeDirs)
# [Environment]::SetEnvironmentVariable("Path", $userPath, [System.EnvironmentVariableTarget]::User)
#}
return;
}
$runtimeInfo = Get-RuntimeAliasOrRuntimeInfo -Version:$VersionOrAlias -Architecture:$Architecture -Runtime:$Runtime -OS:$OS
$runtimeInfo = Get-RuntimeAliasOrRuntimeInfo -Version:$VersionOrAlias -Architecture:$Architecture -OS:$OS
$runtimeFullName = $runtimeInfo.RuntimeName
$runtimeBin = Get-RuntimePath $runtimeFullName
_WriteDebug "Using: $runtimeFullName"
@ -1552,13 +1426,6 @@ function dnvm-use {
_WriteOut "Adding $runtimeBin to process PATH"
Set-Path (Change-Path $env:Path $runtimeBin ($RuntimeDirs))
#if ($Persistent) {
# _WriteOut "Adding $runtimeBin to user PATH"
# $userPath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User)
# $userPath = Change-Path $userPath $runtimeBin ($RuntimeDirs)
# [Environment]::SetEnvironmentVariable("Path", $userPath, [System.EnvironmentVariableTarget]::User)
#}
}
<#
@ -1579,15 +1446,10 @@ function dnvm-run {
[Parameter(Mandatory=$false)]
[string]$Architecture = "",
[Alias("r")]
[ValidateSet("", "clr", "coreclr")]
[Parameter(Mandatory=$false)]
[string]$Runtime = "",
[Parameter(Mandatory=$false, Position=1, ValueFromRemainingArguments=$true)]
[object[]]$DnxArguments)
$runtimeInfo = Get-RuntimeAliasOrRuntimeInfo -Version:$VersionOrAlias -Runtime:$Runtime -Architecture:$Architecture
$runtimeInfo = Get-RuntimeAliasOrRuntimeInfo -Version:$VersionOrAlias -Architecture:$Architecture
$runtimeBin = Get-RuntimePath $runtimeInfo.RuntimeName
if ($runtimeBin -eq $null) {
@ -1622,14 +1484,10 @@ function dnvm-exec {
[Parameter(Mandatory=$false)]
[string]$Architecture = "",
[Alias("r")]
[ValidateSet("", "clr", "coreclr")]
[Parameter(Mandatory=$false)]
[string]$Runtime = "",
[Parameter(Mandatory=$false, Position=2, ValueFromRemainingArguments=$true)]
[object[]]$Arguments)
$runtimeInfo = Get-RuntimeAliasOrRuntimeInfo -Version:$VersionOrAlias -Runtime:$Runtime -Architecture:$Architecture
$runtimeInfo = Get-RuntimeAliasOrRuntimeInfo -Version:$VersionOrAlias -Architecture:$Architecture
$runtimeBin = Get-RuntimePath $runtimeInfo.RuntimeName
if ($runtimeBin -eq $null) {
@ -1708,26 +1566,26 @@ function dnvm-setup {
function Check-Runtimes(){
$runtimesInstall = $false;
foreach($runtimeHomeDir in $RuntimeHomes) {
if (Test-Path "$runtimeHomeDir\runtimes") {
if(Test-Path "$runtimeHomeDir\runtimes\$RuntimePackageName-*"){
if (Test-Path "$runtimeHomeDir\$InstallSubfolder") {
if(Test-Path "$runtimeHomeDir\$InstallSubfolder\$RuntimePackageName-*"){
$runtimesInstall = $true;
break;
}
}
}
if (-not $runtimesInstall){
$title = "Getting started"
$message = "It looks like you don't have any runtimes installed. Do you want us to install a $RuntimeShortFriendlyName to get you started?"
$message = "It looks like you don't have any SDKs installed. Do you want us to install a $RuntimeShortFriendlyName to get you started?"
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", "Install the latest runtime for you"
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", "Do not install the latest runtime and continue"
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
$result = $host.ui.PromptForChoice($title, $message, $options, 0)
if($result -eq 0){
dnvm-upgrade
}

874
scripts/dnvm2.sh Normal file
View file

@ -0,0 +1,874 @@
# dnvm.sh
# Source this file from your .bash-profile or script to use
# "Constants"
_DNVM_BUILDNUMBER="{{BUILD_VERSION}}"
_DNVM_AUTHORS="{{AUTHORS}}"
_DNVM_RUNTIME_PACKAGE_NAME="dotnet"
_DNVM_RUNTIME_FRIENDLY_NAME=".NET CLI"
_DNVM_RUNTIME_SHORT_NAME="dotnet"
_DNVM_RUNTIME_FOLDER_NAME=".dotnet"
_DNVM_COMMAND_NAME="dnvm"
_DNVM_PACKAGE_MANAGER_NAME="dnu"
_DNVM_VERSION_MANAGER_NAME=".NET Version Manager"
_DNVM_DEFAULT_FEED="https://aspdist.blob.core.windows.net/assets/dnvm"
_DNVM_DEFAULT_CHANNEL="unstable"
_DNVM_DEFAULT_UNSTABLE_CHANNEL="dev"
_DNVM_UPDATE_LOCATION="https://raw.githubusercontent.com/aspnet/Home/dev/dnvm.sh"
_DNVM_INSTALL_SUBFOLDER="sdks"
if [ "$NO_COLOR" != "1" ]; then
# ANSI Colors
RCol='\e[0m' # Text Reset
# Regular Bold Underline High Intensity BoldHigh Intens Background High Intensity Backgrounds
Bla='\e[0;30m'; BBla='\e[1;30m'; UBla='\e[4;30m'; IBla='\e[0;90m'; BIBla='\e[1;90m'; On_Bla='\e[40m'; On_IBla='\e[0;100m';
Red='\e[0;31m'; BRed='\e[1;31m'; URed='\e[4;31m'; IRed='\e[0;91m'; BIRed='\e[1;91m'; On_Red='\e[41m'; On_IRed='\e[0;101m';
Gre='\e[0;32m'; BGre='\e[1;32m'; UGre='\e[4;32m'; IGre='\e[0;92m'; BIGre='\e[1;92m'; On_Gre='\e[42m'; On_IGre='\e[0;102m';
Yel='\e[0;33m'; BYel='\e[1;33m'; UYel='\e[4;33m'; IYel='\e[0;93m'; BIYel='\e[1;93m'; On_Yel='\e[43m'; On_IYel='\e[0;103m';
Blu='\e[0;34m'; BBlu='\e[1;34m'; UBlu='\e[4;34m'; IBlu='\e[0;94m'; BIBlu='\e[1;94m'; On_Blu='\e[44m'; On_IBlu='\e[0;104m';
Pur='\e[0;35m'; BPur='\e[1;35m'; UPur='\e[4;35m'; IPur='\e[0;95m'; BIPur='\e[1;95m'; On_Pur='\e[45m'; On_IPur='\e[0;105m';
Cya='\e[0;36m'; BCya='\e[1;36m'; UCya='\e[4;36m'; ICya='\e[0;96m'; BICya='\e[1;96m'; On_Cya='\e[46m'; On_ICya='\e[0;106m';
Whi='\e[0;37m'; BWhi='\e[1;37m'; UWhi='\e[4;37m'; IWhi='\e[0;97m'; BIWhi='\e[1;97m'; On_Whi='\e[47m'; On_IWhi='\e[0;107m';
fi
[[ "$_DNVM_BUILDNUMBER" = {{* ]] && _DNVM_BUILDNUMBER="HEAD"
__dnvm_has() {
type "$1" > /dev/null 2>&1
return $?
}
if __dnvm_has "unsetopt"; then
unsetopt nomatch 2>/dev/null
fi
if [ -z "$DOTNET_USER_HOME" ]; then
eval DOTNET_USER_HOME="~/$_DNVM_RUNTIME_FOLDER_NAME"
fi
if [ -z "$DOTNET_GLOBAL_HOME" ]; then
eval DOTNET_GLOBAL_HOME="/usr/local/lib/dotnet"
fi
if [ -z "$DOTNET_HOME" ]; then
# Set to the user home value
eval DOTNET_HOME="$DOTNET_USER_HOME:$DOTNET_GLOBAL_HOME"
elif [[ $DOTNET_HOME != *"$DOTNET_GLOBAL_HOME"* ]]; then
eval DOTNET_HOME="$DOTNET_HOME:$DOTNET_GLOBAL_HOME"
fi
_DNVM_USER_PACKAGES="$DOTNET_USER_HOME/$_DNVM_INSTALL_SUBFOLDER"
_DNVM_GLOBAL_PACKAGES="$DOTNET_GLOBAL_HOME/$_DNVM_INSTALL_SUBFOLDER"
_DNVM_ALIAS_DIR="$DOTNET_USER_HOME/alias"
_DNVM_DNVM_DIR="$DOTNET_USER_HOME/dnvm"
DNX_ACTIVE_FEED=""
DNX_ACTIVE_CHANNEL=""
__dnvm_current_os()
{
local uname=$(uname)
if [[ $uname == "Darwin" ]]; then
echo "osx"
else
echo "linux"
fi
}
__dnvm_find_latest() {
local arch=$1
local os=$2
if ! __dnvm_has "curl"; then
printf "%b\n" "${Red}$_DNVM_COMMAND_NAME needs curl to proceed. ${RCol}" >&2;
return 1
fi
#dnx-coreclr-linux-x64
local packageId="$_DNVM_RUNTIME_PACKAGE_NAME-$os-$arch"
local url="$DNX_ACTIVE_FEED/channels/$DNX_ACTIVE_CHANNEL/index"
local index="$(curl $url 2>/dev/null)"
local version="$(export IFS=; echo $index | sed -n 's/Latest: \(.*\)/\1/p')"
local fullPackageId="$packageId.$version"
local filename="$(export IFS=; echo $index | sed -n "s/Filename: \(.*$fullPackageId\)/\1/p")"
local downloadUrl="$DNX_ACTIVE_FEED/$filename"
echo $version $downloadUrl
}
__dnvm_find_package() {
local arch=$1
local os=$2
local version=$3
#dnx-coreclr-linux-x64
local packageId="$_DNVM_RUNTIME_PACKAGE_NAME-$os-$arch"
local url="$DNX_ACTIVE_FEED/channels/$_DNVM_DEFAULT_CHANNEL/index"
local index="$(curl $url 2>/dev/null)"
local filename="$(export IFS=; echo $index | sed -n "s/Filename: \(.*$packageId.$version\)/\1/p")"
local packageUrl="$DNX_ACTIVE_FEED/$filename"
echo $packageUrl
}
__dnvm_strip_path() {
echo "$1" | sed -e "s#$_DNVM_USER_PACKAGES/[^/]*$2[^:]*:##g" -e "s#:$_DNVM_USER_PACKAGES/[^/]*$2[^:]*##g" -e "s#$_DNVM_USER_PACKAGES/[^/]*$2[^:]*##g" | sed -e "s#$_DNVM_GLOBAL_PACKAGES/[^/]*$2[^:]*:##g" -e "s#:$_DNVM_GLOBAL_PACKAGES/[^/]*$2[^:]*##g" -e "s#$_DNVM_GLOBAL_PACKAGES/[^/]*$2[^:]*##g"
}
__dnvm_prepend_path() {
if [ -z "$1" ]; then
echo "$2"
else
echo "$2:$1"
fi
}
__dnvm_package_version() {
local runtimeFullName="$1"
echo "$runtimeFullName" | sed "s/[^.]*.\(.*\)/\1/"
}
__dnvm_package_name() {
local runtimeFullName="$1"
echo "$runtimeFullName" | sed "s/\([^.]*\).*/\1/"
}
__dnvm_package_arch() {
local runtimeFullName="$1"
echo "$runtimeFullName" | sed "s/$_DNVM_RUNTIME_PACKAGE_NAME-[^-.]*-\([^-.]*\)\..*/\1/"
}
__dnvm_package_os() {
local runtimeFullName="$1"
echo "$runtimeFullName" | sed "s/$_DNVM_RUNTIME_PACKAGE_NAME-\([^.-]*\).*/\1/"
}
__dnvm_update_self() {
local dnvmFileLocation="$_DNVM_DNVM_DIR/dnvm.sh"
if [ ! -e $dnvmFileLocation ]; then
local formattedDnvmFileLocation=`(echo $dnvmFileLocation | sed s=$HOME=~=g)`
local formattedDnvmHome=`(echo $_DNVM_DNVM_DIR | sed s=$HOME=~=g)`
local bashSourceLocation=${BASH_SOURCE}
local scriptLocation=$bashSourceLocation
if [ -z "${bashSourceLocation}" ]; then
local scriptLocation=${(%):-%x}
fi
printf "%b\n" "${Red}$formattedDnvmFileLocation doesn't exist. This command assumes you have installed dnvm in the usual location and are trying to update it. If you want to use update-self then dnvm.sh should be sourced from $formattedDnvmHome. dnvm is currently sourced from $scriptLocation ${RCol}"
return 1
fi
printf "%b\n" "${Cya}Downloading dnvm.sh from $_DNVM_UPDATE_LOCATION ${RCol}"
local httpResult=$(curl -L -D - "$_DNVM_UPDATE_LOCATION" -o "$dnvmFileLocation" -# | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/")
[[ $httpResult == "404" ]] &&printf "%b\n" "${Red}404. Unable to download DNVM from $_DNVM_UPDATE_LOCATION ${RCol}" && return 1
[[ $httpResult != "302" && $httpResult != "200" ]] && echo "${Red}HTTP Error $httpResult fetching DNVM from $_DNVM_UPDATE_LOCATION ${RCol}" && return 1
source "$dnvmFileLocation"
}
__dnvm_promptSudo() {
local acceptSudo="$1"
local answer=
if [ "$acceptSudo" == "0" ]; then
echo "In order to install dnx globally, dnvm will have to temporarily run as root."
read -p "You may be prompted for your password via 'sudo' during this process. Is this Ok? (y/N) " answer
else
answer="y"
fi
if echo $answer | grep -iq "^y" ; then
return 1
else
return 0
fi
}
__dnvm_download() {
local runtimeFullName="$1"
local downloadUrl="$2"
local runtimeFolder="$3"
local acceptSudo="$4"
#todo: This will need to change to be whatever the filename in the index is.
local runtimeFile="$runtimeFolder/$runtimeFullName.tar.gz"
if [ -e "$runtimeFolder" ]; then
printf "%b\n" "${Gre}$runtimeFullName already installed. ${RCol}"
return 0
fi
if ! __dnvm_has "curl"; then
printf "%b\n" "${Red}$_DNVM_COMMAND_NAME needs curl to proceed. ${RCol}" >&2;
return 1
fi
local useSudo=
mkdir -p "$runtimeFolder" > /dev/null 2>&1
if [ ! -d $runtimeFolder ]; then
if ! __dnvm_promptSudo $acceptSudo ; then
useSudo=sudo
sudo mkdir -p "$runtimeFolder" > /dev/null 2>&1 || return 1
else
return 1
fi
fi
echo "Downloading $runtimeFullName from $DNX_ACTIVE_FEED"
echo "Download: $downloadUrl to $runtimeFile"
local httpResult=$($useSudo curl -L -D - "$downloadUrl" -o "$runtimeFile" -# | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/")
if [[ $httpResult == "404" ]]; then
printf "%b\n" "${Red}$runtimeFullName was not found in repository $DNX_ACTIVE_FEED ${RCol}"
printf "%b\n" "${Cya}This is most likely caused by the feed not having the version that you typed. Check that you typed the right version and try again. Other possible causes are the feed doesn't have a $_DNVM_RUNTIME_SHORT_NAME of the right name format or some other error caused a 404 on the server.${RCol}"
return 1
fi
[[ $httpResult != "302" && $httpResult != "200" ]] && echo "${Red}HTTP Error $httpResult fetching $runtimeFullName from $DNX_ACTIVE_FEED ${RCol}" && return 1
__dnvm_unpack $runtimeFile $runtimeFolder $useSudo
return $?
}
__dnvm_unpack() {
local runtimeFile="$1"
local runtimeFolder="$2"
local useSudo=$3
echo "Installing to $runtimeFolder"
if ! __dnvm_has "unzip"; then
echo "$_DNVM_COMMAND_NAME needs unzip to proceed." >&2;
return 1
fi
$useSudo tar -xzf $runtimeFile -C $runtimeFolder > /dev/null 2>&1
}
__dnvm_requested_version_or_alias() {
local versionOrAlias="$1"
local arch="$2"
local os="$3"
local runtimeBin=$(__dnvm_locate_runtime_bin_from_full_name "$versionOrAlias")
# If the name specified is an existing package, just use it as is
if [ -n "$runtimeBin" ]; then
echo "$versionOrAlias"
else
if [ -e "$_DNVM_ALIAS_DIR/$versionOrAlias.alias" ]; then
local runtimeFullName=$(cat "$_DNVM_ALIAS_DIR/$versionOrAlias.alias")
if [[ ! -n "$arch" ]]; then
echo "$runtimeFullName"
return
fi
local pkgVersion=$(__dnvm_package_version "$runtimeFullName")
fi
if [[ ! -n "$pkgVersion" ]]; then
local pkgVersion=$versionOrAlias
fi
local pkgArchitecture="x64"
local pkgSystem=$os
if [ "$arch" != "" ]; then
local pkgArchitecture="$arch"
fi
if [ "$os" == "" ]; then
local pkgSystem=$(__dnvm_current_os)
fi
echo "$_DNVM_RUNTIME_PACKAGE_NAME-$pkgSystem-$pkgArchitecture.$pkgVersion"
fi
}
# This will be more relevant if we support global installs
__dnvm_locate_runtime_bin_from_full_name() {
local runtimeFullName=$1
for v in `echo $DOTNET_HOME | tr ":" "\n"`; do
if [ -e "$v/$_DNVM_INSTALL_SUBFOLDER/$runtimeFullName" ]; then
echo "$v/$_DNVM_INSTALL_SUBFOLDER/$runtimeFullName" && return
fi
done
}
__echo_art() {
printf "%b" "${Cya}"
echo " ___ _ ___ ____ ___"
echo " / _ \/ |/ / | / / |/ /"
echo " / // / /| |/ / /|_/ / "
echo " /____/_/|_/ |___/_/ /_/ "
printf "%b" "${RCol}"
}
__dnvm_description() {
__echo_art
echo ""
echo "$_DNVM_VERSION_MANAGER_NAME - Version 1.0.0-$_DNVM_BUILDNUMBER"
[[ "$_DNVM_AUTHORS" != {{* ]] && echo "By $_DNVM_AUTHORS"
echo ""
echo "DNVM can be used to download versions of the $_DNVM_RUNTIME_FRIENDLY_NAME and manage which version you are using."
echo "You can control the URL of the stable and unstable channel by setting the DOTNET_FEED and DNX_UNSTABLE_FEED variables."
echo ""
printf "%b\n" "${Yel}Current feed settings:${RCol}"
printf "%b\n" "${Cya}Feed:${Yel} $_DNVM_DEFAULT_FEED"
printf "%b\n" "${Cya}Default Channel:${Yel} $_DNVM_DEFAULT_CHANNEL"
printf "%b\n" "${Cya}Unstable Channel:${Yel} $_DNVM_DEFAULT_UNSTABLE_CHANNEL"
local dnxStableOverride="<none>"
[[ -n $DOTNET_FEED ]] && dnxStableOverride="$DOTNET_FEED"
printf "%b\n" "${Cya}Current Override Feed:${Yel} $dnxStableOverride"
local dnxUnstableOverride="<none>"
[[ -n $DNX_UNSTABLE_FEED ]] && dnxUnstableOverride="$DNX_UNSTABLE_FEED"
#printf "%b\n" "${Cya}Current Unstable Override:${Yel} $dnxUnstableOverride${RCol}"
echo ""
}
__dnvm_version() {
echo "1.0.0-$_DNVM_BUILDNUMBER"
}
__dnvm_help() {
__dnvm_description
printf "%b\n" "${Cya}USAGE:${Yel} $_DNVM_COMMAND_NAME <command> [options] ${RCol}"
echo ""
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME upgrade [-f|-force] [-u|-unstable] [-g|-global] [-y]${RCol}"
echo " install latest $_DNVM_RUNTIME_SHORT_NAME from feed"
echo " adds $_DNVM_RUNTIME_SHORT_NAME bin to path of current command line"
echo " set installed version as default"
echo " -f|forces force upgrade. Overwrite existing version of $_DNVM_RUNTIME_SHORT_NAME if already installed"
echo " -u|unstable use unstable feed. Installs the $_DNVM_RUNTIME_SHORT_NAME from the unstable feed"
echo " -g|global Installs the latest $_DNVM_RUNTIME_SHORT_NAME in the configured global $_DNVM_RUNTIME_SHORT_NAME file location (default: /usr/local/lib/dnx current: $DOTNET_GLOBAL_HOME)"
echo " -y Assume Yes to all queries and do not prompt"
echo ""
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME install <semver>|<alias>|<nupkg>|latest [-OS <OS>] [-a|-alias <alias>] [-p|-persistent] [-f|-force] [-u|-unstable] [-g|-global] [-y]${RCol}"
echo " <semver>|<alias> install requested $_DNVM_RUNTIME_SHORT_NAME from feed"
echo " <nupkg> install requested $_DNVM_RUNTIME_SHORT_NAME from local package on filesystem"
echo " latest install latest version of $_DNVM_RUNTIME_SHORT_NAME from feed"
echo " -OS the operating system that the runtime targets (default:$(__dnvm_current_os)"
echo " -a|-alias <alias> set alias <alias> for requested $_DNVM_RUNTIME_SHORT_NAME on install"
echo " -p|-persistent set installed version as default"
echo " -f|force force install. Overwrite existing version of $_DNVM_RUNTIME_SHORT_NAME if already installed"
echo " -u|unstable use unstable feed. Installs the $_DNVM_RUNTIME_SHORT_NAME from the unstable feed"
echo " -g|global Installs to the configured global $_DNVM_RUNTIME_SHORT_NAME file location (default: /usr/local/lib/dnx current: $DOTNET_GLOBAL_HOME)"
echo " -y Assume Yes to all queries and do not prompt"
echo ""
echo " adds $_DNVM_RUNTIME_SHORT_NAME bin to path of current command line"
echo ""
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME use <semver>|<alias>|<package>|none [-p|-persistent] [-a|-arch <architecture>] ${RCol}"
echo " <semver>|<alias>|<package> add $_DNVM_RUNTIME_SHORT_NAME bin to path of current command line "
echo " none remove $_DNVM_RUNTIME_SHORT_NAME bin from path of current command line"
echo " -p|-persistent set selected version as default"
echo " -a|-arch architecture to use (x64)"
echo ""
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME run <semver>|<alias> <args...> ${RCol}"
echo " <semver>|<alias> the version or alias to run"
echo " <args...> arguments to be passed to $_DNVM_RUNTIME_SHORT_NAME"
echo ""
echo " runs the $_DNVM_RUNTIME_SHORT_NAME command from the specified version of the runtime without affecting the current PATH"
echo ""
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME exec <semver>|<alias> <command> <args...> ${RCol}"
echo " <semver>|<alias> the version or alias to execute in"
echo " <command> the command to run"
echo " <args...> arguments to be passed to the command"
echo ""
echo " runs the specified command in the context of the specified version of the runtime without affecting the current PATH"
echo " example: $_DNVM_COMMAND_NAME exec 1.0.0-beta4 $_DNVM_PACKAGE_MANAGER_NAME build"
echo ""
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME list [-detailed]${RCol}"
echo " -detailed display more detailed information on each runtime"
echo ""
echo " list $_DNVM_RUNTIME_SHORT_NAME versions installed "
echo ""
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME alias ${RCol}"
echo " list $_DNVM_RUNTIME_SHORT_NAME aliases which have been defined"
echo ""
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME alias <alias> ${RCol}"
echo " display value of the specified alias"
echo ""
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME alias <alias> <semver>|<alias>|<package> ${RCol}"
echo " <alias> the name of the alias to set"
echo " <semver>|<alias>|<package> the $_DNVM_RUNTIME_SHORT_NAME version to set the alias to. Alternatively use the version of the specified alias"
echo ""
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME unalias <alias> ${RCol}"
echo " remove the specified alias"
echo ""
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME [help|-h|-help|--help] ${RCol}"
echo " displays this help text."
echo ""
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME [version|-v|-version|--version] ${RCol}"
echo " print the dnvm version."
echo ""
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME update-self ${RCol}"
echo " updates dnvm itself."
}
dnvm()
{
if [ $# -lt 1 ]; then
__dnvm_description
printf "%b\n" "Use ${Yel}$_DNVM_COMMAND_NAME [help|-h|-help|--help] ${RCol} to display help text."
echo ""
return
fi
case $1 in
"help"|"-h"|"-help"|"--help" )
__dnvm_help
;;
"version"|"-v"|"-version"|"--version" )
__dnvm_version
;;
"update-self" )
__dnvm_update_self
;;
"upgrade" )
shift
$_DNVM_COMMAND_NAME install latest -p $@
;;
"install" )
[ $# -lt 2 ] && __dnvm_help && return
shift
local persistent=
local versionOrAlias=
local alias=
local force=
local unstable=
local os=
local arch=
local global=0
local acceptSudo=0
while [ $# -ne 0 ]
do
if [[ $1 == "-p" || $1 == "-persistent" ]]; then
local persistent="-p"
elif [[ $1 == "-a" || $1 == "-alias" ]]; then
local alias=$2
shift
elif [[ $1 == "-f" || $1 == "-force" ]]; then
local force="-f"
elif [[ $1 == "-u" || $1 == "-unstable" ]]; then
local unstable="-u"
elif [[ $1 == "-OS" ]]; then
local os=$2
shift
elif [[ $1 == "-y" ]]; then
local acceptSudo=1
elif [[ $1 == "-arch" ]]; then
local arch=$2
shift
if [[ $arch != "x86" && $arch != "x64" ]]; then
printf "%b\n" "${Red}Architecture must be x86 or x64.${RCol}"
return 1
fi
elif [[ $1 == "-g" || $1 == "-global" ]]; then
local global=1
elif [[ -n $1 ]]; then
[[ -n $versionOrAlias ]] && echo "Invalid option $1" && __dnvm_help && return 1
local versionOrAlias=$1
fi
shift
done
if [[ $arch == "x86" ]]; then
printf "%b\n" "${Red}$_DNVM_RUNTIME_FRIENDLY_NAME doesn't currently have a 32 bit build. You must use x64.${RCol}"
return 1
fi
#This will be temporary whilst a more first class channels feature is added. There needs to be 3 values.
if [ -z $unstable ]; then
DNX_ACTIVE_CHANNEL="$_DNVM_DEFAULT_CHANNEL"
else
DNX_ACTIVE_CHANNEL="$_DNVM_DEFAULT_UNSTABLE_CHANNEL"
fi
echo "Using Channel: $DNX_ACTIVE_CHANNEL"
DNX_ACTIVE_FEED="$DOTNET_FEED"
if [ -z "$DNX_ACTIVE_FEED" ]; then
DNX_ACTIVE_FEED="$_DNVM_DEFAULT_FEED"
else
printf "%b\n" "${Yel}Default feed ($_DNVM_DEFAULT_FEED) is being overridden by the value of the DOTNET_FEED variable ($DOTNET_FEED). ${RCol}"
fi
if [[ -z $os ]]; then
os=$(__dnvm_current_os)
fi
if [[ $os == "darwin" ]]; then
os="osx"
fi
if [[ -z $arch ]]; then
arch="x64"
fi
local runtimeDir=$_DNVM_USER_PACKAGES
if [ $global == 1 ]; then
runtimeDir=$_DNVM_GLOBAL_PACKAGES
fi
if [[ "$versionOrAlias" != *.nupkg ]]; then
if [[ "$versionOrAlias" == "latest" ]]; then
echo "Determining latest version"
read versionOrAlias downloadUrl < <(__dnvm_find_latest "$arch" "$os")
echo "DownoadURL: $downloadUrl"
[[ $? == 1 ]] && echo "Error: Could not find latest version from feed $DNX_ACTIVE_FEED" && return 1
printf "%b\n" "Latest version is ${Cya}$versionOrAlias located at $downloadUrl${RCol}"
else
local runtimeFullName=$(__dnvm_requested_version_or_alias "$versionOrAlias" "$arch" "$os")
local runtimeVersion=$(__dnvm_package_version "$runtimeFullName")
local versionOrAlias=$runtimeVersion
local downloadUrl=$(__dnvm_find_package "$arch" "$os" "$runtimeVersion")
echo "DownloadURL: $downloadUrl"
[[ $? == 1 ]] && echo "Error: Could not find version $runtimeVersion in feed $DNX_ACTIVE_FEED" && return 1
fi
local runtimeFullName=$(__dnvm_requested_version_or_alias "$versionOrAlias" "$arch" "$os")
local runtimeFolder="$runtimeDir/$runtimeFullName"
#check all runtime homes for the runtime being installed.
#we can force install a DNX if it exists in the user or global folder, but not anywhere else.
#The installed dnx could be global, so if we are forcing it here we will remove it since we have the
#global path handy.
local exist=0
for folder in `echo $DOTNET_HOME | tr ":" "\n"`; do
if [ -e "$folder/$_DNVM_INSTALL_SUBFOLDER/$runtimeFullName" ]; then
local useSudo=
if [[ ("$folder" == "$DOTNET_USER_HOME" || "$folder" == "$DOTNET_GLOBAL_HOME") && -n "$force" ]]; then
if [[ "$folder" == "$DOTNET_GLOBAL_HOME" ]]; then
useSudo=sudo
fi
printf "%b\n" "${Yel}Forcing download by deleting $folder/$_DNVM_INSTALL_SUBFOLDER/$runtimeFullName directory ${RCol}"
$useSudo rm -rf "$folder/$_DNVM_INSTALL_SUBFOLDER/$runtimeFullName"
continue
fi
echo "$runtimeFullName already installed in $folder $DNVM_USER_HOME"
exist=1
fi
done
if [[ $exist != 1 ]]; then
__dnvm_download "$runtimeFullName" "$downloadUrl" "$runtimeFolder" "$acceptSudo"
fi
[[ $? == 1 ]] && return 1
if [[ "$os" == $(__dnvm_current_os) ]]; then
$_DNVM_COMMAND_NAME use "$versionOrAlias" "$persistent" "-arch" "$arch"
[[ -n $alias ]] && $_DNVM_COMMAND_NAME alias "$alias" "$versionOrAlias"
fi
else
local runtimeFullName=$(basename $versionOrAlias | sed "s/\(.*\)\.nupkg/\1/")
local runtimeVersion=$(__dnvm_package_version "$runtimeFullName")
local runtimeFolder="$runtimeDir/$runtimeFullName"
local runtimeFile="$runtimeFolder/$runtimeFullName.nupkg"
local runtimeClr=$(__dnvm_package_runtime "$runtimeFullName")
if [ -n "$force" ]; then
printf "%b\n" "${Yel}Forcing download by deleting $runtimeFolder directory ${RCol}"
rm -rf "$runtimeFolder"
fi
if [ -e "$runtimeFolder" ]; then
echo "$runtimeFullName already installed"
else
local useSudo=
mkdir -p "$runtimeFolder" > /dev/null 2>&1
if [ ! -d $runtimeFolder ]; then
if ! __dnvm_promptSudo $acceptSudo ; then
useSudo=sudo
sudo mkdir -p "$runtimeFolder" > /dev/null 2>&1 || return 1
else
return 1
fi
fi
cp -a "$versionOrAlias" "$runtimeFile"
__dnvm_unpack "$runtimeFile" "$runtimeFolder" $useSudo
[[ $? == 1 ]] && return 1
fi
$_DNVM_COMMAND_NAME use "$runtimeVersion" "$persistent"
[[ -n $alias ]] && $_DNVM_COMMAND_NAME alias "$alias" "$runtimeVersion"
fi
;;
"use"|"run"|"exec" )
[[ $1 == "use" && $# -lt 2 ]] && __dnvm_help && return
local cmd=$1
local persistent=
local arch=
local versionOrAlias=
shift
if [ $cmd == "use" ]; then
while [ $# -ne 0 ]
do
if [[ $1 == "-p" || $1 == "-persistent" ]]; then
local persistent="true"
elif [[ $1 == "-a" || $1 == "-arch" ]]; then
local arch=$2
shift
elif [[ $1 == -* ]]; then
echo "Invalid option $1" && __dnvm_help && return 1
elif [[ -n $1 ]]; then
[[ -n $versionOrAlias ]] && echo "Invalid option $1" && __dnvm_help && return 1
local versionOrAlias=$1
fi
shift
done
else
while [ $# -ne 0 ]
do
if [[ $1 == "-a" || $1 == "-arch" ]]; then
local arch=$2
shift
elif [[ -n $1 ]]; then
[[ -n $versionOrAlias ]] && break
local versionOrAlias=$1
fi
shift
done
fi
if [[ $cmd == "use" && $versionOrAlias == "none" ]]; then
echo "Removing $_DNVM_RUNTIME_SHORT_NAME from process PATH"
# Strip other version from PATH
PATH=$(__dnvm_strip_path "$PATH")
if [[ -n $persistent && -e "$_DNVM_ALIAS_DIR/default.alias" ]]; then
echo "Setting default $_DNVM_RUNTIME_SHORT_NAME to none"
rm "$_DNVM_ALIAS_DIR/default.alias"
fi
return 0
fi
local runtimeFullName=$(__dnvm_requested_version_or_alias "$versionOrAlias" "$arch" "$(__dnvm_current_os)")
local runtimeBin=$(__dnvm_locate_runtime_bin_from_full_name "$runtimeFullName")
if [[ -z $runtimeBin ]]; then
echo "Cannot find $runtimeFullName, do you need to run '$_DNVM_COMMAND_NAME install $versionOrAlias'?"
return 1
fi
case $cmd in
"run")
local hostpath="$runtimeBin/dotnet"
if [[ -e $hostpath ]]; then
$hostpath $@
return $?
else
echo "Cannot find $_DNVM_RUNTIME_SHORT_NAME in $runtimeBin. It may have been corrupted. Use '$_DNVM_COMMAND_NAME install $versionOrAlias -f' to attempt to reinstall it"
fi
;;
"exec")
(
PATH=$(__dnvm_strip_path "$PATH")
PATH=$(__dnvm_prepend_path "$PATH" "$runtimeBin")
$@
)
return $?
;;
"use")
echo "Adding" $runtimeBin "to process PATH"
PATH=$(__dnvm_strip_path "$PATH")
PATH=$(__dnvm_prepend_path "$PATH" "$runtimeBin")
if [[ -n $persistent ]]; then
local runtimeVersion=$(__dnvm_package_version "$runtimeFullName")
$_DNVM_COMMAND_NAME alias default "$runtimeVersion"
fi
;;
esac
;;
"alias" )
[[ $# -gt 7 ]] && __dnvm_help && return
[[ ! -e "$_DNVM_ALIAS_DIR/" ]] && mkdir "$_DNVM_ALIAS_DIR/" > /dev/null
if [[ $# == 1 ]]; then
echo ""
local format="%-25s %s\n"
printf "$format" "Alias" "Name"
printf "$format" "-----" "----"
if [ -d "$_DNVM_ALIAS_DIR" ]; then
for __dnvm_file in $(find "$_DNVM_ALIAS_DIR" -name *.alias); do
local alias="$(basename $__dnvm_file | sed 's/\.alias//')"
local name="$(cat $__dnvm_file)"
printf "$format" "$alias" "$name"
done
fi
echo ""
return
fi
shift
local name="$1"
if [[ $# == 1 ]]; then
[[ ! -e "$_DNVM_ALIAS_DIR/$name.alias" ]] && echo "There is no alias called '$name'" && return 1
cat "$_DNVM_ALIAS_DIR/$name.alias"
echo ""
return
fi
shift
local versionOrAlias="$1"
shift
while [ $# -ne 0 ]
do
if [[ $1 == "-a" || $1 == "-arch" ]]; then
local arch=$2
shift
elif [[ $1 == "-OS" ]]; then
local os=$2
shift
fi
shift
done
local runtimeFullName=$(__dnvm_requested_version_or_alias "$versionOrAlias" "$arch" "$os")
([[ ! -d "$_DNVM_USER_PACKAGES/$runtimeFullName" ]] && [[ ! -d "$_DNVM_GLOBAL_PACKAGES/$runtimeFullName" ]]) && echo "$runtimeFullName is not an installed $_DNVM_RUNTIME_SHORT_NAME version" && return 1
local action="Setting"
[[ -e "$_DNVM_ALIAS_DIR/$name.alias" ]] && action="Updating"
echo "$action alias '$name' to '$runtimeFullName'"
echo "$runtimeFullName" >| "$_DNVM_ALIAS_DIR/$name.alias"
;;
"unalias" )
[[ $# -ne 2 ]] && __dnvm_help && return
local name=$2
local aliasPath="$_DNVM_ALIAS_DIR/$name.alias"
[[ ! -e "$aliasPath" ]] && echo "Cannot remove alias, '$name' is not a valid alias name" && return 1
echo "Removing alias $name"
rm "$aliasPath" >> /dev/null 2>&1
;;
"list" )
[[ $# -gt 2 ]] && __dnvm_help && return
[[ ! -d $_DNVM_USER_PACKAGES ]] && echo "$_DNVM_RUNTIME_FRIENDLY_NAME is not installed." && return 1
local searchGlob="$_DNVM_RUNTIME_PACKAGE_NAME-*"
local runtimes=""
for location in `echo $DOTNET_HOME | tr ":" "\n"`; do
location+="/$_DNVM_INSTALL_SUBFOLDER"
if [ -d "$location" ]; then
local oruntimes="$(find $location -name "$searchGlob" \( -type d -or -type l \) -prune -exec basename {} \;)"
for v in `echo $oruntimes | tr "\n" " "`; do
runtimes+="$v:$location"$'\n'
done
fi
done
[[ -z $runtimes ]] && echo 'No runtimes installed. You can run `dnvm install latest` or `dnvm upgrade` to install a runtime.' && return
echo ""
# Separate empty array declaration from initialization
# to avoid potential ZSH error: local:217: maximum nested function level reached
local arr
arr=()
# Z shell array-index starts at one.
local i=1
local format="%-20s %s\n"
if [ -d "$_DNVM_ALIAS_DIR" ]; then
for __dnvm_file in $(find "$_DNVM_ALIAS_DIR" -name *.alias); do
if [ ! -d "$_DNVM_USER_PACKAGES/$(cat $__dnvm_file)" ] && [ ! -d "$_DNVM_GLOBAL_PACKAGES/$(cat $__dnvm_file)" ]; then
arr[$i]="$(basename $__dnvm_file | sed 's/\.alias//')/missing/$(cat $__dnvm_file)"
runtimes="$runtimes $(cat $__dnvm_file)"
else
arr[$i]="$(basename $__dnvm_file | sed 's/\.alias//')/$(cat $__dnvm_file)"
fi
let i+=1
done
fi
if [[ $2 == "-detailed" ]]; then
# Calculate widest alias
local widestAlias=5
for f in `echo $runtimes`; do
local pkgName=$(__dnvm_package_name "$f")
local pkgVersion=$(__dnvm_package_version "$f")
local alias=""
local delim=""
for i in "${arr[@]}"; do
if [[ ${i##*/} == "$pkgName.$pkgVersion" ]]; then
alias+="$delim${i%%/*}"
delim=", "
if [[ "${i%/*}" =~ \/missing$ ]]; then
alias+=" (missing)"
fi
fi
done
if [ "${#alias}" -gt "$widestAlias" ]; then
widestAlias=${#alias}
fi
done
local formatString="%-6s %-20s %-7s %-12s %-15s %-${widestAlias}s %s\n"
printf "$formatString" "Active" "Version" "Alias" "Location"
printf "$formatString" "------" "-------" "-----" "--------"
else
local formatString="%-6s %-20s %-7s %-12s %-15s %s\n"
printf "$formatString" "Active" "Version" "Alias"
printf "$formatString" "------" "-------" "-----"
fi
for f in `echo -e "$runtimes" | sort -t. -k2 -k3 -k4 -k1`; do
local location=`echo $f | sed 's/.*\([:]\)//'`
f=`echo $f | sed 's/\([:]\).*//'`
local formattedHome=`(echo $location | sed s=$HOME=~=g)`
local active=""
[[ $PATH == *"$location/$f"* ]] && local active=" *"
local pkgName=$(__dnvm_package_name "$f")
local pkgVersion=$(__dnvm_package_version "$f")
local alias=""
local delim=""
for i in "${arr[@]}"; do
if [[ ${i##*/} == "$pkgName.$pkgVersion" ]]; then
alias+="$delim${i%%/*}"
delim=", "
if [[ "${i%/*}" =~ \/missing$ ]]; then
alias+=" (missing)"
formattedHome=""
fi
fi
done
if [[ $2 == "-detailed" ]]; then
printf "$formatString" "$active" "$pkgVersion" "$alias" "$formattedHome"
else
printf "$formatString" "$active" "$pkgVersion" "$alias"
fi
done
echo ""
;;
*)
echo "Unknown command $1"
return 1
esac
return 0
}
# Add the home location's bin directory to the path if it doesn't exist
[[ ":$PATH:" != *":$DOTNET_USER_HOME:"* ]] && export PATH="$DOTNET_USER_HOME:$PATH"
# Generate the command function using the constant defined above.
$_DNVM_COMMAND_NAME alias default >/dev/null && $_DNVM_COMMAND_NAME use default >/dev/null || true

11
scripts/docker/Dockerfile Normal file
View file

@ -0,0 +1,11 @@
# Dockerfile that creates a container suitable to build dotnet-cli
FROM microsoft/aspnet:1.0.0-beta8-coreclr
# Temporary: Install Mono, we use MCS to bootstrap
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF 2>&1 && \
echo "deb http://download.mono-project.com/repo/debian nightly main" > /etc/apt/sources.list.d/mono-nightly.list && \
apt-get -qqy update && \
apt-get -qqy install mono-complete
# Set working directory
WORKDIR /opt/code

View file

@ -8,10 +8,12 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
# work around restore timeouts on Mono
[ -z "$MONO_THREADS_PER_CPU" ] && export MONO_THREADS_PER_CPU=50
cd $DIR/..
# Makes development easier
export PATH=$PATH:$DIR
[ -z "$DOTNET_BUILD_CONTAINER_TAG" ] && DOTNET_BUILD_CONTAINER_TAG="dotnetcli-build"
exec "dnx" -p "$DIR/../../src/Microsoft.DotNet.Tools.Publish" run "$@"
# Build the docker container (will be fast if it is already built)
docker build -t $DOTNET_BUILD_CONTAINER_TAG scripts/docker/
# Run the build in the container
docker run -it --rm -v $(pwd):/opt/code -e DOTNET_BUILD_VERSION=$DOTNET_BUILD_VERSION $DOTNET_BUILD_CONTAINER_TAG /opt/code/build.sh

13
scripts/install-stage0.sh Executable file
View file

@ -0,0 +1,13 @@
#!/usr/bin/env bash
STAGE0_DIR=$1
DNVM_PATH=$2
export DOTNET_USER_HOME=$STAGE0_DIR
source $DNVM_PATH
dnvm upgrade -a dotnet_stage0
VER=`dnvm alias dotnet_stage0`
mv $STAGE0_DIR/sdks/$VER $STAGE0_DIR/bin

66
scripts/package-dnvm.sh Normal file
View file

@ -0,0 +1,66 @@
#!/usr/bin/env bash
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
REPOROOT="$( cd -P "$DIR/.." && pwd )"
if [ -z "$RID" ]; then
UNAME=$(uname)
if [ "$UNAME" == "Darwin" ]; then
OSNAME=osx
RID=osx.10.10-x64
elif [ "$UNAME" == "Linux" ]; then
# Detect Distro?
OSNAME=linux
RID=ubuntu.14.04-x64
else
echo "Unknown OS: $UNAME" 1>&2
exit 1
fi
fi
if [ -z "$DOTNET_BUILD_VERSION" ]; then
TIMESTAMP=$(date "+%Y%m%d%H%M%S")
DOTNET_BUILD_VERSION=0.0.1-alpha-t$TIMESTAMP
fi
STAGE2_DIR=$REPOROOT/artifacts/$RID/stage2
if [ ! -d "$STAGE2_DIR" ]; then
echo "Missing stage2 output in $STAGE2_DIR" 1>&2
exit
fi
PACKAGE_DIR=$REPOROOT/artifacts/packages/dnvm
[ -d "$PACKAGE_DIR" ] || mkdir -p $PACKAGE_DIR
PACKAGE_NAME=$PACKAGE_DIR/dotnet-${OSNAME}-x64.${DOTNET_BUILD_VERSION}.tar.gz
cd $STAGE2_DIR
# Correct all the mode flags
# Managed code doesn't need 'x'
find . -type f -name "*.dll" | xargs chmod 644
find . -type f -name "*.exe" | xargs chmod 644
# Generally, dylibs and sos have 'x' (no idea if it's required ;))
if [ "$OSNAME" == "osx" ]; then
find . -type f -name "*.dylib" | xargs chmod 744
else
find . -type f -name "*.so" | xargs chmod 744
fi
# Executables (those without dots) are executable :)
find . -type f ! -name "*.*" | xargs chmod 755
# Tar up the stage2 artifacts
tar -czf $PACKAGE_NAME *
echo "Packaged stage2 to $PACKAGE_NAME"

4
scripts/package.cmd Normal file
View file

@ -0,0 +1,4 @@
@echo off
REM PowerShell has access to Zipping tools
@powershell -NoLogo -NoProfile -ExecutionPolicy unrestricted -File "%~dp0package.ps1"

22
scripts/package.ps1 Normal file
View file

@ -0,0 +1,22 @@
$Rid = "win7-x64"
$RepoRoot = Convert-Path (Split-Path -Parent $PSScriptRoot)
$Stage2Dir = Join-Path $RepoRoot "artifacts\$RID\stage2"
$PackageDir = Join-Path $RepoRoot "artifacts\packages\dnvm"
if(!(Test-Path $PackageDir)) {
mkdir $PackageDir | Out-Null
}
if(![string]::IsNullOrEmpty($env:DOTNET_BUILD_VERSION)) {
$PackageVersion = $env:DOTNET_BUILD_VERSION
} else {
$Timestamp = [DateTime]::Now.ToString("yyyyMMddHHmmss")
$PackageVersion = "0.0.1-alpha-t$Timestamp"
}
$PackageName = Join-Path $PackageDir "dotnet-win-x64.$PackageVersion.zip"
Add-Type -Assembly System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::CreateFromDirectory($Stage2Dir, $PackageName, "Optimal", $false)
Write-Host "Packaged stage2 to $PackageName"

View file

@ -1,6 +1,4 @@
#!/usr/bin/env bash
#
# Packaging Script
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
@ -10,7 +8,10 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
# Create Dnvm Package
$DIR/package-dnvm.sh
# Create Debian package
$DIR/package-debian.sh
# TODO: Create Pkg
# TODO: Create Pkg

View file

@ -1,20 +0,0 @@
#!/usr/bin/env bash
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
# work around restore timeouts on Mono
[ -z "$MONO_THREADS_PER_CPU" ] && export MONO_THREADS_PER_CPU=50
# Makes development easier
export PATH=$PATH:$DIR
# Assume bootstrapping with mono if this script still exists
export BOOTSTRAPPING_WITH_MONO=true
exec "dnx" -p "$DIR/../../src/Microsoft.DotNet.Tools.Compiler" run "$@"

View file

@ -1,17 +0,0 @@
#!/usr/bin/env bash
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
# work around restore timeouts on Mono
[ -z "$MONO_THREADS_PER_CPU" ] && export MONO_THREADS_PER_CPU=50
# Makes development easier
export PATH=$PATH:$DIR
exec "dnx" -p "$DIR/../../src/Microsoft.DotNet.Tools.Compiler.Csc" run "$@"

View file

@ -11,7 +11,6 @@ namespace Microsoft.DotNet.Cli.Utils
{
public class Command
{
private TaskCompletionSource<int> _processTcs;
private Process _process;
private StringWriter _stdOutCapture;
@ -36,8 +35,6 @@ namespace Microsoft.DotNet.Cli.Utils
RedirectStandardOutput = true
};
_processTcs = new TaskCompletionSource<int>();
_process = new Process()
{
StartInfo = psi
@ -112,34 +109,37 @@ namespace Microsoft.DotNet.Cli.Utils
return false;
}
public async Task<CommandResult> RunAsync()
public CommandResult Execute()
{
ThrowIfRunning();
_running = true;
_process.OutputDataReceived += (sender, args) =>
{
ProcessData(args.Data, _stdOutCapture, _stdOutForward, _stdOutHandler);
};
_process.ErrorDataReceived += (sender, args) =>
{
ProcessData(args.Data, _stdErrCapture, _stdErrForward, _stdErrHandler);
};
_process.EnableRaisingEvents = true;
_process.Exited += (sender, _) =>
_processTcs.SetResult(_process.ExitCode);
#if DEBUG
var sw = Stopwatch.StartNew();
Reporter.Output.WriteLine($"> {_process.StartInfo.FileName} {_process.StartInfo.Arguments}".White());
Reporter.Output.WriteLine($"> {FormatProcessInfo(_process.StartInfo)}".White());
#endif
_process.Start();
_process.BeginOutputReadLine();
_process.BeginErrorReadLine();
var exitCode = await _processTcs.Task;
_process.WaitForExit();
var exitCode = _process.ExitCode;
#if DEBUG
var message = $"> {_process.StartInfo.FileName} {_process.StartInfo.Arguments} exited with {exitCode} in {sw.ElapsedMilliseconds} ms.";
var message = $"> {FormatProcessInfo(_process.StartInfo)} exited with {exitCode} in {sw.ElapsedMilliseconds} ms.";
if (exitCode == 0)
{
Reporter.Output.WriteLine(message.Green().Bold());
@ -206,6 +206,16 @@ namespace Microsoft.DotNet.Cli.Utils
return this;
}
private string FormatProcessInfo(ProcessStartInfo info)
{
if (string.IsNullOrWhiteSpace(info.Arguments))
{
return info.FileName;
}
return info.FileName + " " + info.Arguments;
}
private void ThrowIfRunning([CallerMemberName] string memberName = null)
{
if (_running)

View file

@ -24,8 +24,7 @@ namespace Microsoft.DotNet.Cli
return Command.Create("dotnet-" + args[1], "--help")
.ForwardStdErr()
.ForwardStdOut()
.RunAsync()
.Result
.Execute()
.ExitCode;
}
else
@ -39,8 +38,7 @@ namespace Microsoft.DotNet.Cli
return Command.Create("dotnet-" + args[0], args.Skip(1))
.ForwardStdErr()
.ForwardStdOut()
.RunAsync()
.Result
.Execute()
.ExitCode;
}
}

View file

@ -8,7 +8,7 @@
"dotnet": "Microsoft.DotNet.Cli"
},
"dependencies": {
"Microsoft.NETCore.Runtime": "1.0.1-*",
"Microsoft.NETCore.Runtime": "1.0.1-beta-23413",
"System.Console": "4.0.0-*",
"System.Collections": "4.0.11-*",

View file

@ -25,8 +25,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Csc
var result = RunCsc($"-noconfig @\"{responseFileArg.Value}\"")
.ForwardStdErr()
.ForwardStdOut()
.RunAsync()
.Result;
.Execute();
return result.ExitCode;
});

View file

@ -9,7 +9,7 @@
},
"dependencies": {
"Microsoft.NETCore.TestHost": "1.0.0-*",
"Microsoft.NETCore.Runtime": "1.0.1-*",
"Microsoft.NETCore.Runtime": "1.0.1-beta-23413",
"System.Console": "4.0.0-*",
"System.Collections": "4.0.11-*",

View file

@ -0,0 +1,415 @@
using System;
using System.Globalization;
using System.Text.RegularExpressions;
// https://github.com/dotnet/roslyn/blob/master/src/Compilers/Core/MSBuildTask/CanonicalError.cs
namespace Microsoft.DotNet.Tools.Compiler
{
/// <summary>
/// Functions for dealing with the specially formatted errors returned by
/// build tools.
/// </summary>
/// <remarks>
/// Various tools produce and consume CanonicalErrors in various formats.
///
/// DEVENV Format When Clicking on Items in the Output Window
/// (taken from env\msenv\core\findutil.cpp ParseLocation function)
///
/// v:\dir\file.ext (loc) : msg
/// \\server\share\dir\file.ext(loc):msg
/// url
///
/// loc:
/// (line)
/// (line-line)
/// (line,col)
/// (line,col-col)
/// (line,col,len)
/// (line,col,line,col)
///
/// DevDiv Build Process
/// (taken from tools\devdiv2.def)
///
/// To echo warnings and errors to the build console, the
/// "description block" must be recognized by build. To do this,
/// add a $(ECHO_COMPILING_COMMAND) or $(ECHO_PROCESSING_COMMAND)
/// to the first line of the description block, e.g.
///
/// $(ECHO_COMPILING_CMD) Resgen_$&lt;
///
/// Errors must have the format:
///
/// &lt;text&gt; : error [num]: &lt;msg&gt;
///
/// Warnings must have the format:
///
/// &lt;text&gt; : warning [num]: &lt;msg&gt;
/// </remarks>
/// <owner>JomoF</owner>
internal static class CanonicalError
{
// Defines the main pattern for matching messages.
private static readonly Regex s_originCategoryCodeTextExpression = new Regex
(
// Beginning of line and any amount of whitespace.
@"^\s*"
// Match a [optional project number prefix 'ddd>'], single letter + colon + remaining filename, or
// string with no colon followed by a colon.
+ @"(((?<ORIGIN>(((\d+>)?[a-zA-Z]?:[^:]*)|([^:]*))):)"
// Origin may also be empty. In this case there's no trailing colon.
+ "|())"
// Match the empty string or a string without a colon that ends with a space
+ "(?<SUBCATEGORY>(()|([^:]*? )))"
// Match 'error' or 'warning'.
+ @"(?<CATEGORY>(error|warning))"
// Match anything starting with a space that's not a colon/space, followed by a colon.
// Error code is optional in which case "error"/"warning" can be followed immediately by a colon.
+ @"( \s*(?<CODE>[^: ]*))?\s*:"
// Whatever's left on this line, including colons.
+ "(?<TEXT>.*)$",
RegexOptions.IgnoreCase
);
// Matches and extracts filename and location from an 'origin' element.
private static readonly Regex s_filenameLocationFromOrigin = new Regex
(
"^" // Beginning of line
+ @"(\d+>)?" // Optional ddd> project number prefix
+ "(?<FILENAME>.*)" // Match anything.
+ @"\(" // Find a parenthesis.
+ @"(?<LOCATION>[\,,0-9,-]*)" // Match any combination of numbers and ',' and '-'
+ @"\)\s*" // Find the closing paren then any amount of spaces.
+ "$", // End-of-line
RegexOptions.IgnoreCase
);
// Matches location that is a simple number.
private static readonly Regex s_lineFromLocation = new Regex // Example: line
(
"^" // Beginning of line
+ "(?<LINE>[0-9]*)" // Match any number.
+ "$", // End-of-line
RegexOptions.IgnoreCase
);
// Matches location that is a range of lines.
private static readonly Regex s_lineLineFromLocation = new Regex // Example: line-line
(
"^" // Beginning of line
+ "(?<LINE>[0-9]*)" // Match any number.
+ "-" // Dash
+ "(?<ENDLINE>[0-9]*)" // Match any number.
+ "$", // End-of-line
RegexOptions.IgnoreCase
);
// Matches location that is a line and column
private static readonly Regex s_lineColFromLocation = new Regex // Example: line,col
(
"^" // Beginning of line
+ "(?<LINE>[0-9]*)" // Match any number.
+ "," // Comma
+ "(?<COLUMN>[0-9]*)" // Match any number.
+ "$", // End-of-line
RegexOptions.IgnoreCase
);
// Matches location that is a line and column-range
private static readonly Regex s_lineColColFromLocation = new Regex // Example: line,col-col
(
"^" // Beginning of line
+ "(?<LINE>[0-9]*)" // Match any number.
+ "," // Comma
+ "(?<COLUMN>[0-9]*)" // Match any number.
+ "-" // Dash
+ "(?<ENDCOLUMN>[0-9]*)" // Match any number.
+ "$", // End-of-line
RegexOptions.IgnoreCase
);
// Matches location that is line,col,line,col
private static readonly Regex s_lineColLineColFromLocation = new Regex // Example: line,col,line,col
(
"^" // Beginning of line
+ "(?<LINE>[0-9]*)" // Match any number.
+ "," // Comma
+ "(?<COLUMN>[0-9]*)" // Match any number.
+ "," // Dash
+ "(?<ENDLINE>[0-9]*)" // Match any number.
+ "," // Dash
+ "(?<ENDCOLUMN>[0-9]*)" // Match any number.
+ "$", // End-of-line
RegexOptions.IgnoreCase
);
/// <summary>
/// Represents the parts of a decomposed canonical message.
/// </summary>
/// <owner>JomoF</owner>
internal sealed class Parts
{
/// <summary>
/// Defines the error category\severity level.
/// </summary>
internal enum Category
{
Warning,
Error
}
/// <summary>
/// Value used for unspecified line and column numbers, which are 1-relative.
/// </summary>
internal const int numberNotSpecified = 0;
/// <summary>
/// Initializes a new instance of the <see cref="Parts"/> class.
/// </summary>
internal Parts()
{
}
/// <summary>
/// Name of the file or tool (not localized)
/// </summary>
internal string origin;
/// <summary>
/// The line number.
/// </summary>
internal int line = Parts.numberNotSpecified;
/// <summary>
/// The column number.
/// </summary>
internal int column = Parts.numberNotSpecified;
/// <summary>
/// The ending line number.
/// </summary>
internal int endLine = Parts.numberNotSpecified;
/// <summary>
/// The ending column number.
/// </summary>
internal int endColumn = Parts.numberNotSpecified;
/// <summary>
/// The category/severity level
/// </summary>
internal Category category;
/// <summary>
/// The sub category (localized)
/// </summary>
internal string subcategory;
/// <summary>
/// The error code (not localized)
/// </summary>
internal string code;
/// <summary>
/// The error message text (localized)
/// </summary>
internal string text;
#if NEVER
internal new string ToString()
{
return String.Format
(
"Origin='{0}'\n"
+"Filename='{1}'\n"
+"Line='{2}'\n"
+"Column='{3}'\n"
+"EndLine='{4}'\n"
+"EndColumn='{5}'\n"
+"Category='{6}'\n"
+"Subcategory='{7}'\n"
+"Text='{8}'\n"
, origin, line, column, endLine, endColumn, category.ToString(), subcategory, code, text
);
}
#endif
}
/// <summary>
/// A small custom int conversion method that treats invalid entries as missing (0). This is done to work around tools
/// that don't fully conform to the canonical message format - we still want to salvage what we can from the message.
/// </summary>
/// <param name="value"></param>
/// <returns>'value' converted to int or 0 if it can't be parsed or is negative</returns>
/// <owner>LukaszG</owner>
private static int ConvertToIntWithDefault(string value)
{
int result;
bool success = int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out result);
if (!success || (result < 0))
{
result = CanonicalError.Parts.numberNotSpecified;
}
return result;
}
/// <summary>
/// Decompose an error or warning message into constituent parts. If the message isn't in the canonical form, return null.
/// </summary>
/// <remarks>This method is thread-safe, because the Regex class is thread-safe (per MSDN).</remarks>
/// <owner>JomoF</owner>
/// <param name="message"></param>
/// <returns>Decomposed canonical message, or null.</returns>
internal static Parts Parse(string message)
{
// An unusually long string causes pathologically slow Regex back-tracking.
// To avoid that, only scan the first 400 characters. That's enough for
// the longest possible prefix: MAX_PATH, plus a huge subcategory string, and an error location.
// After the regex is done, we can append the overflow.
string messageOverflow = String.Empty;
if (message.Length > 400)
{
messageOverflow = message.Substring(400);
message = message.Substring(0, 400);
}
// If a tool has a large amount of output that isn't an error or warning (eg., "dir /s %hugetree%")
// the regex below is slow. It's faster to pre-scan for "warning" and "error"
// and bail out if neither are present.
if (message.IndexOf("warning", StringComparison.OrdinalIgnoreCase) == -1 &&
message.IndexOf("error", StringComparison.OrdinalIgnoreCase) == -1)
{
return null;
}
Parts parsedMessage = new Parts();
// First, split the message into three parts--Origin, Category, Code, Text.
// Example,
// Main.cs(17,20):Command line warning CS0168: The variable 'foo' is declared but never used
// -------------- ------------ ------- ------ ----------------------------------------------
// Origin SubCategory Cat. Code Text
//
// To accommodate absolute filenames in Origin, tolerate a colon in the second position
// as long as its preceded by a letter.
//
// Localization Note:
// Even in foreign-language versions of tools, the category field needs to be in English.
// Also, if origin is a tool name, then that needs to be in English.
//
// Here's an example from the Japanese version of CL.EXE:
// cl : ???? ??? warning D4024 : ?????????? 'AssemblyInfo.cs' ?????????????????? ???????????
//
// Here's an example from the Japanese version of LINK.EXE:
// AssemblyInfo.cpp : fatal error LNK1106: ???????????? ??????????????: 0x6580 ??????????
//
Match match = s_originCategoryCodeTextExpression.Match(message);
if (!match.Success)
{
// If no match here, then this message is not an error or warning.
return null;
}
string origin = match.Groups["ORIGIN"].Value.Trim();
string category = match.Groups["CATEGORY"].Value.Trim();
parsedMessage.code = match.Groups["CODE"].Value.Trim();
parsedMessage.text = (match.Groups["TEXT"].Value + messageOverflow).Trim();
parsedMessage.subcategory = match.Groups["SUBCATEGORY"].Value.Trim();
// Next, see if category is something that is recognized.
if (0 == String.Compare(category, "error", StringComparison.OrdinalIgnoreCase))
{
parsedMessage.category = Parts.Category.Error;
}
else if (0 == String.Compare(category, "warning", StringComparison.OrdinalIgnoreCase))
{
parsedMessage.category = Parts.Category.Warning;
}
else
{
// Not an error\warning message.
return null;
}
// Origin is not a simple file, but it still could be of the form,
// foo.cpp(location)
match = s_filenameLocationFromOrigin.Match(origin);
if (match.Success)
{
// The origin is in the form,
// foo.cpp(location)
// Assume the filename exists, but don't verify it. What else could it be?
string location = match.Groups["LOCATION"].Value.Trim();
parsedMessage.origin = match.Groups["FILENAME"].Value.Trim();
// Now, take apart the location. It can be one of these:
// loc:
// (line)
// (line-line)
// (line,col)
// (line,col-col)
// (line,col,len)
// (line,col,line,col)
if (location.Length > 0)
{
match = s_lineFromLocation.Match(location);
if (match.Success)
{
parsedMessage.line = ConvertToIntWithDefault(match.Groups["LINE"].Value.Trim());
}
else
{
match = s_lineLineFromLocation.Match(location);
if (match.Success)
{
parsedMessage.line = ConvertToIntWithDefault(match.Groups["LINE"].Value.Trim());
parsedMessage.endLine = ConvertToIntWithDefault(match.Groups["ENDLINE"].Value.Trim());
}
else
{
match = s_lineColFromLocation.Match(location);
if (match.Success)
{
parsedMessage.line = ConvertToIntWithDefault(match.Groups["LINE"].Value.Trim());
parsedMessage.column = ConvertToIntWithDefault(match.Groups["COLUMN"].Value.Trim());
}
else
{
match = s_lineColColFromLocation.Match(location);
if (match.Success)
{
parsedMessage.line = ConvertToIntWithDefault(match.Groups["LINE"].Value.Trim());
parsedMessage.column = ConvertToIntWithDefault(match.Groups["COLUMN"].Value.Trim());
parsedMessage.endColumn = ConvertToIntWithDefault(match.Groups["ENDCOLUMN"].Value.Trim());
}
else
{
match = s_lineColLineColFromLocation.Match(location);
if (match.Success)
{
parsedMessage.line = ConvertToIntWithDefault(match.Groups["LINE"].Value.Trim());
parsedMessage.column = ConvertToIntWithDefault(match.Groups["COLUMN"].Value.Trim());
parsedMessage.endLine = ConvertToIntWithDefault(match.Groups["ENDLINE"].Value.Trim());
parsedMessage.endColumn = ConvertToIntWithDefault(match.Groups["ENDCOLUMN"].Value.Trim());
}
}
}
}
}
}
}
else
{
// The origin does not fit the filename(location) pattern.
parsedMessage.origin = origin;
}
return parsedMessage;
}
}
}

View file

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@ -77,25 +77,17 @@ namespace Microsoft.DotNet.Tools.Compiler
private static bool Compile(ProjectContext context, string configuration, string outputPath, bool buildProjectReferences)
{
Reporter.Output.WriteLine($"Building {context.RootProject.Identity.Name.Yellow()} for {context.TargetFramework.DotNetFrameworkName.Yellow()}");
Reporter.Output.WriteLine($"Compiling {context.RootProject.Identity.Name.Yellow()} for {context.TargetFramework.DotNetFrameworkName.Yellow()}");
// Create the library exporter
var exporter = context.CreateExporter(configuration);
var diagnostics = new List<DiagnosticMessage>();
bool success = true;
// Print out dependency diagnostics
foreach (var diag in context.LibraryManager.GetAllDiagnostics())
{
success &= diag.Severity != DiagnosticMessageSeverity.Error;
Console.WriteLine(diag.FormattedMessage);
}
// If there were dependency errors don't bother compiling
if (!success)
{
return false;
}
// Collect dependency diagnostics
diagnostics.AddRange(context.LibraryManager.GetAllDiagnostics());
// Gather exports for the project
var dependencies = exporter.GetCompilationDependencies().ToList();
@ -121,12 +113,10 @@ namespace Microsoft.DotNet.Tools.Compiler
var compileResult = Command.Create("dotnet-compile", $"--framework {projectDependency.Framework} --configuration {configuration} --no-project-dependencies {projectDependency.Project.ProjectDirectory}")
.ForwardStdOut()
.ForwardStdErr()
.RunAsync()
.Result;
.Execute();
if (compileResult.ExitCode != 0)
{
Console.Error.WriteLine($"Failed to compile dependency: {projectDependency.Identity.Name.Red().Bold()}");
return false;
}
}
@ -168,9 +158,7 @@ namespace Microsoft.DotNet.Tools.Compiler
// Get compilation options
var compilationOptions = context.ProjectFile.GetCompilerOptions(context.TargetFramework, configuration);
var outputName = Path.Combine(outputPath, context.ProjectFile.Name + (compilationOptions.EmitEntryPoint.GetValueOrDefault() ? ".exe" : ".dll"));
var bootstrappingWithMono = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("BOOTSTRAPPING_WITH_MONO"));
// Assemble args
var compilerArgs = new List<string>()
{
@ -179,16 +167,13 @@ namespace Microsoft.DotNet.Tools.Compiler
$"-out:\"{outputName}\""
};
if (!bootstrappingWithMono)
{
// Default suppressions, some versions of mono don't support these
compilerArgs.Add("-nowarn:CS1701");
compilerArgs.Add("-nowarn:CS1702");
compilerArgs.Add("-nowarn:CS1705");
}
// Default suppressions, some versions of mono don't support these
compilerArgs.Add("-nowarn:CS1701");
compilerArgs.Add("-nowarn:CS1702");
compilerArgs.Add("-nowarn:CS1705");
// Add compilation options to the args
ApplyCompilationOptions(compilationOptions, compilerArgs, bootstrappingWithMono);
ApplyCompilationOptions(compilationOptions, compilerArgs);
foreach (var dependency in dependencies)
{
@ -212,19 +197,66 @@ namespace Microsoft.DotNet.Tools.Compiler
File.WriteAllLines(rsp, compilerArgs);
var result = Command.Create($"dotnet-compile-{compiler}", $"\"{rsp}\"")
.ForwardStdErr()
.ForwardStdOut()
.RunAsync()
.GetAwaiter()
.GetResult();
.OnErrorLine(line =>
{
var diagnostic = ParseDiagnostic(context.ProjectDirectory, line);
if (diagnostic != null)
{
diagnostics.Add(diagnostic);
}
else
{
Console.Error.WriteLine(line);
}
})
.OnOutputLine(line =>
{
var diagnostic = ParseDiagnostic(context.ProjectDirectory, line);
if (result.ExitCode == 0)
if (diagnostic != null)
{
diagnostics.Add(diagnostic);
}
else
{
Console.Out.WriteLine(line);
}
})
.Execute();
foreach (var diag in diagnostics)
{
Reporter.Output.WriteLine($"Compiled {context.ProjectFile.Name} successfully!".Green().Bold());
return true;
success &= diag.Severity != DiagnosticMessageSeverity.Error;
PrintDiagnostic(diag);
}
success &= result.ExitCode == 0;
PrintSummary(diagnostics);
return success;
}
private static void PrintSummary(List<DiagnosticMessage> diagnostics)
{
Reporter.Output.Writer.WriteLine();
var errorCount = diagnostics.Count(d => d.Severity == DiagnosticMessageSeverity.Error);
var warningCount = diagnostics.Count(d => d.Severity == DiagnosticMessageSeverity.Warning);
if (errorCount > 0)
{
Reporter.Output.WriteLine("Compilation failed.".Red());
}
else
{
Reporter.Output.WriteLine("Compilation succeeded.".Green());
}
return false;
Reporter.Output.WriteLine($" {warningCount} Warning(s)");
Reporter.Output.WriteLine($" {errorCount} Error(s)");
Reporter.Output.Writer.WriteLine();
}
private static bool AddResources(Project project, List<string> compilerArgs, string intermediateOutputPath)
@ -265,9 +297,7 @@ namespace Microsoft.DotNet.Tools.Compiler
var result = Command.Create("resgen", $"{fileName} {resourcesFile}")
.ForwardStdErr()
.ForwardStdOut()
.RunAsync()
.GetAwaiter()
.GetResult();
.Execute();
if (result.ExitCode != 0)
{
@ -312,52 +342,92 @@ namespace Microsoft.DotNet.Tools.Compiler
outputs.Add(project);
}
private static void ApplyCompilationOptions(CompilerOptions compilationOptions, List<string> cscArgs, bool bootstrappingWithMono)
private static DiagnosticMessage ParseDiagnostic(string projectRootPath, string line)
{
var error = CanonicalError.Parse(line);
if (error != null)
{
var severity = error.category == CanonicalError.Parts.Category.Error ?
DiagnosticMessageSeverity.Error : DiagnosticMessageSeverity.Warning;
return new DiagnosticMessage(
error.code,
error.text,
Path.IsPathRooted(error.origin) ? line : projectRootPath + Path.DirectorySeparatorChar + line,
Path.Combine(projectRootPath, error.origin),
severity,
error.line,
error.column,
error.endColumn,
error.endLine,
source: null);
}
return null;
}
private static void PrintDiagnostic(DiagnosticMessage diag)
{
switch (diag.Severity)
{
case DiagnosticMessageSeverity.Info:
Reporter.Error.WriteLine(diag.FormattedMessage);
break;
case DiagnosticMessageSeverity.Warning:
Reporter.Error.WriteLine(diag.FormattedMessage.Yellow().Bold());
break;
case DiagnosticMessageSeverity.Error:
Reporter.Error.WriteLine(diag.FormattedMessage.Red().Bold());
break;
}
}
private static void ApplyCompilationOptions(CompilerOptions compilationOptions, List<string> compilerArgs)
{
// TODO: Move compilation arguments into the compiler itself
var targetType = compilationOptions.EmitEntryPoint.GetValueOrDefault() ? "exe" : "library";
cscArgs.Add($"-target:{targetType}");
compilerArgs.Add($"-target:{targetType}");
if (compilationOptions.AllowUnsafe.GetValueOrDefault())
{
cscArgs.Add("-unsafe+");
compilerArgs.Add("-unsafe+");
}
cscArgs.AddRange(compilationOptions.Defines.Select(d => $"-d:{d}"));
compilerArgs.AddRange(compilationOptions.Defines.Select(d => $"-d:{d}"));
if (compilationOptions.Optimize.GetValueOrDefault())
{
cscArgs.Add("-optimize");
compilerArgs.Add("-optimize");
}
if (!string.IsNullOrEmpty(compilationOptions.Platform))
{
cscArgs.Add($"-platform:{compilationOptions.Platform}");
compilerArgs.Add($"-platform:{compilationOptions.Platform}");
}
if (compilationOptions.WarningsAsErrors.GetValueOrDefault())
{
cscArgs.Add("-warnaserror");
compilerArgs.Add("-warnaserror");
}
if (compilationOptions.DelaySign.GetValueOrDefault())
{
cscArgs.Add("-delaysign+");
compilerArgs.Add("-delaysign+");
}
if (!string.IsNullOrEmpty(compilationOptions.KeyFile))
{
cscArgs.Add($"-keyFile:\"{compilationOptions.KeyFile}\"");
compilerArgs.Add($"-keyFile:\"{compilationOptions.KeyFile}\"");
}
if (bootstrappingWithMono || RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
cscArgs.Add("-debug:full");
compilerArgs.Add("-debug:full");
}
else
{
cscArgs.Add("-debug:portable");
compilerArgs.Add("-debug:portable");
}
// TODO: OSS signing

View file

@ -9,7 +9,7 @@
},
"dependencies": {
"Microsoft.NETCore.TestHost": "1.0.0-*",
"Microsoft.NETCore.Runtime": "1.0.1-*",
"Microsoft.NETCore.Runtime": "1.0.1-beta-23413",
"System.Console": "4.0.0-*",
"System.Collections": "4.0.11-*",

View file

@ -101,8 +101,7 @@ namespace Microsoft.DotNet.Tools.Publish
var result = Command.Create("dotnet-compile", $"--framework {context.TargetFramework.DotNetFrameworkName} {context.ProjectFile.ProjectDirectory}")
.ForwardStdErr()
.ForwardStdOut()
.RunAsync()
.Result;
.Execute();
if (result.ExitCode != 0)
{
@ -179,16 +178,15 @@ while [ -h ""$SOURCE"" ]; do # resolve $SOURCE until the file is no longer a sym
[[ $SOURCE != /* ]] && SOURCE=""$DIR/$SOURCE"" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR=""$( cd -P ""$( dirname ""$SOURCE"" )"" && pwd )""
exec ""$DIR/corerun"" ""$DIR/{context.ProjectFile.Name}.exe"" $*";
exec ""$DIR/corerun"" ""$DIR/{context.ProjectFile.Name}.exe"" $*
";
File.WriteAllText(outputExe, script);
Command.Create("chmod", $"a+x {outputExe}")
.ForwardStdOut()
.ForwardStdErr()
.RunAsync()
.GetAwaiter()
.GetResult();
.Execute();
return 0;
}

View file

@ -8,7 +8,7 @@
"dotnet-publish": "Microsoft.DotNet.Tools.Publish"
},
"dependencies": {
"Microsoft.NETCore.Runtime": "1.0.1-*",
"Microsoft.NETCore.Runtime": "1.0.1-beta-23413",
"System.Console": "4.0.0-*",
"System.Collections": "4.0.11-*",
"System.Linq": "4.0.1-*",

View file

@ -9,7 +9,7 @@
},
"dependencies": {
"Microsoft.NETCore.TestHost": "1.0.0-*",
"Microsoft.NETCore.Runtime": "1.0.1-*",
"Microsoft.NETCore.Runtime": "1.0.1-beta-23413",
"System.Console": "4.0.0-*",
"System.Collections": "4.0.11-*",
"System.Linq": "4.0.1-*",

View file

@ -1,8 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Extensions.JsonParser.Sources;
namespace Microsoft.Extensions.ProjectModel
{
/// <summary>

View file

@ -1,12 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Extensions.ProjectModel.Graph;
using NuGet.Versioning;
namespace Microsoft.Extensions.ProjectModel.Resolution
{
@ -47,9 +44,9 @@ namespace Microsoft.Extensions.ProjectModel.Resolution
foreach (var range in library.RequestedRanges)
{
errorCode = ErrorCodes.NU1001;
message = $"The dependency {range.Name} {range.VersionRange} could not be resolved.";
message = $"The dependency {FormatLibraryRange(range)} could not be resolved.";
AddDiagnostics(messages, library, message, errorCode);
AddDiagnostics(messages, library, message, DiagnosticMessageSeverity.Error, errorCode);
}
}
else
@ -57,7 +54,7 @@ namespace Microsoft.Extensions.ProjectModel.Resolution
errorCode = ErrorCodes.NU1002;
message = $"The dependency {library.Identity} does not support framework {library.Framework}.";
AddDiagnostics(messages, library, message, errorCode);
AddDiagnostics(messages, library, message, DiagnosticMessageSeverity.Error, errorCode);
}
}
else
@ -87,18 +84,11 @@ namespace Microsoft.Extensions.ProjectModel.Resolution
{
var message = $"Dependency specified was {range} but ended up with {library.Identity}.";
foreach (var source in GetRangesWithSourceLocations(library))
{
messages.Add(
new DiagnosticMessage(
ErrorCodes.NU1007,
message,
source.SourceFilePath,
DiagnosticMessageSeverity.Warning,
source.SourceLine,
source.SourceColumn,
library));
}
AddDiagnostics(messages,
library,
message,
DiagnosticMessageSeverity.Warning,
ErrorCodes.NU1007);
}
}
}
@ -107,7 +97,21 @@ namespace Microsoft.Extensions.ProjectModel.Resolution
return messages;
}
private void AddDiagnostics(List<DiagnosticMessage> messages, LibraryDescription library, string message, string errorCode)
private static string FormatLibraryRange(LibraryRange range)
{
if (range.VersionRange == null)
{
return range.Name;
}
return range.Name + " " + range.VersionRange;
}
private void AddDiagnostics(List<DiagnosticMessage> messages,
LibraryDescription library,
string message,
DiagnosticMessageSeverity severity,
string errorCode)
{
// A (in project.json) -> B (unresolved) (not in project.json)
foreach (var source in GetRangesWithSourceLocations(library).Distinct())
@ -117,7 +121,7 @@ namespace Microsoft.Extensions.ProjectModel.Resolution
errorCode,
message,
source.SourceFilePath,
DiagnosticMessageSeverity.Error,
severity,
source.SourceLine,
source.SourceColumn,
library));