Skip to content

Commit

Permalink
Fix some build warnings. (#2021)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrp authored Apr 7, 2024
1 parent 28b0763 commit 81cfc10
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion build/nuke/Build.CodeSigning.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Output>();
Expand Down
3 changes: 2 additions & 1 deletion build/nuke/Build.Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 8 additions & 7 deletions build/nuke/Build.Generation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -52,14 +53,14 @@ partial class Build
{
DotNet($"sln \"{Path.GetFileName(OriginalSolution.FileName)}\" add \"{missedOut}\"");
}
PrUpdatedBindings();
}
}
)
);


void PrUpdatedBindings()
{
var pushableToken = EnvironmentInfo.GetVariable<string>("PUSHABLE_GITHUB_TOKEN");
Expand Down Expand Up @@ -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}\"");
}

Expand All @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions build/nuke/Build.NuGet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -44,7 +45,7 @@ async Task<IEnumerable<Output>> 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)
Expand All @@ -64,7 +65,7 @@ async Task<IEnumerable<Output>> PushPackages()
{
if (NugetUsername is null || NugetPassword is null)
{
ControlFlow.Fail
Assert.Fail
(
"Both \"NugetUsername\" and \"NugetPassword\" must be specified if either are used."
);
Expand Down
9 changes: 5 additions & 4 deletions build/nuke/Build.PublicApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -133,10 +134,10 @@ string FormatCmd
// about adding dodgy MSBuild targets that could swipe it
var githubToken = EnvironmentInfo.GetVariable<string>("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);
Expand Down Expand Up @@ -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}\"");
}

Expand Down
11 changes: 6 additions & 5 deletions build/nuke/Build.ReviewHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using Nuke.Common;
using Nuke.Common.IO;
using Serilog;

partial class Build
{
Expand All @@ -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.");
}
}
)
Expand All @@ -46,7 +47,7 @@ List<string> 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;
Expand All @@ -61,7 +62,7 @@ List<string> 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 " +
Expand Down
11 changes: 6 additions & 5 deletions build/nuke/Build.SolutionGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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;
}

Expand Down Expand Up @@ -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("*"))
{
Expand All @@ -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();
}
15 changes: 8 additions & 7 deletions build/nuke/Build.Support.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -147,27 +148,27 @@ async Task AddOrUpdatePrComment(string type, string file, bool editOnly = false,
var githubToken = EnvironmentInfo.GetVariable<string>("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;
}

Expand All @@ -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;
}

Expand All @@ -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);
}
}
Expand Down
9 changes: 5 additions & 4 deletions build/nuke/Native/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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}\"");
}

Expand All @@ -118,4 +119,4 @@ public void PrUpdatedNativeBinary(string name, [CanBeNull] string glob = null)
}
}
}
}
}
9 changes: 5 additions & 4 deletions build/nuke/Native/SilkDroid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
Expand All @@ -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<Output>();
}
Expand All @@ -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?)");
}
Expand Down Expand Up @@ -99,4 +100,4 @@ string AndroidHome
}
)
);
}
}

0 comments on commit 81cfc10

Please sign in to comment.