From 81cfc1008b1df8901a4d8c4e365cabda6797eaf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 7 Apr 2024 21:33:11 +0200 Subject: [PATCH] Fix some build warnings. (#2021) --- .editorconfig | 2 +- build/nuke/Build.CodeSigning.cs | 2 +- build/nuke/Build.Core.cs | 3 ++- build/nuke/Build.Generation.cs | 15 ++++++++------- build/nuke/Build.NuGet.cs | 5 +++-- build/nuke/Build.PublicApi.cs | 9 +++++---- build/nuke/Build.ReviewHelpers.cs | 11 ++++++----- build/nuke/Build.SolutionGenerator.cs | 11 ++++++----- build/nuke/Build.Support.cs | 15 ++++++++------- build/nuke/Native/Core.cs | 9 +++++---- build/nuke/Native/SilkDroid.cs | 9 +++++---- 11 files changed, 50 insertions(+), 41 deletions(-) diff --git a/.editorconfig b/.editorconfig index 3c09d9f6c0..20858fbe2e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -40,7 +40,7 @@ dotnet_diagnostic.RS0016.severity = error dotnet_diagnostic.RS0017.severity = error # we should care more about this one day -dotnet_diagnostic.RS0041.severity = warn +dotnet_diagnostic.RS0041.severity = warning # public api warnings silk.net doesn't care about dotnet_diagnostic.RS0026.severity = none # Don't add multiple public overloads with optional parameters diff --git a/build/nuke/Build.CodeSigning.cs b/build/nuke/Build.CodeSigning.cs index 008ea19a0a..983624405f 100644 --- a/build/nuke/Build.CodeSigning.cs +++ b/build/nuke/Build.CodeSigning.cs @@ -35,7 +35,7 @@ partial class Build { if (!CanCodeSign) { - ControlFlow.Fail("SignClient username and/or password not specified."); + Assert.Fail("SignClient username and/or password not specified."); } var outputs = Enumerable.Empty(); diff --git a/build/nuke/Build.Core.cs b/build/nuke/Build.Core.cs index 819bdd83a1..0b47ac05f2 100644 --- a/build/nuke/Build.Core.cs +++ b/build/nuke/Build.Core.cs @@ -7,6 +7,7 @@ using Nuke.Common; using Nuke.Common.Tooling; using Nuke.Common.Tools.DotNet; +using Serilog; using static Nuke.Common.IO.FileSystemTasks; using static Nuke.Common.Tools.DotNet.DotNetTasks; using static Nuke.Common.Tooling.ProcessTasks; @@ -57,7 +58,7 @@ partial class Build } else { - Logger.Warn("Skipping gradlew clean as the \"native\" feature-set has not been specified."); + Log.Warning("Skipping gradlew clean as the \"native\" feature-set has not been specified."); } return outputs; diff --git a/build/nuke/Build.Generation.cs b/build/nuke/Build.Generation.cs index 0837e2fbc8..9f8628753f 100644 --- a/build/nuke/Build.Generation.cs +++ b/build/nuke/Build.Generation.cs @@ -11,6 +11,7 @@ using Nuke.Common.Tools.DotNet; using Octokit; using Octokit.Internal; +using Serilog; using static Nuke.Common.Tools.DotNet.DotNetTasks; using static Nuke.Common.Tools.Git.GitTasks; using static Nuke.Common.Tooling.ProcessTasks; @@ -31,7 +32,7 @@ partial class Build var project = OriginalSolution.GetProject("Silk.NET.BuildTools"); if (project == default) { - Logger.Error("Couldn't find BuildTools in the solution file."); + Log.Error("Couldn't find BuildTools in the solution file."); return; } @@ -52,14 +53,14 @@ partial class Build { DotNet($"sln \"{Path.GetFileName(OriginalSolution.FileName)}\" add \"{missedOut}\""); } - + PrUpdatedBindings(); } } ) ); - - + + void PrUpdatedBindings() { var pushableToken = EnvironmentInfo.GetVariable("PUSHABLE_GITHUB_TOKEN"); @@ -89,13 +90,13 @@ void PrUpdatedBindings() Git("reset --hard", RootDirectory); if (GitCurrentCommit(RootDirectory) != curCommit) // might get "nothing to commit", you never know... { - Logger.Info("Checking for existing branch..."); + Log.Information("Checking for existing branch..."); var exists = StartProcess("git", $"checkout \"{newBranch}\"", RootDirectory) .AssertWaitForExit() .ExitCode == 0; if (!exists) { - Logger.Info("None found, creating a new one..."); + Log.Information("None found, creating a new one..."); Git($"checkout -b \"{newBranch}\""); } @@ -108,7 +109,7 @@ void PrUpdatedBindings() new ProductHeaderValue("Silk.NET-CI"), new InMemoryCredentialStore(new Credentials(pushableToken)) ); - + var pr = github.PullRequest.Create ("dotnet", "Silk.NET", new($"Regenerate bindings as of {DateTime.UtcNow:dd/MM/yyyy}", newBranch, curBranch)) .GetAwaiter() diff --git a/build/nuke/Build.NuGet.cs b/build/nuke/Build.NuGet.cs index cb325cd8e7..24c4212a63 100644 --- a/build/nuke/Build.NuGet.cs +++ b/build/nuke/Build.NuGet.cs @@ -9,6 +9,7 @@ using Nuke.Common; using Nuke.Common.Tooling; using Nuke.Common.Tools.DotNet; +using Serilog; using static Nuke.Common.Tools.DotNet.DotNetTasks; partial class Build @@ -44,7 +45,7 @@ async Task> PushPackages() .Select(x => x.Select(v => v.Value).ToList()) .ToList(); var first = true; - Logger.Info($"Searching for packages in \"{RootDirectory / "build" / "output_packages"}\"..."); + Log.Information($"Searching for packages in \"{RootDirectory / "build" / "output_packages"}\"..."); foreach (var files in allFiles) { if (first) @@ -64,7 +65,7 @@ async Task> PushPackages() { if (NugetUsername is null || NugetPassword is null) { - ControlFlow.Fail + Assert.Fail ( "Both \"NugetUsername\" and \"NugetPassword\" must be specified if either are used." ); diff --git a/build/nuke/Build.PublicApi.cs b/build/nuke/Build.PublicApi.cs index 657e172f0a..b75e82f110 100644 --- a/build/nuke/Build.PublicApi.cs +++ b/build/nuke/Build.PublicApi.cs @@ -10,6 +10,7 @@ using Nuke.Common.Tooling; using Octokit; using Octokit.Internal; +using Serilog; using static Nuke.Common.Tools.Git.GitTasks; using static Nuke.Common.Tooling.ProcessTasks; using static Nuke.Common.Tools.DotNet.DotNetTasks; @@ -133,10 +134,10 @@ string FormatCmd // about adding dodgy MSBuild targets that could swipe it var githubToken = EnvironmentInfo.GetVariable("GITHUB_TOKEN"); EnvironmentInfo.SetVariable("GITHUB_TOKEN", string.Empty); - + // run the format command InheritedShell($"{cmd} --verify-no-changes").AssertZeroExitCode(); - + // add our github token back EnvironmentInfo.SetVariable("GITHUB_TOKEN", githubToken); await AddOrUpdatePrComment("public_api", "public_api_declared", true); @@ -184,13 +185,13 @@ void MakePr() Git("reset --hard", RootDirectory); if (GitCurrentCommit(RootDirectory) != curCommit) // might get "nothing to commit", you never know... { - Logger.Info("Checking for existing branch..."); + Log.Information("Checking for existing branch..."); var exists = StartProcess("git", $"checkout \"{newBranch}\"", RootDirectory) .AssertWaitForExit() .ExitCode == 0; if (!exists) { - Logger.Info("None found, creating a new one..."); + Log.Information("None found, creating a new one..."); Git($"checkout -b \"{newBranch}\""); } diff --git a/build/nuke/Build.ReviewHelpers.cs b/build/nuke/Build.ReviewHelpers.cs index 7f4c2c2fc0..aa5c2a2ecc 100644 --- a/build/nuke/Build.ReviewHelpers.cs +++ b/build/nuke/Build.ReviewHelpers.cs @@ -6,6 +6,7 @@ using System.Linq; using Nuke.Common; using Nuke.Common.IO; +using Serilog; partial class Build { @@ -27,13 +28,13 @@ partial class Build var missedOut = GetNewProjects(); if (missedOut.Any()) { - Logger.Warn("Commands to add these for your convenience:"); + Log.Warning("Commands to add these for your convenience:"); foreach (var file in missedOut) { - Logger.Warn($"dotnet sln \"{Path.GetFileName(OriginalSolution.FileName)}\" add \"{file}\""); + Log.Warning($"dotnet sln \"{Path.GetFileName(OriginalSolution.FileName)}\" add \"{file}\""); } - ControlFlow.Fail("Action required."); + Assert.Fail("Action required."); } } ) @@ -46,7 +47,7 @@ List GetNewProjects() .Concat(RootDirectory.GlobFiles("**/*.csproj")) .Where(x => !x.ToString().Contains("submodules")) .ToArray(); - Logger.Info($"Found {files.Length} csproj files in \"{RootDirectory}\""); + Log.Information($"Found {files.Length} csproj files in \"{RootDirectory}\""); foreach (var file in files) { var found = false; @@ -61,7 +62,7 @@ List GetNewProjects() if (!found && !AllowedExclusions.Contains(Path.GetFileNameWithoutExtension(file))) { - Logger.Error + Log.Error ( "A project has not been included in the solution and will not be shipped! " + $"\"{file}\" if this is acceptable please add the project name (excluding the path and " + diff --git a/build/nuke/Build.SolutionGenerator.cs b/build/nuke/Build.SolutionGenerator.cs index e1c3d08c96..0d77ba621f 100644 --- a/build/nuke/Build.SolutionGenerator.cs +++ b/build/nuke/Build.SolutionGenerator.cs @@ -12,6 +12,7 @@ using Nuke.Common.IO; using Nuke.Common.ProjectModel; using Nuke.Common.Utilities; +using Serilog; using static Nuke.Common.IO.FileSystemTasks; using static Nuke.Common.ProjectModel.ProjectModelTasks; @@ -28,7 +29,7 @@ partial class Build "specified, but if you don't want to run a build just use \"nuke sln --projects ...\" to run a dummy target." )] readonly string[] Projects; - + [Parameter("If specified, ignores any generated solution present and builds the entire project.", Name = "All")] readonly bool BuildAll; @@ -42,7 +43,7 @@ void GenerateSolution() { if (Projects is not { Length: > 0 }) { - Logger.Trace("Nothing to do for GenerateSolution."); + Log.Verbose("Nothing to do for GenerateSolution."); return; } @@ -101,7 +102,7 @@ AbsolutePath Concat(AbsolutePath path, string next) // make a new Solution object to prevent us mutating the OriginalSolution var genSln = ParseSolution(OriginalSolution.Path); - + // remove irrelevant projects foreach (var project in genSln.GetProjects("*")) { @@ -112,8 +113,8 @@ AbsolutePath Concat(AbsolutePath path, string next) } genSln.SaveAs(RootDirectory / "Silk.NET.gen.sln"); - Logger.Info($"Generated solution containing {genSln.AllProjects.Count} projects"); + Log.Information($"Generated solution containing {genSln.AllProjects.Count} projects"); } - + Target Sln => CommonTarget(); } diff --git a/build/nuke/Build.Support.cs b/build/nuke/Build.Support.cs index 2d13394232..2a3565fee0 100644 --- a/build/nuke/Build.Support.cs +++ b/build/nuke/Build.Support.cs @@ -19,6 +19,7 @@ using Nuke.Common.Tools.DotNet; using Nuke.Common.Utilities; using Octokit; +using Serilog; using static Nuke.Common.IO.FileSystemTasks; using static Nuke.Common.Tooling.ProcessTasks; using static Nuke.Common.Tools.DotNet.DotNetTasks; @@ -147,27 +148,27 @@ async Task AddOrUpdatePrComment(string type, string file, bool editOnly = false, var githubToken = EnvironmentInfo.GetVariable("GITHUB_TOKEN"); if (string.IsNullOrWhiteSpace(githubToken)) { - Logger.Info("GitHub token not found, skipping writing a comment."); + Log.Information("GitHub token not found, skipping writing a comment."); return; } var @ref = GitHubActions.Instance?.Ref; if (string.IsNullOrWhiteSpace(@ref)) { - Logger.Info("Not running in GitHub Actions, skipping writing a comment."); + Log.Information("Not running in GitHub Actions, skipping writing a comment."); return; } var prMatch = PrRegex.Match(@ref); if (!prMatch.Success || prMatch.Groups.Count < 2) { - Logger.Info($"Couldn't match {@ref} to a PR, skipping writing a comment."); + Log.Information($"Couldn't match {@ref} to a PR, skipping writing a comment."); return; } if (!int.TryParse(prMatch.Groups[1].Value, out var pr)) { - Logger.Info($"Couldn't parse {@prMatch.Groups[1].Value} as an int, skipping writing a comment."); + Log.Information($"Couldn't parse {@prMatch.Groups[1].Value} as an int, skipping writing a comment."); return; } @@ -181,7 +182,7 @@ async Task AddOrUpdatePrComment(string type, string file, bool editOnly = false, .FirstOrDefault(x => x.Body.Contains($"`{type}`") && x.User.Name == "github-actions[bot]"); if (existingComment is null && editOnly) { - Logger.Info("Edit only mode is on and no existing comment found, skipping writing a comment."); + Log.Information("Edit only mode is on and no existing comment found, skipping writing a comment."); return; } @@ -198,12 +199,12 @@ async Task AddOrUpdatePrComment(string type, string file, bool editOnly = false, if (existingComment is not null) { - Logger.Info("Updated the comment on the PR."); + Log.Information("Updated the comment on the PR."); await github.Issue.Comment.Update("dotnet", "Silk.NET", existingComment.Id, commentText); } else { - Logger.Info("Added a comment to the PR."); + Log.Information("Added a comment to the PR."); await github.Issue.Comment.Create("dotnet", "Silk.NET", pr, commentText); } } diff --git a/build/nuke/Native/Core.cs b/build/nuke/Native/Core.cs index 2ab58cdbb3..5ebdf4fb65 100644 --- a/build/nuke/Native/Core.cs +++ b/build/nuke/Native/Core.cs @@ -17,6 +17,7 @@ using Nuke.Common.Tools.Git; using Octokit; using Octokit.Internal; +using Serilog; using static Nuke.Common.IO.CompressionTasks; using static Nuke.Common.IO.FileSystemTasks; using static Nuke.Common.IO.HttpTasks; @@ -33,7 +34,7 @@ partial class Build { static string JobsArg => string.IsNullOrWhiteSpace(GitHubActions.Instance?.Job) ? $" -j{Jobs}" : string.Empty; - + static int Jobs => string.IsNullOrWhiteSpace(GitHubActions.Instance?.Job) ? Environment.ProcessorCount - 1 : 1; @@ -90,13 +91,13 @@ public void PrUpdatedNativeBinary(string name, [CanBeNull] string glob = null) Git("reset --hard", RootDirectory); if (GitCurrentCommit(RootDirectory) != curCommit) // might get "nothing to commit", you never know... { - Logger.Info("Checking for existing branch..."); + Log.Information("Checking for existing branch..."); var exists = StartProcess("git", $"checkout \"{newBranch}\"", RootDirectory) .AssertWaitForExit() .ExitCode == 0; if (!exists) { - Logger.Info("None found, creating a new one..."); + Log.Information("None found, creating a new one..."); Git($"checkout -b \"{newBranch}\""); } @@ -118,4 +119,4 @@ public void PrUpdatedNativeBinary(string name, [CanBeNull] string glob = null) } } } -} \ No newline at end of file +} diff --git a/build/nuke/Native/SilkDroid.cs b/build/nuke/Native/SilkDroid.cs index 7b9716d82d..4394174c79 100644 --- a/build/nuke/Native/SilkDroid.cs +++ b/build/nuke/Native/SilkDroid.cs @@ -17,6 +17,7 @@ using Nuke.Common.Tools.Git; using Octokit; using Octokit.Internal; +using Serilog; using static Nuke.Common.IO.CompressionTasks; using static Nuke.Common.IO.FileSystemTasks; using static Nuke.Common.IO.HttpTasks; @@ -38,7 +39,7 @@ string AndroidHome var utils = RootDirectory / "build" / "utilities"; DotNet($"build \"{utils / "android_probe.proj"}\" /t:GetAndroidJar"); AndroidHomeValue = (AbsolutePath) File.ReadAllText(utils / "android.jar.gen.txt") / ".." / ".." / ".."; - Logger.Info($"Android Home: {AndroidHomeValue}"); + Log.Information($"Android Home: {AndroidHomeValue}"); return AndroidHomeValue; } } @@ -53,7 +54,7 @@ string AndroidHome { if (!Native) { - Logger.Warn("Skipping gradlew build as the --native parameter has not been specified."); + Log.Warning("Skipping gradlew build as the --native parameter has not been specified."); return Enumerable.Empty(); } @@ -70,7 +71,7 @@ string AndroidHome { if (!Directory.Exists(from)) { - ControlFlow.Fail + Assert.Fail ($"\"{from}\" does not exist (did you forget to recursively clone the repo?)"); } @@ -99,4 +100,4 @@ string AndroidHome } ) ); -} \ No newline at end of file +}