Skip to content

Commit

Permalink
Core: new toolchain implementation with dnx451 code reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsitnik committed Mar 5, 2016
1 parent ab8b265 commit 9e13722
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 26 deletions.
1 change: 1 addition & 0 deletions .nuget/NuGet.Config
Expand Up @@ -5,5 +5,6 @@
</solution>
<packageSources>
<add key="fsprojects" value="https://www.myget.org/F/fsprojects/api/v3/index.json" />
<add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
</packageSources>
</configuration>
1 change: 1 addition & 0 deletions BenchmarkDotNet.Samples/project.json
Expand Up @@ -25,6 +25,7 @@
"define": [ "CORE" ]
},
"dependencies": {
"NETStandard.Library": "1.0.0-rc2-23811",
"System.Security.Cryptography.Hashing.Algorithms": "4.0.0-beta-23225"
}
}
Expand Down
3 changes: 2 additions & 1 deletion BenchmarkDotNet/Portability/RuntimeInformation.cs
Expand Up @@ -10,6 +10,8 @@ namespace BenchmarkDotNet.Portability
{
internal class RuntimeInformation
{
internal static string ExecutableExtension => IsWindows() ? ".exe" : string.Empty;

internal static bool IsWindows()
{
#if !CORE
Expand Down Expand Up @@ -81,6 +83,5 @@ internal static string GetClrVersion()
return "CORE"; // TODO: verify if it is possible to get this for CORE
#endif
}

}
}
7 changes: 3 additions & 4 deletions BenchmarkDotNet/Templates/BenchmarkProject.json
Expand Up @@ -15,11 +15,10 @@
"run": "BenchmarkDotNet.Autogenerated"
},

$REQUIREDDEPENDENCY$,

"frameworks": {
"dnx451": {
"frameworkAssemblies": {
"System.Runtime": "4.0.10.0"
},
"$TFM$": {
"dependencies": {
"$EXECUTINGASSEMBLY$": {
"version": "$EXECUTINGASSEMBLYVERSION$",
Expand Down
11 changes: 8 additions & 3 deletions BenchmarkDotNet/Toolchains/Core/CoreToolchain.cs
@@ -1,15 +1,20 @@
using BenchmarkDotNet.Toolchains.Classic;
using BenchmarkDotNet.Toolchains.Dnx;
using BenchmarkDotNet.Toolchains.DotNetCli;

namespace BenchmarkDotNet.Toolchains.Core
{
public class CoreToolchain : Toolchain
{
private const string TargetFrameworkMoniker = "dnxcore50"; // todo: when dnx gets replaced in VS with dotnet cli replace this name with fancy dotnet5.4 name

public static readonly IToolchain Instance = new CoreToolchain();

private CoreToolchain() : base("Core", new DnxGenerator(), new DnxBuilder(), new ClassicExecutor())
private CoreToolchain()
: base("Core",
new DotNetCliGenerator(TargetFrameworkMoniker),
new DotNetCliBuilder(TargetFrameworkMoniker),
new ClassicExecutor())
{
// todo: implement the toolchain
}
}
}
9 changes: 8 additions & 1 deletion BenchmarkDotNet/Toolchains/Dnx/DnxToolchain.cs
@@ -1,12 +1,19 @@
using BenchmarkDotNet.Toolchains.Classic;
using BenchmarkDotNet.Toolchains.DotNetCli;

namespace BenchmarkDotNet.Toolchains.Dnx
{
public class DnxToolchain : Toolchain
{
private const string TargetFrameworkMoniker = "dnx451";

public static readonly IToolchain Instance = new DnxToolchain();

private DnxToolchain() : base("Dnx", new DnxGenerator(), new DnxBuilder(), new ClassicExecutor())
private DnxToolchain()
: base("Dnx",
new DotNetCliGenerator(TargetFrameworkMoniker),
new DotNetCliBuilder(TargetFrameworkMoniker),
new ClassicExecutor())
{
}
}
Expand Down
Expand Up @@ -2,28 +2,34 @@
using System.Diagnostics;
using System.IO;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Portability;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Toolchains.Results;

namespace BenchmarkDotNet.Toolchains.Dnx
namespace BenchmarkDotNet.Toolchains.DotNetCli
{
public class DnxBuilder : IBuilder
public class DotNetCliBuilder : IBuilder
{
private static readonly int DefaultTimeout = (int)TimeSpan.FromMinutes(2).TotalMilliseconds;
private const string Configuration = "RELEASE";

private const string OutputDirectory = "binaries";

private string Framework { get; } = "dnx451";
private static readonly int DefaultTimeout = (int)TimeSpan.FromMinutes(2).TotalMilliseconds;

private string Configuration { get; } = "RELEASE";
private string Framework { get; }

private string OutputDirectory { get; } = "binaries";
public DotNetCliBuilder(string framework)
{
Framework = framework;
}

/// <summary>
/// generates project.lock.json that tells compiler where to take dlls and source from
/// and builds executable and copies all required dll's
/// </summary>
public BuildResult Build(GenerateResult generateResult, ILogger logger, Benchmark benchmark)
{
if (!ExecuteCommand("restore", generateResult.DirectoryPath, logger))
if (!ExecuteCommand("restore --fallbacksource https://dotnet.myget.org/F/dotnet-core/api/v3/index.json", generateResult.DirectoryPath, logger))
{
return new BuildResult(generateResult, false, new Exception("dotnet restore has failed"), null);
}
Expand Down Expand Up @@ -88,6 +94,6 @@ private static ProcessStartInfo BuildStartInfo(string workingDirectory, string a
/// we use custom output path in order to avoid any future problems related to dotnet cli paths changing
/// </summary>
private string BuildExecutablePath(GenerateResult generateResult, Benchmark benchmark)
=> Path.Combine(generateResult.DirectoryPath, OutputDirectory, $"{benchmark.ShortInfo}.exe");
=> Path.Combine(generateResult.DirectoryPath, OutputDirectory, $"{benchmark.ShortInfo}{RuntimeInformation.ExecutableExtension}");
}
}
Expand Up @@ -5,16 +5,23 @@
using BenchmarkDotNet.Helpers;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Portability;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Toolchains.Classic;
using BenchmarkDotNet.Portability;

namespace BenchmarkDotNet.Toolchains.Dnx
namespace BenchmarkDotNet.Toolchains.DotNetCli
{
internal class DnxGenerator : ClassicGenerator
internal class DotNetCliGenerator : ClassicGenerator
{
private const string ProjectFileName = "project.json";

private string TargetFrameworkMoniker { get; }

public DotNetCliGenerator(string targetFrameworkMoniker)
{
TargetFrameworkMoniker = targetFrameworkMoniker;
}

/// <summary>
/// we need our folder to be on the same level as the project that we want to reference
/// we are limited by xprojs (by default compiles all .cs files in all subfolders, Program.cs could be doubled and fail the build)
Expand All @@ -34,7 +41,9 @@ protected override void GenerateProjectFile(ILogger logger, string projectDir, B

var content = SetPlatform(template, benchmark.Job.Platform);
content = SetDependencyToExecutingAssembly(content, benchmark.Target.Type);

content = SetTargetFrameworkMoniker(content, TargetFrameworkMoniker);
content = SetExtraDependencies(content);

var projectJsonFilePath = Path.Combine(projectDir, ProjectFileName);

File.WriteAllText(projectJsonFilePath, content);
Expand All @@ -60,6 +69,20 @@ private static string SetDependencyToExecutingAssembly(string template, Type ben
.Replace("$EXECUTINGASSEMBLY$", assemblyName.Name);
}

private static string SetTargetFrameworkMoniker(string content, string targetFrameworkMoniker)
{
return content.Replace("$TFM$", targetFrameworkMoniker);
}

private static string SetExtraDependencies(string content)
{
#if CORE
return content.Replace("$REQUIREDDEPENDENCY$", "\"dependencies\": { \"NETStandard.Library\": \"1.0.0-rc2-23811\" }");
#else
return content.Replace("$REQUIREDDEPENDENCY$", "\"frameworkAssemblies\": { \"System.Runtime\": \"4.0.10.0\" }");
#endif
}

/// <summary>
/// we can not simply call assemblyName.Version.ToString() because it is different than package version which can contain (and often does) text
/// we are using the wildcard to get latest version of package/project restored
Expand Down
15 changes: 10 additions & 5 deletions BenchmarkDotNet/project.json
Expand Up @@ -54,14 +54,19 @@
"define": [ "CORE" ]
},
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"NETStandard.Library": "1.0.0-rc2-23811",
"Microsoft.CSharp": "4.0.0",
"System.Collections": "4.0.10",
"System.Console": "4.0.0-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Threading": "4.0.11-beta-23516",
"System.Linq": "4.0.0",
"System.Threading": "4.0.10",
"System.Threading.Thread": "4.0.0-beta-23516",
"System.Diagnostics.Process": "4.1.0-beta-23516",
"System.IO.FileSystem": "4.0.1-beta-23516",
"System.IO": "4.0.10",
"System.IO.FileSystem.Primitives": "4.0.0",
"System.IO.FileSystem": "4.0.0",
"System.Runtime": "4.0.20",
"System.Runtime.Extensions": "4.0.10",
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0-beta-23516"
}
}
Expand Down

0 comments on commit 9e13722

Please sign in to comment.