Skip to content

Commit

Permalink
Installing sdk/runtime defined by Universe (#360)
Browse files Browse the repository at this point in the history
Fixes the current regressions due to the wrong shared runtime used.
Uses the official way to install specific SDKs and runtimes.
Loads the runtime and sdk versions specified in Coherence Universe repos, when targeting 2.1-*
  • Loading branch information
sebastienros committed Dec 19, 2017
1 parent aabd3b1 commit 4597c5f
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 40 deletions.
1 change: 0 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

<Import Project="version.props" />
<Import Project="build\dependencies.props" />
<Import Project="build\compiler.props" />

<PropertyGroup>
<Product>Microsoft ASP.NET Core</Product>
Expand Down
6 changes: 6 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project>
<PropertyGroup>
<RuntimeFrameworkVersion Condition=" '$(TargetFramework)' == 'netcoreapp2.0' ">$(MicrosoftNETCoreApp20PackageVersion)</RuntimeFrameworkVersion>
<RuntimeFrameworkVersion Condition=" '$(TargetFramework)' == 'netcoreapp2.1' ">$(MicrosoftNETCoreApp21PackageVersion)</RuntimeFrameworkVersion>
</PropertyGroup>
</Project>
1 change: 1 addition & 0 deletions NuGet.Config
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<configuration>
<packageSources>
<clear />
<add key="DotnetCore" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
<add key="AspNetCore" value="https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json" />
<add key="AspNetCoreTools" value="https://dotnet.myget.org/F/aspnetcore-tools/api/v3/index.json" />
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
Expand Down
15 changes: 0 additions & 15 deletions build/compiler.props

This file was deleted.

10 changes: 7 additions & 3 deletions build/dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
<InternalAspNetCoreSdkVersion>2.1.1-*</InternalAspNetCoreSdkVersion>
<JsonNetVersion>10.0.1</JsonNetVersion>
<JilVersion>2.15.4</JilVersion>
<NETStandardImplicitPackageVersion>2.0.0-*</NETStandardImplicitPackageVersion>
<NETCoreAppImplicitPackageVersion>2.0.0-*</NETCoreAppImplicitPackageVersion>
<NETStandardImplicitPackageVersion>2.0.0</NETStandardImplicitPackageVersion>
<NETCoreAppImplicitPackageVersion>2.0.0</NETCoreAppImplicitPackageVersion>
<MicrosoftNETCoreApp20PackageVersion>2.0.0</MicrosoftNETCoreApp20PackageVersion>
<MicrosoftNETCoreApp21PackageVersion>2.1.0-preview1-26016-05</MicrosoftNETCoreApp21PackageVersion>
<RuntimeFrameworkVersion>2.0.0-*</RuntimeFrameworkVersion>
<DefaultTargetFramework>netcoreapp2.0</DefaultTargetFramework>

<!--
Following properties are specific to src/Benchmarks/Benchmarks.csproj.
Separate to ease testing of earlier releases.
-->
<BenchmarksTargetFramework>$(DefaultTargetFramework)</BenchmarksTargetFramework>
<BenchmarksAspNetCoreVersion>$(AspNetCoreVersion)</BenchmarksAspNetCoreVersion>
<BenchmarksNETCoreAppImplicitPackageVersion>$(NETCoreAppImplicitPackageVersion)</BenchmarksNETCoreAppImplicitPackageVersion>
<BenchmarksNETStandardImplicitPackageVersion>$(NETStandardImplicitPackageVersion)</BenchmarksNETStandardImplicitPackageVersion>
<BenchmarksNETCoreAppImplicitPackageVersion>$(NETCoreAppImplicitPackageVersion)</BenchmarksNETCoreAppImplicitPackageVersion>
<BenchmarksRuntimeFrameworkVersion>$(RuntimeFrameworkVersion)</BenchmarksRuntimeFrameworkVersion>
<MongoDbVersion>2.*</MongoDbVersion>
<DapperVersion>1.*</DapperVersion>
Expand Down
8 changes: 8 additions & 0 deletions build/repo.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project>
<Import Project="dependencies.props" />

<ItemGroup>
<DotNetCoreRuntime Include="$(MicrosoftNETCoreApp20PackageVersion)" />
<DotNetCoreRuntime Include="$(MicrosoftNETCoreApp21PackageVersion)" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions src/Benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>$(BenchmarksTargetFramework)</TargetFramework>
<OutputType>Exe</OutputType>
<MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
<NETCoreAppImplicitPackageVersion>$(BenchmarksNETCoreAppImplicitPackageVersion)</NETCoreAppImplicitPackageVersion>
<RuntimeFrameworkVersion>$(BenchmarksRuntimeFrameworkVersion)</RuntimeFrameworkVersion>
<RuntimeFrameworkVersion>$(BenchmarksNETCoreAppImplicitPackageVersion)</RuntimeFrameworkVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(BenchmarksAspNetCoreVersion)' == '2.1.0-*'">
Expand Down
8 changes: 6 additions & 2 deletions src/BenchmarksClient/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ private static async Task ProcessJobs(CancellationToken cancellationToken)

Debug.Assert(process == null);

MeasureFirstRequestLatency(job);

Log($"Running job {jobLogText}");
job.State = ClientState.Running;
job.RunningSince = DateTime.UtcNow;

MeasureFirstRequestLatency(job);

process = StartProcess(job);
}
else if (job.State == ClientState.Running)
Expand Down Expand Up @@ -214,6 +214,8 @@ private static void MeasureFirstRequestLatency(ClientJob job)
job.LatencyFirstRequest = stopwatch.Elapsed;
}

Log(job.LatencyFirstRequest.ToString());

Log("Measuring single connection latency");

for (var i = 0; i < 10; i++)
Expand All @@ -228,6 +230,8 @@ private static void MeasureFirstRequestLatency(ClientJob job)
job.LatencyNoLoad = stopwatch.Elapsed;
}
}

Log(job.LatencyNoLoad.ToString());
}

private static Process StartProcess(ClientJob job)
Expand Down
5 changes: 3 additions & 2 deletions src/BenchmarksDriver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ Options:
BenchmarksAspNetCoreVersion Set to the value of --aspnetCoreVersion
BenchmarksNETStandardImplicitPackageVersion Set to the value of --aspnetCoreVersion
BenchmarksNETCoreAppImplicitPackageVersion Set to the value of --aspnetCoreVersion
BenchmarksRuntimeFrameworkVersion Set to 2.0.0
BenchmarksRuntimeFrameworkVersion Set to 2.0.3 or 2.1.0-*
BenchmarksTargetFramework Set to netcoreapp2.0 or netcoreapp2.1
```

### Sample project file
Expand All @@ -137,7 +138,7 @@ This demonstrate how `msbuild` parameters can be used in a benchmarked applicati
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>$(BenchmarksTargetFramework)</TargetFramework>
<OutputType>Exe</OutputType>
<MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
<NETCoreAppImplicitPackageVersion>$(BenchmarksNETCoreAppImplicitPackageVersion)</NETCoreAppImplicitPackageVersion>
Expand Down
69 changes: 54 additions & 15 deletions src/BenchmarksServer/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Runtime.InteropServices;
Expand All @@ -31,8 +30,11 @@ public class Startup
{
private static readonly HttpClient _httpClient;
private static readonly HttpClientHandler _httpClientHandler;
private const string _buildToolsRepoUrl = "https://raw.githubusercontent.com/aspnet/BuildTools/dev/scripts/bootstrapper/";
private static readonly string[] _buildToolsFiles = new string[] { "build.cmd", "build.sh", "run.cmd", "run.ps1", "run.sh" };
private static readonly string _dotnetInstallRepoUrl = "https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain/";
private static readonly string[] _dotnetInstallPaths = new string[] { "dotnet-install.sh", "dotnet-install.ps1" };
private static readonly string _sdkVersionUrl = "https://raw.githubusercontent.com/aspnet/BuildTools/dev/files/KoreBuild/config/sdk.version";
private static readonly string _universeDependenciesUrl = "https://raw.githubusercontent.com/aspnet/Universe/dev/build/dependencies.props";

private const string _defaultUrl = "http://*:5001";
private static readonly string _defaultHostname = Environment.MachineName.ToLowerInvariant();

Expand Down Expand Up @@ -531,19 +533,14 @@ private static async Task<string> CloneRestoreAndBuild(string path, ServerJob jo

Debug.Assert(benchmarkedDir != null);

// on windows dotnet is installed into subdirectory of 'dotnetHome' so we have to append 'x64'
string dotnetExeLocation = OperatingSystem == OperatingSystem.Windows
? Path.Combine(dotnetHome, "x64")
: dotnetHome;

var env = new Dictionary<string, string>
{
// for repos using the latest build tools from aspnet/BuildTools
["DOTNET_HOME"] = dotnetHome,
// for backward compatibility with aspnet/KoreBuild
["DOTNET_INSTALL_DIR"] = dotnetHome,
// temporary for custom compiler to find right dotnet
["PATH"] = dotnetExeLocation + Path.PathSeparator + Environment.GetEnvironmentVariable("PATH")
["PATH"] = dotnetHome + Path.PathSeparator + Environment.GetEnvironmentVariable("PATH")
};

// Source dependencies are always built using KoreBuild
Expand All @@ -562,11 +559,30 @@ private static async Task<string> CloneRestoreAndBuild(string path, ServerJob jo

// Computes the location of the benchmarked app
var benchmarkedApp = Path.Combine(path, benchmarkedDir, Path.GetDirectoryName(job.Source.Project));
string targetFramework = "netcoreapp2.0";
string runtimeFrameworkVersion = "2.0.3";

// Downloading latest SDK version
var sdkVersionPath = Path.Combine(buildToolsPath, Path.GetFileName(_sdkVersionUrl));
await DownloadFileAsync(_sdkVersionUrl, sdkVersionPath, maxRetries: 5);
var sdkVersion = File.ReadAllText(sdkVersionPath);
Log.WriteLine($"Detecting latest SDK version: {sdkVersion}");

var universeDependenciesPath = Path.Combine(buildToolsPath, Path.GetFileName(_universeDependenciesUrl));
await DownloadFileAsync(_universeDependenciesUrl, universeDependenciesPath, maxRetries: 5);
var latestRuntimeVersion = XDocument.Load(universeDependenciesPath).Root
.Element("PropertyGroup")
.Element("MicrosoftNETCoreApp21PackageVersion")
.Value;
Log.WriteLine($"Detecting Universe Coherence runtime version: {latestRuntimeVersion}");

// Defines which SDK will be installed. Using "" downloads the latest SDK.
if (job.AspNetCoreVersion == "2.1.0-*")
{
env["KOREBUILD_DOTNET_VERSION"] = "";
File.WriteAllText(Path.Combine(benchmarkedApp, "global.json"), "{ }");
targetFramework = "netcoreapp2.1";
runtimeFrameworkVersion = "2.1.0-*";
}
else
{
Expand All @@ -578,15 +594,37 @@ private static async Task<string> CloneRestoreAndBuild(string path, ServerJob jo

if (OperatingSystem == OperatingSystem.Windows)
{
ProcessUtil.Run("cmd", "/c build.cmd /t:noop",
// Install latest stable 2.0 SDK version (and associated runtime)
ProcessUtil.Run("powershell", $"-NoProfile -ExecutionPolicy unrestricted .\\dotnet-install.ps1 -Channel Current",
workingDirectory: buildToolsPath,
environmentVariables: env);

// Install latest SDK version (and associated runtime)
ProcessUtil.Run("powershell", $"-NoProfile -ExecutionPolicy unrestricted .\\dotnet-install.ps1 -Version {sdkVersion}",
workingDirectory: buildToolsPath,
environmentVariables: env);

// Install runtime required by coherence universe
ProcessUtil.Run("powershell", $"-NoProfile -ExecutionPolicy unrestricted .\\dotnet-install.ps1 -Version {latestRuntimeVersion} -SharedRuntime",
workingDirectory: buildToolsPath,
environmentVariables: env);
}
else
{
ProcessUtil.Run("/usr/bin/env", "bash build.sh /t:noop",
// Install latest stable 2.0 SDK version (and associated runtime)
ProcessUtil.Run("/usr/bin/env", $"bash dotnet-install.sh --channel Current",
workingDirectory: buildToolsPath,
environmentVariables: env);

// Install latest SDK version (and associated runtime)
ProcessUtil.Run("/usr/bin/env", $"bash dotnet-install.sh --version {sdkVersion}",
workingDirectory: buildToolsPath,
environmentVariables: env);

// Install runtime required by coherence universe
ProcessUtil.Run("/usr/bin/env", $"bash dotnet-install.sh --version {latestRuntimeVersion} --shared-runtime",
workingDirectory: buildToolsPath,
environmentVariables: env);
}

// Build and Restore
Expand All @@ -598,7 +636,8 @@ private static async Task<string> CloneRestoreAndBuild(string path, ServerJob jo
var buildParameters = $"/p:BenchmarksAspNetCoreVersion={job.AspNetCoreVersion} " +
$"/p:BenchmarksNETStandardImplicitPackageVersion={job.AspNetCoreVersion} " +
$"/p:BenchmarksNETCoreAppImplicitPackageVersion={job.AspNetCoreVersion} " +
$"/p:BenchmarksRuntimeFrameworkVersion=2.0.0 ";
$"/p:BenchmarksRuntimeFrameworkVersion={runtimeFrameworkVersion} " +
$"/p:BenchmarksTargetFramework={targetFramework} ";

ProcessUtil.Run(dotnetExecutable, $"restore /p:VersionSuffix=zzzzz-99999 {buildParameters}",
workingDirectory: benchmarkedApp,
Expand Down Expand Up @@ -634,9 +673,9 @@ private static async Task DownloadBuildTools(string buildToolsPath)

const int maxRetries = 5;

foreach (var file in _buildToolsFiles)
foreach (var file in _dotnetInstallPaths)
{
var url = _buildToolsRepoUrl + file;
var url = _dotnetInstallRepoUrl + file;

// If any of the files completely fails to download the entire thing will fail
var path = Path.Combine(buildToolsPath, file);
Expand Down Expand Up @@ -840,7 +879,7 @@ private static void DeleteDir(string path)
private static string GetDotNetExecutable(string dotnetHome)
{
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? Path.Combine(dotnetHome, RuntimeInformation.ProcessArchitecture.ToString(), "dotnet.exe")
? Path.Combine(dotnetHome, "dotnet.exe")
: Path.Combine(dotnetHome, "dotnet");
}

Expand Down

0 comments on commit 4597c5f

Please sign in to comment.