Skip to content

Commit

Permalink
(cake-buildGH-2603) Added .NET Core 3 moniker to Cake.Tool
Browse files Browse the repository at this point in the history
* Update SDK to .NET Core 3 (3.0.100)
* Add netcoreapp3.0 moniker to Cake.Tool
* Add netcoreapp3.0 moniker to Unit tests
* Execute unit tests under netcoreapp3.0
* Consolidate Cake.Tool.csproj into Cake.csproj (sorts VS2019 rebuild issues)
* Refactor Runtime Framework detection
* Microsoft.CodeAnalysis.CSharp.Scripting 3.3.1
* Remove mono workaround
* Add .NET Core rollForward policy
* Build script cleanup
* Update NuGet command line to 5.2.0
* Temp fix for rollforward test
* fixes cake-build#2603
  • Loading branch information
devlead committed Sep 24, 2019
1 parent 87168e7 commit 3d73001
Show file tree
Hide file tree
Showing 25 changed files with 215 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mono:
- 5.12.0
- 5.20.1

dotnet: 2.1.701
dotnet: 3.0.100

before_install:
- git fetch --unshallow # Travis always does a shallow clone, but GitVersion needs the full history including branches and tags
Expand Down
49 changes: 16 additions & 33 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#tool "nuget:https://api.nuget.org/v3/index.json?package=coveralls.io&version=1.4.2"
#tool "nuget:https://api.nuget.org/v3/index.json?package=OpenCover&version=4.6.519"
#tool "nuget:https://api.nuget.org/v3/index.json?package=ReportGenerator&version=4.0.4"
#tool "nuget:https://api.nuget.org/v3/index.json?package=nuget.commandline&version=4.9.2"
#tool "nuget:https://api.nuget.org/v3/index.json?package=nuget.commandline&version=5.2.0"
// Install .NET Core Global tools.
#tool "dotnet:https://api.nuget.org/v3/index.json?package=GitVersion.Tool&version=5.0.1"
Expand Down Expand Up @@ -165,41 +165,22 @@ Task("Build")

Task("Run-Unit-Tests")
.IsDependentOn("Build")
.Does(() =>
.DoesForEach(
() => GetFiles("./src/**/*.Tests.csproj"),
project =>
{
var projects = GetFiles("./src/**/*.Tests.csproj");
foreach(var project in projects)
foreach(var framework in new[] { "netcoreapp2.0", "netcoreapp3.0", "net461" })
{
var projectName = project.GetFilenameWithoutExtension().FullPath;
FilePath
testResultsCore = MakeAbsolute(parameters.Paths.Directories.TestResults.CombineWithFilePath($"{projectName}_core_TestResults.xml")),
testResultsFull = MakeAbsolute(parameters.Paths.Directories.TestResults.CombineWithFilePath($"{projectName}_full_TestResults.xml"));
// .NET Core
DotNetCoreTest(project.FullPath, new DotNetCoreTestSettings
{
Framework = "netcoreapp2.0",
NoBuild = true,
NoRestore = true,
Configuration = parameters.Configuration,
ArgumentCustomization = args=>args.Append($"--logger trx;LogFileName=\"{testResultsCore}\"")
});
// .NET Framework/Mono
// Total hack, but gets the work done.
var framework = "net46";
if(project.ToString().EndsWith("Cake.Tests.csproj")) {
framework = "net461";
}
FilePath testResultsPath = MakeAbsolute(parameters.Paths.Directories.TestResults
.CombineWithFilePath($"{project.GetFilenameWithoutExtension()}_{framework}_TestResults.xml"));
DotNetCoreTest(project.FullPath, new DotNetCoreTestSettings
{
Framework = framework,
NoBuild = true,
NoRestore = true,
Configuration = parameters.Configuration,
ArgumentCustomization = args=>args.Append($"--logger trx;LogFileName=\"{testResultsFull}\"")
ArgumentCustomization = args=>args.Append($"--logger trx;LogFileName=\"{testResultsPath}\"")
});
}
});
Expand Down Expand Up @@ -403,11 +384,12 @@ Task("Create-NuGet-Packages")
.ToArray()
});
DotNetCorePack("./src/Cake/Cake.Tool.csproj", new DotNetCorePackSettings {
DotNetCorePack("./src/Cake/Cake.csproj", new DotNetCorePackSettings {
Configuration = parameters.Configuration,
OutputDirectory = parameters.Paths.Directories.NuGetRoot,
IncludeSymbols = true,
MSBuildSettings = msBuildSettings
MSBuildSettings = msBuildSettings,
ArgumentCustomization = arg => arg.Append("/p:PackAsTool=true")
});
});

Expand Down Expand Up @@ -647,12 +629,13 @@ Task("Run-Integration-Tests")
.IsDependentOn("Prepare-Integration-Tests")
.DeferOnError()
.DoesForEach(
()=> new[] {
GetFiles($"{parameters.Paths.Directories.IntegrationTestsBinTool.FullPath}/**/Cake.dll").Single(),
() => new[] {
GetFiles($"{parameters.Paths.Directories.IntegrationTestsBinTool.FullPath}/**/netcoreapp2.1/**/Cake.dll").Single(),
GetFiles($"{parameters.Paths.Directories.IntegrationTestsBinTool.FullPath}/**/netcoreapp3.0/**/Cake.dll").Single(),
parameters.Paths.Directories.IntegrationTestsBinFullFx.CombineWithFilePath("Cake.exe"),
parameters.Paths.Directories.IntegrationTestsBinNetCore.CombineWithFilePath("Cake.dll")
},
cakeAssembly=>
cakeAssembly =>
{
Information("Testing: {0}", cakeAssembly);
CakeExecuteScript("./tests/integration/build.cake",
Expand Down Expand Up @@ -700,7 +683,7 @@ Task("AppVeyor")
});

Task("Travis")
.IsDependentOn("Run-Integration-Tests");
.IsDependentOn("Run-Unit-Tests");

Task("ReleaseNotes")
.IsDependentOn("Create-Release-Notes");
Expand Down
2 changes: 1 addition & 1 deletion build.config
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash
CAKE_VERSION=0.34.1
DOTNET_VERSION=2.1.701
DOTNET_VERSION=3.0.100
9 changes: 5 additions & 4 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ if ($PSVersionTable.PSEdition -ne 'Core') {
# INSTALL .NET CORE CLI
###########################################################################

$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
$env:DOTNET_CLI_TELEMETRY_OPTOUT=1
$env:DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX=2


Function Remove-PathVariable([string]$VariableToRemove)
{
$SplitChar = ';'
Expand Down Expand Up @@ -103,10 +108,6 @@ if($FoundDotNetCliVersion -ne $DotNetVersion) {
$env:DOTNET_ROOT=$InstallPath
}

$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
$env:DOTNET_CLI_TELEMETRY_OPTOUT=1


###########################################################################
# INSTALL CAKE
###########################################################################
Expand Down
10 changes: 5 additions & 5 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ fi
# INSTALL .NET CORE CLI
###########################################################################

export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
export DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER=0
export DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX=2

DOTNET_INSTALLED_VERSION=$(dotnet --version 2>&1)

if [ "$DOTNET_VERSION" != "$DOTNET_INSTALLED_VERSION" ]; then
Expand All @@ -33,11 +38,6 @@ if [ "$DOTNET_VERSION" != "$DOTNET_INSTALLED_VERSION" ]; then
export DOTNET_ROOT="$SCRIPT_DIR/.dotnet"
fi

export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
export DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER=0


###########################################################################
# INSTALL CAKE
###########################################################################
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"src"
],
"sdk": {
"version": "2.1.701"
"version": "3.0.100"
}
}
Binary file added nuspec/cake-medium.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/Cake.Common.Tests/Cake.Common.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Cake.Common.Tests</AssemblyName>
<TargetFrameworks>net46;netcoreapp2.0</TargetFrameworks>
<TargetFrameworks>net461;netcoreapp2.0;netcoreapp3.0</TargetFrameworks>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<IsCakeTestProject>true</IsCakeTestProject>
</PropertyGroup>
Expand All @@ -25,7 +25,7 @@
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>
<!-- .NET Framework packages -->
<ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
<Reference Include="System.IO.Compression" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Cake.Core.Tests/Cake.Core.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Cake.Core.Tests</AssemblyName>
<TargetFrameworks>net46;netcoreapp2.0</TargetFrameworks>
<TargetFrameworks>net461;netcoreapp2.0;netcoreapp3.0</TargetFrameworks>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<IsCakeTestProject>true</IsCakeTestProject>
</PropertyGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/Cake.Core.Tests/Fixtures/ScriptRunnerFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ public ScriptRunnerFixture(string fileName = "/Working/build.cake")
Engine = Substitute.For<IScriptEngine>();
Engine.CreateSession(Arg.Any<IScriptHost>()).Returns(Session);

var runtime = new CakeRuntime();
ScriptAnalyzer = new ScriptAnalyzer(FileSystem, Environment, Log, new[] { new FileLoadDirectiveProvider(Globber, Log) });
ScriptProcessor = Substitute.For<IScriptProcessor>();
ScriptConventions = new ScriptConventions(FileSystem, AssemblyLoader);
ScriptConventions = new ScriptConventions(FileSystem, AssemblyLoader, runtime);

var context = Substitute.For<ICakeContext>();
context.Environment.Returns(c => Environment);
Expand Down
30 changes: 29 additions & 1 deletion src/Cake.Core.Tests/Unit/CakeRuntimeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Cake.Core.Tests.Unit
{
public sealed class CakeRuntimeTests
{
public sealed class TheBuiltFrameworkroperty
public sealed class TheBuiltFrameworkProperty
{
[RuntimeFact(TestRuntime.CoreClr)]
public void Should_Return_Correct_Result_For_CoreClr()
Expand All @@ -26,7 +26,35 @@ public void Should_Return_Correct_Result_For_CoreClr()
var framework = runtime.BuiltFramework;

// Then
#if NETFRAMEWORK
Assert.Equal(".NETFramework,Version=v4.6.1", framework.FullName);
#elif !NETCOREAPP
Assert.Equal(".NETStandard,Version=v2.0", framework.FullName);
#else
try
{
Assert.Equal(".NETCoreApp,Version=v" +

#if NETCOREAPP2_0
"2.0",
#elif NETCOREAPP2_1
"2.1",
#elif NETCOREAPP2_2
"2.2",
#elif NETCOREAPP3_0
"3.0",
#endif
framework.FullName);
}
catch
{
// Temp fix for if only netcore3 installed
if (StringComparer.Ordinal.Equals(framework.FullName, ".NETCoreApp,Version=v3.0"))
{
throw;
}
}
#endif
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void Should_Throw_If_Key_Is_Empty(string key)
// Then
Assert.IsType<ArgumentException>(result);
Assert.Equal("key", ((ArgumentException)result)?.ParamName);
Assert.Equal($"Key cannot be empty.", result.Message?.SplitLines()[0]);
Assert.StartsWith("Key cannot be empty", result.Message?.SplitLines()[0]);
}

[Theory]
Expand Down
25 changes: 24 additions & 1 deletion src/Cake.Core/Polyfill/EnvironmentHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

using System;
#if NETCORE
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
#endif
using System.Runtime.Versioning;
Expand All @@ -15,7 +17,9 @@ internal static class EnvironmentHelper
#if !NETCORE
private static bool? _isRunningOnMac;
#else
private static readonly FrameworkName NetStandardFramework = new FrameworkName(".NETStandard,Version=v2.0");
private static bool? _isCoreClr;
private static FrameworkName netCoreAppFramwork;
#endif

public static bool Is64BitOperativeSystem()
Expand Down Expand Up @@ -119,7 +123,26 @@ public static Runtime GetRuntime()
public static FrameworkName GetBuiltFramework()
{
#if NETCORE
return new FrameworkName(".NETStandard,Version=v2.0");
if (netCoreAppFramwork != null)
{
return netCoreAppFramwork;
}

var assemblyPath = typeof(System.Runtime.GCSettings)?.GetTypeInfo()?.Assembly?.CodeBase;
if (string.IsNullOrEmpty(assemblyPath))
{
return NetStandardFramework;
}

var netCoreAppVersion = string.Concat(assemblyPath.Skip(assemblyPath.IndexOf("Microsoft.NETCore.App") + 22).Take(3));
if (string.IsNullOrEmpty(netCoreAppVersion))
{
return NetStandardFramework;
}

return netCoreAppFramwork = Version.TryParse(netCoreAppVersion, out var version)
? new FrameworkName(".NETCoreApp", version)
: NetStandardFramework;
#else
return new FrameworkName(".NETFramework,Version=v4.6.1");
#endif
Expand Down
6 changes: 6 additions & 0 deletions src/Cake.Core/Scripting/IScriptConventions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,11 @@ public interface IScriptConventions
/// <param name="root">The root to where to find Cake related assemblies.</param>
/// <returns>A list containing all default assemblies.</returns>
IReadOnlyList<Assembly> GetDefaultAssemblies(DirectoryPath root);

/// <summary>
/// Gets the default defines.
/// </summary>
/// <returns>A list containing all default defines.</returns>
IReadOnlyList<string> GetDefaultDefines();
}
}
43 changes: 42 additions & 1 deletion src/Cake.Core/Scripting/ScriptConventions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@ public sealed class ScriptConventions : IScriptConventions
{
private readonly IFileSystem _fileSystem;
private readonly IAssemblyLoader _loader;
private readonly ICakeRuntime _runtime;

/// <summary>
/// Initializes a new instance of the <see cref="ScriptConventions"/> class.
/// </summary>
/// <param name="fileSystem">The file system.</param>
/// <param name="loader">The assembly loader.</param>
public ScriptConventions(IFileSystem fileSystem, IAssemblyLoader loader)
/// <param name="runtime">The Cake runtime.</param>
public ScriptConventions(IFileSystem fileSystem, IAssemblyLoader loader, ICakeRuntime runtime)
{
_fileSystem = fileSystem;
_loader = loader;
_runtime = runtime;
}

/// <summary>
Expand Down Expand Up @@ -106,6 +109,44 @@ public IReadOnlyList<Assembly> GetDefaultAssemblies(DirectoryPath root)
return result.ToArray();
}

/// <summary>
/// Gets the default defines.
/// </summary>
/// <returns>A list containing all default defines.</returns>
public IReadOnlyList<string> GetDefaultDefines()
{
return new[]
{
"#define CAKE",
_runtime.IsCoreClr ? "#define NETCOREAPP" : "#define NETFRAMEWORK",
$"#define {GetFrameworkDefine()}"
};
}

private string GetFrameworkDefine()
{
switch (_runtime.BuiltFramework.FullName)
{
case ".NETFramework,Version=v4.6.1":
return "NET461";

case ".NETCoreApp,Version=v2.0":
return "NETCOREAPP2_0";

case ".NETCoreApp,Version=v2.1":
return "NETCOREAPP2_1";

case ".NETCoreApp,Version=v2.2":
return "NETCOREAPP2_2";

case ".NETCoreApp,Version=v3.0":
return "NETCOREAPP3_0";

default:
return "NETSTANDARD2_0";
}
}

private List<Assembly> LoadCakeAssemblies(DirectoryPath root)
{
var result = new List<Assembly>();
Expand Down
Loading

0 comments on commit 3d73001

Please sign in to comment.