Skip to content

Commit

Permalink
Enable nullable references in build project
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Feb 23, 2025
1 parent 6bc8876 commit 23c9ffe
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 29 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,8 @@ dotnet_diagnostic.IDE0090.severity = none
# Allow namespaces to be independent of folder names
dotnet_diagnostic.IDE0130.severity = none

# Allow file-scoped namespaces
dotnet_diagnostic.IDE0160.severity = none

# Who cares if it's a JSON formatted string, in a test?
dotnet_diagnostic.JSON002.severity = none
6 changes: 5 additions & 1 deletion build/Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
<OutputPath Condition=" '$(Configuration)' == '' ">..\_build\out\$(AssemblyName)\VSCodeIDE\bin\</OutputPath>
<BaseIntermediateOutputPath Condition=" '$(Configuration)' != '' ">..\_build\out\$(AssemblyName)\$(Configuration)\obj\</BaseIntermediateOutputPath>
<BaseIntermediateOutputPath Condition=" '$(Configuration)' == '' ">..\_build\out\$(AssemblyName)\VSCodeIDE\obj\</BaseIntermediateOutputPath>
<Prefer32Bit>false</Prefer32Bit>
<LangVersion>12</LangVersion>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
<ItemGroup>
Expand All @@ -19,4 +23,4 @@
</PackageReference>
</ItemGroup>
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
</Project>
</Project>
35 changes: 21 additions & 14 deletions build/BuildContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

using Cake.Common;
using Cake.Common.Diagnostics;
using Cake.Common.IO;
Expand All @@ -19,7 +20,7 @@ public partial class BuildContext : FrostingContext
public string Target { get; }

// Named to avoid conflict with ICakeContext.Configuration
public string BuildConfiguration { get; set; }
public string? BuildConfiguration { get; set; }
public string Solution { get; }

public BuildPaths Paths { get; }
Expand All @@ -28,26 +29,30 @@ public BuildContext(ICakeContext context)
: base(context)
{
var rootDir = context.Environment.WorkingDirectory.GetParent();

Target = context.Argument("target", "Default");
BuildConfiguration = context.Argument<string>("configuration", null);
BuildConfiguration = context.Argument<string?>("configuration", null);
Solution = context.Argument("solution", rootDir.CombineWithFilePath("CKAN.sln").FullPath);

if (string.Equals(Target, "Release", StringComparison.OrdinalIgnoreCase))
{
if (BuildConfiguration != null)
{
context.Warning($"Ignoring configuration argument: '{BuildConfiguration}'");
}

BuildConfiguration = "Release";
}
else if (string.Equals(Target, "Debug", StringComparison.OrdinalIgnoreCase))
{
if (BuildConfiguration != null)
{
context.Warning($"Ignoring configuration argument: '{BuildConfiguration}'");
}

BuildConfiguration = "Debug";
}

BuildConfiguration ??= "Debug";
Paths = new BuildPaths(rootDir, BuildConfiguration, GetVersion(false));
}
Expand All @@ -59,11 +64,11 @@ public SemVersion GetVersion(bool withBuild = true)
var versionMatch = System.IO.File
.ReadAllLines(rootDirectory.CombineWithFilePath("CHANGELOG.md").FullPath)
.Select(i => VersionRegex().Match(i))
.FirstOrDefault(i => i.Success);
.First(i => i.Success);

if (!SemVersion.TryParse(versionMatch.Groups["version"].Value, out var version))
{
throw new System.Exception("Could not parse version from CHANGELOG.md");
throw new Exception("Could not parse version from CHANGELOG.md");
}

if (withBuild && this.DirectoryExists(rootDirectory.Combine(".git")))
Expand Down Expand Up @@ -109,7 +114,7 @@ public DirectoryPath FacadesDirectory()
{
monoLib = new DirectoryPath("/usr").Combine("lib");
}

return monoLib
.Combine("mono")
.Combine("4.8-api")
Expand All @@ -135,31 +140,33 @@ public static void RepackSilently(ProcessSettings settings)
.SetRedirectStandardError(true)
.SetRedirectedStandardErrorHandler(s => "");

public string GetQuote(FilePath file)
public string? GetQuote(FilePath file)
{
if (!this.FileExists(file)) return null;
if (!this.FileExists(file))
{
return null;
}

var quotes = System.IO.File
.ReadAllText(file.FullPath)
.Split("%", StringSplitOptions.RemoveEmptyEntries);

return quotes.Length > 0 ? quotes[new Random().Next(quotes.Length)] : null;
}

public IEnumerable<string> RunExecutable(FilePath executable, string arguments)
{
IEnumerable<string> output;
var exitCode = this.StartProcess(
executable,
new ProcessSettings { Arguments = arguments, RedirectStandardOutput = true },
out output
out IEnumerable<string> output
);

if (exitCode != 0)
{
throw new Exception("Process failed with exit code: " + exitCode);
}

return output;
}
}
}
11 changes: 6 additions & 5 deletions build/BuildLifetime.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;
using Cake.Common;
using Cake.Common.Diagnostics;
using Cake.Core;
using Cake.Frosting;
Expand All @@ -15,11 +13,14 @@ public override void Setup(BuildContext context, ISetupContext info)
public override void Teardown(BuildContext context, ITeardownContext info)
{
var quote = context.GetQuote(context.Paths.RootDirectory.CombineWithFilePath("quotes.txt"));
if (quote == null) return;

if (quote == null)
{
return;
}

using (context.NormalVerbosity())
{
context.Information(quote);
}
}
}
}
7 changes: 4 additions & 3 deletions build/MakeTasks.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;

using Cake.Common;
using Cake.Core.IO;
using Cake.Frosting;
Expand Down Expand Up @@ -52,7 +53,7 @@ public sealed class RpmTestTask() : MakeTask("rpm", "test");
[TaskDescription("Clean the rpm package output directory.")]
public sealed class RpmCleanTask() : MakeTask("rpm", "clean");

public abstract class MakeTask(string location, ProcessArgumentBuilder args = null) : FrostingTask<BuildContext>
public abstract class MakeTask(string location, ProcessArgumentBuilder? args = null) : FrostingTask<BuildContext>
{
private string Location { get; } = location;
private ProcessArgumentBuilder Args { get; } = args ?? "";
Expand All @@ -62,11 +63,11 @@ public override void Run(BuildContext context)
var exitCode = context.StartProcess("make", new ProcessSettings() {
WorkingDirectory = Location,
Arguments = Args,
EnvironmentVariables = new Dictionary<string, string> { { "CONFIGURATION", context.BuildConfiguration } }
EnvironmentVariables = new Dictionary<string, string?> { { "CONFIGURATION", context.BuildConfiguration } }
});
if (exitCode != 0)
{
throw new Exception("Make failed with exit code: " + exitCode);
}
}
}
}
13 changes: 7 additions & 6 deletions build/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;

using Cake.Common;
using Cake.Common.Diagnostics;
using Cake.Common.IO;
Expand Down Expand Up @@ -74,7 +75,7 @@ public override void Run(BuildContext context)
{
WorkingDirectory = context.Paths.RootDirectory,
PackagesDirectory = context.Paths.NugetDirectory,
EnvironmentVariables = new Dictionary<string, string> { { "Configuration", context.BuildConfiguration } }
EnvironmentVariables = new Dictionary<string, string?> { { "Configuration", context.BuildConfiguration } }
});
}
}
Expand All @@ -87,7 +88,7 @@ public override void Run(BuildContext context)
{
var metaDirectory = context.Paths.BuildDirectory.Combine("meta");
context.CreateDirectory(metaDirectory);

var version = context.GetVersion();

context.CreateAssemblyInfo(
Expand Down Expand Up @@ -128,7 +129,7 @@ public override void Run(BuildContext context)
{
Configuration = context.BuildConfiguration,
});

// Use Mono to build for net48 since dotnet can't use WinForms on Linux
context.MSBuild(context.Solution, new MSBuildSettings
{
Expand All @@ -154,7 +155,7 @@ public sealed class RepackCkanTask : FrostingTask<BuildContext>
public override void Run(BuildContext context)
{
context.CreateDirectory(context.Paths.RepackDirectory.Combine(context.BuildConfiguration));

var cmdLineBinDirectory = context.Paths.OutDirectory.Combine("CKAN-CmdLine")
.Combine(context.BuildConfiguration)
.Combine("bin")
Expand Down Expand Up @@ -318,7 +319,7 @@ public sealed class TestUnitTestsOnlyTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
var where = context.Argument<string>("where", null);
var where = context.Argument<string?>("where", null);
var nunitOutputDirectory = context.Paths.BuildDirectory.Combine("test")
.Combine("nunit");
context.CreateDirectory(nunitOutputDirectory);
Expand Down Expand Up @@ -379,4 +380,4 @@ public override void Run(BuildContext context)
context.Information(context.GetVersion().ToString());
}
}
}
}

0 comments on commit 23c9ffe

Please sign in to comment.