From bb5a5805ad219c909d2c6aaa70e8c75adb7ac32a Mon Sep 17 00:00:00 2001 From: Vatsan Madhavan Date: Thu, 16 May 2019 10:47:36 -0700 Subject: [PATCH 1/4] Add support for per-platform runtimes to support x86 specific test runners. --- eng/common/build.ps1 | 4 ++++ eng/common/dotnet-install.ps1 | 10 ++++++++-- .../src/InstallDotNetCore.cs | 14 +++++++++++--- .../tools/InstallDotNetCore.targets | 3 ++- .../tools/XUnit/XUnit.targets | 5 ++++- 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/eng/common/build.ps1 b/eng/common/build.ps1 index d7e3799ebd9..a4f017b1e47 100644 --- a/eng/common/build.ps1 +++ b/eng/common/build.ps1 @@ -1,6 +1,7 @@ [CmdletBinding(PositionalBinding=$false)] Param( [string][Alias('c')]$configuration = "Debug", + [string][Alias('p')]$platform = $null, [string] $projects, [string][Alias('v')]$verbosity = "minimal", [string] $msbuildEngine = $null, @@ -29,6 +30,7 @@ Param( function Print-Usage() { Write-Host "Common settings:" Write-Host " -configuration Build configuration: 'Debug' or 'Release' (short: -c)" + Write-Host " -platform Platform configuration: 'x86', 'x64' or any valid Platform value to pass to msbuild (short: -p)" Write-Host " -verbosity Msbuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic] (short: -v)" Write-Host " -binaryLog Output binary log (short: -bl)" Write-Host " -help Print help and exit" @@ -77,6 +79,7 @@ function Build { InitializeCustomToolset $bl = if ($binaryLog) { "/bl:" + (Join-Path $LogDir "Build.binlog") } else { "" } + $pl = if ($platform) { "/p:Platform=$platform" } else { "" } if ($projects) { # Re-assign properties to a new variable because PowerShell doesn't let us append properties directly for unclear reasons. @@ -88,6 +91,7 @@ function Build { MSBuild $toolsetBuildProj ` $bl ` + $pl ` /p:Configuration=$configuration ` /p:RepoRoot=$RepoRoot ` /p:Restore=$restore ` diff --git a/eng/common/dotnet-install.ps1 b/eng/common/dotnet-install.ps1 index 5987943fd6f..0944a905988 100644 --- a/eng/common/dotnet-install.ps1 +++ b/eng/common/dotnet-install.ps1 @@ -10,7 +10,13 @@ Param( try { $dotnetRoot = Join-Path $RepoRoot ".dotnet" - InstallDotNet $dotnetRoot $version $architecture $runtime $true + + $dotnetInstallLocation = $dotnetRoot + if ($architecture -and -not ($architecture -like '')) { + $dotnetInstallLocation = Join-Path $dotnetRoot $architecture + } + + InstallDotNet $dotnetInstallLocation $version $architecture $runtime $true } catch { Write-Host $_ @@ -19,4 +25,4 @@ catch { ExitWithExitCode 1 } -ExitWithExitCode 0 \ No newline at end of file +ExitWithExitCode 0 diff --git a/src/Microsoft.DotNet.Arcade.Sdk/src/InstallDotNetCore.cs b/src/Microsoft.DotNet.Arcade.Sdk/src/InstallDotNetCore.cs index b49030a58b1..4486fac5ca7 100644 --- a/src/Microsoft.DotNet.Arcade.Sdk/src/InstallDotNetCore.cs +++ b/src/Microsoft.DotNet.Arcade.Sdk/src/InstallDotNetCore.cs @@ -28,6 +28,7 @@ public class InstallDotNetCore : Task public string DotNetInstallScript { get; set; } [Required] public string GlobalJsonPath { get; set; } + public string Platform { get; set; } public override bool Execute() { @@ -101,10 +102,17 @@ public override bool Execute() { arguments += $" -architecture {architecture}"; } - else if (RuntimeInformation.OSArchitecture == Architecture.X86 || - RuntimeInformation.OSArchitecture == Architecture.X64) + else { - arguments += " -architecture x64"; + if (!string.IsNullOrWhiteSpace(Platform) && !string.Equals(Platform, "AnyCpu", StringComparison.OrdinalIgnoreCase)) + { + arguments += $" -architecture {Platform}"; + } + else if (RuntimeInformation.OSArchitecture == Architecture.X86 || + RuntimeInformation.OSArchitecture == Architecture.X64) + { + arguments += " -architecture x64"; + } } Log.LogMessage(MessageImportance.Low, $"Executing: {DotNetInstallScript} {arguments}"); var process = Process.Start(new ProcessStartInfo() diff --git a/src/Microsoft.DotNet.Arcade.Sdk/tools/InstallDotNetCore.targets b/src/Microsoft.DotNet.Arcade.Sdk/tools/InstallDotNetCore.targets index e1a2abfb15d..444a002de7e 100644 --- a/src/Microsoft.DotNet.Arcade.Sdk/tools/InstallDotNetCore.targets +++ b/src/Microsoft.DotNet.Arcade.Sdk/tools/InstallDotNetCore.targets @@ -15,7 +15,8 @@ + DotNetInstallScript="$(_DotNetInstallScript)" + Platform="$(Platform)"/> diff --git a/src/Microsoft.DotNet.Arcade.Sdk/tools/XUnit/XUnit.targets b/src/Microsoft.DotNet.Arcade.Sdk/tools/XUnit/XUnit.targets index b0f98d65d17..b6369f3adbc 100644 --- a/src/Microsoft.DotNet.Arcade.Sdk/tools/XUnit/XUnit.targets +++ b/src/Microsoft.DotNet.Arcade.Sdk/tools/XUnit/XUnit.targets @@ -47,7 +47,10 @@ <_TargetDir>$([System.IO.Path]::GetDirectoryName('$(_TestAssembly)'))\ <_CoreRuntimeConfigPath>$(_TargetDir)$(_TargetFileNameNoExt).runtimeconfig.json <_CoreDepsPath>$(_TargetDir)$(_TargetFileNameNoExt).deps.json - <_TestRunner>$(DotNetTool) + + <_TestRunner Condition="'$(TestArchitectures)'!='' And '$(TestArchitectures)'!='AnyCpu' And Exists('$(DotNetRoot)$(TestArchitectures)\dotnet.exe')">$(DotNetRoot)$(TestArchitectures)\dotnet.exe + <_TestRunner Condition="'$(_TestRunner)'==''">$(DotNetTool) + <_TestRunnerArgs>exec --depsfile "$(_CoreDepsPath)" --runtimeconfig "$(_CoreRuntimeConfigPath)" $(TestRuntimeAdditionalArguments) "$(NuGetPackageRoot)xunit.runner.console/$(XUnitVersion)/tools/$(_TestRunnerTargetFramework)/xunit.console.dll" "$(_TestAssembly)" -noautoreporters -xml "%(TestToRun.ResultsXmlPath)" -html "%(TestToRun.ResultsHtmlPath)" $(_TestRunnerAdditionalArguments) From b47815337d2ccad03f000fe3b7e4d2442ed44fe9 Mon Sep 17 00:00:00 2001 From: Vatsan Madhavan Date: Thu, 16 May 2019 12:31:54 -0700 Subject: [PATCH 2/4] Change back x64 install to happen under $(RepoRoot).dotnet\, and only install x86 under its own folder Pass installdir from InstallDotNetCore task => dotnet-install.ps1 --- eng/common/build.ps1 | 4 ++-- eng/common/dotnet-install.ps1 | 11 +++++---- .../src/InstallDotNetCore.cs | 24 ++++++++++++++++++- .../tools/InstallDotNetCore.targets | 1 + 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/eng/common/build.ps1 b/eng/common/build.ps1 index a4f017b1e47..10ea57d1f12 100644 --- a/eng/common/build.ps1 +++ b/eng/common/build.ps1 @@ -1,7 +1,7 @@ [CmdletBinding(PositionalBinding=$false)] Param( [string][Alias('c')]$configuration = "Debug", - [string][Alias('p')]$platform = $null, + [string]$platform = $null, [string] $projects, [string][Alias('v')]$verbosity = "minimal", [string] $msbuildEngine = $null, @@ -30,7 +30,7 @@ Param( function Print-Usage() { Write-Host "Common settings:" Write-Host " -configuration Build configuration: 'Debug' or 'Release' (short: -c)" - Write-Host " -platform Platform configuration: 'x86', 'x64' or any valid Platform value to pass to msbuild (short: -p)" + Write-Host " -platform Platform configuration: 'x86', 'x64' or any valid Platform value to pass to msbuild" Write-Host " -verbosity Msbuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic] (short: -v)" Write-Host " -binaryLog Output binary log (short: -bl)" Write-Host " -help Print help and exit" diff --git a/eng/common/dotnet-install.ps1 b/eng/common/dotnet-install.ps1 index 0944a905988..104530f8f85 100644 --- a/eng/common/dotnet-install.ps1 +++ b/eng/common/dotnet-install.ps1 @@ -3,7 +3,8 @@ Param( [string] $verbosity = "minimal", [string] $architecture = "", [string] $version = "Latest", - [string] $runtime = "dotnet" + [string] $runtime = "dotnet", + [string] $installdir = "" ) . $PSScriptRoot\tools.ps1 @@ -11,11 +12,11 @@ Param( try { $dotnetRoot = Join-Path $RepoRoot ".dotnet" - $dotnetInstallLocation = $dotnetRoot - if ($architecture -and -not ($architecture -like '')) { - $dotnetInstallLocation = Join-Path $dotnetRoot $architecture + $dotnetInstallLocation = $installdir + if (-not $dotnetInstallLocation) { + $dotnetInstallLocation = $dotnetRoot } - + InstallDotNet $dotnetInstallLocation $version $architecture $runtime $true } catch { diff --git a/src/Microsoft.DotNet.Arcade.Sdk/src/InstallDotNetCore.cs b/src/Microsoft.DotNet.Arcade.Sdk/src/InstallDotNetCore.cs index 4486fac5ca7..24ba0c41639 100644 --- a/src/Microsoft.DotNet.Arcade.Sdk/src/InstallDotNetCore.cs +++ b/src/Microsoft.DotNet.Arcade.Sdk/src/InstallDotNetCore.cs @@ -28,7 +28,10 @@ public class InstallDotNetCore : Task public string DotNetInstallScript { get; set; } [Required] public string GlobalJsonPath { get; set; } + [Required] public string Platform { get; set; } + [Required] + public string RepoRoot { get; set; } public override bool Execute() { @@ -56,7 +59,14 @@ public override bool Execute() foreach (var runtime in dotnetLocalElement.EnumerateObject()) { var items = GetItemsFromJsonElementArray(runtime, out string runtimeName); - runtimeItems.Add(runtimeName, items); + if (runtimeItems.ContainsKey(runtimeName)) + { + runtimeItems[runtimeName] = runtimeItems[runtimeName].Concat(items); + } + else + { + runtimeItems.Add(runtimeName, items); + } } if (runtimeItems.Count > 0) { @@ -97,16 +107,26 @@ public override bool Execute() if(version != null) { string arguments = $"-runtime \"{runtimeItem.Key}\" -version \"{version.ToNormalizedString()}\""; + string installdir = Path.Combine(RepoRoot, ".dotnet"); + string architecture = item.Value; if (!string.IsNullOrWhiteSpace(architecture)) { arguments += $" -architecture {architecture}"; + if (string.Equals(architecture, "x86", StringComparison.OrdinalIgnoreCase)) + { + installdir = Path.Combine(installdir, "x86"); + } } else { if (!string.IsNullOrWhiteSpace(Platform) && !string.Equals(Platform, "AnyCpu", StringComparison.OrdinalIgnoreCase)) { arguments += $" -architecture {Platform}"; + if (string.Equals(Platform, "x86", StringComparison.OrdinalIgnoreCase)) + { + installdir = Path.Combine(installdir, "x86"); + } } else if (RuntimeInformation.OSArchitecture == Architecture.X86 || RuntimeInformation.OSArchitecture == Architecture.X64) @@ -114,6 +134,8 @@ public override bool Execute() arguments += " -architecture x64"; } } + + arguments += $" -installdir {installdir}"; Log.LogMessage(MessageImportance.Low, $"Executing: {DotNetInstallScript} {arguments}"); var process = Process.Start(new ProcessStartInfo() { diff --git a/src/Microsoft.DotNet.Arcade.Sdk/tools/InstallDotNetCore.targets b/src/Microsoft.DotNet.Arcade.Sdk/tools/InstallDotNetCore.targets index 444a002de7e..b3fe811bc30 100644 --- a/src/Microsoft.DotNet.Arcade.Sdk/tools/InstallDotNetCore.targets +++ b/src/Microsoft.DotNet.Arcade.Sdk/tools/InstallDotNetCore.targets @@ -13,6 +13,7 @@ Command="chmod +x "$(_DotNetInstallScript)"" /> Date: Thu, 16 May 2019 13:56:43 -0700 Subject: [PATCH 3/4] Changing $pl => $platformArg; simplifying $installdir init --- eng/common/build.ps1 | 4 ++-- eng/common/dotnet-install.ps1 | 11 ++--------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/eng/common/build.ps1 b/eng/common/build.ps1 index 10ea57d1f12..67046a43f8c 100644 --- a/eng/common/build.ps1 +++ b/eng/common/build.ps1 @@ -79,7 +79,7 @@ function Build { InitializeCustomToolset $bl = if ($binaryLog) { "/bl:" + (Join-Path $LogDir "Build.binlog") } else { "" } - $pl = if ($platform) { "/p:Platform=$platform" } else { "" } + $platformArg = if ($platform) { "/p:Platform=$platform" } else { "" } if ($projects) { # Re-assign properties to a new variable because PowerShell doesn't let us append properties directly for unclear reasons. @@ -91,7 +91,7 @@ function Build { MSBuild $toolsetBuildProj ` $bl ` - $pl ` + $platformArg ` /p:Configuration=$configuration ` /p:RepoRoot=$RepoRoot ` /p:Restore=$restore ` diff --git a/eng/common/dotnet-install.ps1 b/eng/common/dotnet-install.ps1 index 104530f8f85..d4c4aad127d 100644 --- a/eng/common/dotnet-install.ps1 +++ b/eng/common/dotnet-install.ps1 @@ -4,20 +4,13 @@ Param( [string] $architecture = "", [string] $version = "Latest", [string] $runtime = "dotnet", - [string] $installdir = "" + [string] $installdir = Join-Path $RepoRoot ".dotnet" ) . $PSScriptRoot\tools.ps1 try { - $dotnetRoot = Join-Path $RepoRoot ".dotnet" - - $dotnetInstallLocation = $installdir - if (-not $dotnetInstallLocation) { - $dotnetInstallLocation = $dotnetRoot - } - - InstallDotNet $dotnetInstallLocation $version $architecture $runtime $true + InstallDotNet $installdir $version $architecture $runtime $true } catch { Write-Host $_ From ef8e5c79597af6800bdcf4db3508940e377f51ed Mon Sep 17 00:00:00 2001 From: Vatsan Madhavan Date: Thu, 16 May 2019 16:02:26 -0700 Subject: [PATCH 4/4] Go back to calculating install location in dotnet-install.ps1 (instead of doing this in the Task) Fix condition in XUnit.targets --- eng/common/dotnet-install.ps1 | 9 +++++++-- .../src/InstallDotNetCore.cs | 12 ------------ .../tools/InstallDotNetCore.targets | 1 - .../tools/XUnit/XUnit.targets | 2 +- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/eng/common/dotnet-install.ps1 b/eng/common/dotnet-install.ps1 index d4c4aad127d..0b629b8301a 100644 --- a/eng/common/dotnet-install.ps1 +++ b/eng/common/dotnet-install.ps1 @@ -3,13 +3,18 @@ Param( [string] $verbosity = "minimal", [string] $architecture = "", [string] $version = "Latest", - [string] $runtime = "dotnet", - [string] $installdir = Join-Path $RepoRoot ".dotnet" + [string] $runtime = "dotnet" ) . $PSScriptRoot\tools.ps1 +$dotnetRoot = Join-Path $RepoRoot ".dotnet" + +$installdir = $dotnetRoot try { + if ($architecture -and $architecture.Trim() -eq "x86") { + $installdir = Join-Path $installdir "x86" + } InstallDotNet $installdir $version $architecture $runtime $true } catch { diff --git a/src/Microsoft.DotNet.Arcade.Sdk/src/InstallDotNetCore.cs b/src/Microsoft.DotNet.Arcade.Sdk/src/InstallDotNetCore.cs index 24ba0c41639..4f3cd294623 100644 --- a/src/Microsoft.DotNet.Arcade.Sdk/src/InstallDotNetCore.cs +++ b/src/Microsoft.DotNet.Arcade.Sdk/src/InstallDotNetCore.cs @@ -30,8 +30,6 @@ public class InstallDotNetCore : Task public string GlobalJsonPath { get; set; } [Required] public string Platform { get; set; } - [Required] - public string RepoRoot { get; set; } public override bool Execute() { @@ -107,26 +105,17 @@ public override bool Execute() if(version != null) { string arguments = $"-runtime \"{runtimeItem.Key}\" -version \"{version.ToNormalizedString()}\""; - string installdir = Path.Combine(RepoRoot, ".dotnet"); string architecture = item.Value; if (!string.IsNullOrWhiteSpace(architecture)) { arguments += $" -architecture {architecture}"; - if (string.Equals(architecture, "x86", StringComparison.OrdinalIgnoreCase)) - { - installdir = Path.Combine(installdir, "x86"); - } } else { if (!string.IsNullOrWhiteSpace(Platform) && !string.Equals(Platform, "AnyCpu", StringComparison.OrdinalIgnoreCase)) { arguments += $" -architecture {Platform}"; - if (string.Equals(Platform, "x86", StringComparison.OrdinalIgnoreCase)) - { - installdir = Path.Combine(installdir, "x86"); - } } else if (RuntimeInformation.OSArchitecture == Architecture.X86 || RuntimeInformation.OSArchitecture == Architecture.X64) @@ -135,7 +124,6 @@ public override bool Execute() } } - arguments += $" -installdir {installdir}"; Log.LogMessage(MessageImportance.Low, $"Executing: {DotNetInstallScript} {arguments}"); var process = Process.Start(new ProcessStartInfo() { diff --git a/src/Microsoft.DotNet.Arcade.Sdk/tools/InstallDotNetCore.targets b/src/Microsoft.DotNet.Arcade.Sdk/tools/InstallDotNetCore.targets index b3fe811bc30..444a002de7e 100644 --- a/src/Microsoft.DotNet.Arcade.Sdk/tools/InstallDotNetCore.targets +++ b/src/Microsoft.DotNet.Arcade.Sdk/tools/InstallDotNetCore.targets @@ -13,7 +13,6 @@ Command="chmod +x "$(_DotNetInstallScript)"" /> $(_TargetDir)$(_TargetFileNameNoExt).runtimeconfig.json <_CoreDepsPath>$(_TargetDir)$(_TargetFileNameNoExt).deps.json - <_TestRunner Condition="'$(TestArchitectures)'!='' And '$(TestArchitectures)'!='AnyCpu' And Exists('$(DotNetRoot)$(TestArchitectures)\dotnet.exe')">$(DotNetRoot)$(TestArchitectures)\dotnet.exe + <_TestRunner Condition="'%(TestToRun.Architecture)'=='x86' And Exists('$(DotNetRoot)x86\dotnet.exe')">$(DotNetRoot)x86\dotnet.exe <_TestRunner Condition="'$(_TestRunner)'==''">$(DotNetTool) <_TestRunnerArgs>exec --depsfile "$(_CoreDepsPath)" --runtimeconfig "$(_CoreRuntimeConfigPath)" $(TestRuntimeAdditionalArguments) "$(NuGetPackageRoot)xunit.runner.console/$(XUnitVersion)/tools/$(_TestRunnerTargetFramework)/xunit.console.dll" "$(_TestAssembly)" -noautoreporters -xml "%(TestToRun.ResultsXmlPath)" -html "%(TestToRun.ResultsHtmlPath)" $(_TestRunnerAdditionalArguments)