Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
matkoch committed Aug 5, 2024
1 parent faf3c15 commit d551d6b
Show file tree
Hide file tree
Showing 23 changed files with 343 additions and 260 deletions.
67 changes: 64 additions & 3 deletions build/Build.CodeGeneration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,70 @@ partial class Build
Target GenerateTools => _ => _
.Executes(() =>
{
SpecificationsDirectory.GlobFiles("*/*.json").Where(x => x.Name.ContainsAnyOrdinalIgnoreCase([
"resharper",
])).ForEach(x =>
SpecificationsDirectory.GlobFiles("*/*.json").Where(x => x.Name.EqualsAnyOrdinalIgnoreCase([
"AzureSignTool.json",
"BenchmarkDotNet.json",
"Boots.json",
"Chocolatey.json",
// "CloudFoundry.json",
"CodeMetrics.json",
"Codecov.json",
"CorFlags.json",
"CoverallsNet.json",
"Coverlet.json",
// "Discord.json",
"DocFX.json",
// "Docker.json",
"DotCover.json",
"DotMemoryUnit.json",
"DotNet.json",
// "DotnetPackaging.json",
"EntityFramework.json",
"Fixie.json",
"Git.json",
"GitLink.json",
"GitReleaseManager.json",
"GitVersion.json",
// "Helm.json",
"ILRepack.json",
"InnoSetup.json",
// "Kubernetes.json",
"MSBuild.json",
"MSpec.json",
"MakeNSIS.json",
// "Mastodon.json",
"MauiCheck.json",
"MinVer.json",
// "NSwag.json",
"NUnit.json",
"NerdbankGitVersioning.json",
"Netlify.json",
"Npm.json",
"NuGet.json",
"OctoVersion.json",
"Octopus.json",
// "OpenCover.json",
"Paket.json",
"PowerShell.json",
"Pulumi.json",
"Pwsh.json",
"ReSharper.json",
"ReportGenerator.json",
"SignClient.json",
"SignTool.json",
// "Slack.json",
"SonarScanner.json",
"SpecFlow.json",
"Squirrel.json",
"StaticWebApps.json",
"Teams.json",
"TestCloud.json",
// "Unity.json",
"VSTest.json",
"VSWhere.json",
"WebConfigTransformRunner.json",
// "Xunit.json",
])).ForEach(x =>
GenerateCode(
x,
namespaceProvider: x => $"Nuke.Common.Tools.{x.Name}",
Expand Down
30 changes: 23 additions & 7 deletions source/Nuke.Common.Tests/SettingsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ private static void Assert<T>(Configure<T> configurator, string arguments)
configurator.Invoke(new T()).GetProcessArguments().RenderForOutput().Should().Be(arguments);
}

private static void Assert2<T>(Configure<T> configurator, string arguments)
private static void Assert<T>(T options, string arguments)
where T : ToolOptions, new()
{
configurator.Invoke(new T()).GetArguments().JoinSpace().Should().Be(arguments);
options.GetArguments().JoinSpace().Should().Be(arguments);
}

[Fact]
Expand All @@ -55,21 +55,21 @@ public void TestMSBuild()
var projectFile = RootDirectory / "source" / "Nuke.Common" / "Nuke.Common.csproj";
var solutionFile = RootDirectory / "nuke-common.sln";

Assert<MSBuildSettings>(x => x
Assert(new MSBuildSettings()
.SetProjectFile(projectFile)
.SetTargetPlatform(MSBuildTargetPlatform.MSIL)
.SetConfiguration("Release")
.DisableNodeReuse()
.EnableNoLogo(),
$"{projectFile.ToString().DoubleQuoteIfNeeded()} /nodeReuse:False /nologo /p:Platform=AnyCPU /p:Configuration=Release");
$"{projectFile.ToString().DoubleQuoteIfNeeded()} /p:Platform=AnyCPU /p:Configuration=Release /nodeReuse:false /nologo");

Assert<MSBuildSettings>(x => x
Assert(new MSBuildSettings()
.SetProjectFile(solutionFile)
.SetTargetPlatform(MSBuildTargetPlatform.MSIL)
.EnableNodeReuse()
.DisableNoLogo()
.ToggleRunCodeAnalysis(),
$"{solutionFile.ToString().DoubleQuoteIfNeeded()} /nodeReuse:True /p:Platform=\"Any CPU\" /p:RunCodeAnalysis=True");
$"{solutionFile.ToString().DoubleQuoteIfNeeded()} /p:Platform=\"Any CPU\" /nodeReuse:true /p:RunCodeAnalysis=true");
}

[Fact]
Expand Down Expand Up @@ -107,10 +107,26 @@ public void TestOpenCover()
[Fact]
public void TestCorFlags()
{
Assert2<CorFlagsSettings>(x => x
Assert(new CorFlagsSettings()
.SetAssembly("assembly")
.EnablePrefer32Bit()
.DisableILOnly(),
"assembly -32BITPREF+ -ILONLY-");
}

[Fact]
public void TestDotNet()
{
Assert(new DotNetTestSettings()
.AddRunSetting("key", "value")
.AddRunSetting("foo", "bar")
.EnableNoLogo(),
"test --nologo -- key=value foo=bar");

Assert(new DotNetRunSettings()
.AddApplicationArguments("arg1")
.AddApplicationArguments("arg2")
.SetProperty("foo", "bar"),
"run /property:foo=bar -- arg1 arg2");
}
}
58 changes: 4 additions & 54 deletions source/Nuke.Common/Tools/DotNet/DotNetTasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using JetBrains.Annotations;
using Nuke.Common.Tooling;
using Nuke.Tooling;
using Serilog;
using Serilog.Events;

namespace Nuke.Common.Tools.DotNet;

Expand All @@ -24,62 +24,12 @@ public DotNetVerbosityMappingAttribute()
}
}

partial class DotNetRunSettings
{
private string GetApplicationArguments()
{
return ApplicationArguments;
}
}
[LogLevelPattern(LogEventLevel.Warning, @": warning \w{2,5}\d{1,5}:")]
[LogLevelPattern(LogEventLevel.Error, @": error \w{2,5}\d{1,5}:")]
partial class DotNetTasks;

Check warning on line 29 in source/Nuke.Common/Tools/DotNet/DotNetTasks.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Base type is required

Base interface 'Nuke.Common.Tooling.IRequirePathTool' is required by attribute 'PathToolRequirementAttribute'

public partial class DotNetTasks

Check warning on line 31 in source/Nuke.Common/Tools/DotNet/DotNetTasks.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Base type is required

Base interface 'Nuke.Common.Tooling.IRequirePathTool' is required by attribute 'PathToolRequirementAttribute'
{
// ReSharper disable once CognitiveComplexity
internal static void CustomLogger(OutputType type, string output)
{
if (type == OutputType.Err)
{
Log.Error(output);
return;
}

var spaces = 0;
for (var i = 0; i < output.Length && spaces < 3; i++)
{
if (output[i] == ' ')
{
spaces++;
continue;
}

if (i >= 4 &&
'e' == output[i - 4] &&
'r' == output[i - 3] &&
'r' == output[i - 2] &&
'o' == output[i - 1] &&
'r' == output[i])
{
Log.Error(output);
return;
}

if (i >= 6 &&
'w' == output[i - 6] &&
'a' == output[i - 5] &&
'r' == output[i - 4] &&
'n' == output[i - 3] &&
'i' == output[i - 2] &&
'n' == output[i - 1] &&
'g' == output[i])
{
Log.Warning(output);
return;
}
}

Log.Debug(output);
}

public static string EscapeMSBuild(string str)
{
// https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-special-characters
Expand Down
48 changes: 0 additions & 48 deletions source/Nuke.Common/Tools/MSBuild/MSBuildSettings.cs

This file was deleted.

42 changes: 40 additions & 2 deletions source/Nuke.Common/Tools/MSBuild/MSBuildTasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,33 @@

using System;
using System.Linq;
using System.Reflection;
using JetBrains.Annotations;
using Nuke.Common.Tooling;
using Nuke.Common.Utilities;
using Nuke.Tooling;

namespace Nuke.Common.Tools.MSBuild;

[PublicAPI]
public class MSBuildVerbosityMappingAttribute : VerbosityMappingAttribute
{
public MSBuildVerbosityMappingAttribute()
: base(typeof(MSBuildVerbosity))
{
Quiet = nameof(MSBuildVerbosity.Quiet);
Minimal = nameof(MSBuildVerbosity.Minimal);
Normal = nameof(MSBuildVerbosity.Minimal);
Verbose = nameof(MSBuildVerbosity.Detailed);
}
}

partial class MSBuildTasks
{
private static string GetToolPath()
protected override string GetToolPath(ToolOptions options = null)
{
return MSBuildToolPathResolver.Resolve();
var msbuildOptions = options as MSBuildSettings;
return MSBuildToolPathResolver.Resolve(msbuildOptions?.MSBuildVersion, msbuildOptions?.MSBuildPlatform);
}

public static string EscapeMSBuild(string str)
Expand All @@ -27,3 +46,22 @@ public static string EscapeMSBuild(string str)
.Replace("*", "%2A"); // Wildcard character for use in file names in Include and Exclude attributes
}
}

partial class MSBuildSettings
{
[CanBeNull]
private string FormatPlatform(MSBuildTargetPlatform value, PropertyInfo property)
{
if (value == null)
return null;

if (Equals(value, MSBuildTargetPlatform.MSIL))
{
return TargetPath == null || TargetPath.EndsWithOrdinalIgnoreCase(".sln")
? "Any CPU".DoubleQuote()
: "AnyCPU";
}

return value.ToString();
}
}
Loading

0 comments on commit d551d6b

Please sign in to comment.