Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/Fallout.Build/ControlFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public static class ControlFlow
{
public static void SuppressErrors(Action action, bool includeStackTrace = false, bool logWarning = true)
{
SuppressErrorsIf(condition: true, action, includeStackTrace: includeStackTrace, logWarning: logWarning);
SuppressErrorsIf(condition: true, action, logWarning: logWarning);
}

public static T SuppressErrors<T>(Func<T> action, T defaultValue = default, bool includeStackTrace = false, bool logWarning = true)
{
return (T)SuppressErrorsIf(condition: true, action, defaultValue, includeStackTrace, logWarning);
return (T)SuppressErrorsIf(condition: true, action, defaultValue, logWarning);
}

public static IEnumerable<T> SuppressErrors<T>(Func<IEnumerable<T>> action, bool includeStackTrace = false)
Expand All @@ -34,7 +34,6 @@ private static object SuppressErrorsIf(
bool condition,
Delegate action,
object defaultValue = null,
bool includeStackTrace = false,
bool logWarning = true)
{
if (!condition)
Expand Down
4 changes: 2 additions & 2 deletions src/Fallout.Build/Utilities/SchemaUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private static JsonObject SchemaForType(Type type, SchemaContext ctx)
return new JsonObject { ["type"] = "string" };

if (typeof(Enumeration).IsAssignableFrom(type))
return BuildEnumerationSchema(type, ctx);
return BuildEnumerationSchema(type);

if (type.IsEnum)
return StringEnumSchema(Enum.GetNames(type));
Expand All @@ -266,7 +266,7 @@ private static JsonObject SchemaForType(Type type, SchemaContext ctx)
return BuildComplexTypeReference(type, ctx);
}

private static JsonObject BuildEnumerationSchema(Type enumerationType, SchemaContext ctx)
private static JsonObject BuildEnumerationSchema(Type enumerationType)
{
var values = enumerationType
.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)
Expand Down
10 changes: 5 additions & 5 deletions src/Fallout.Cli/Program.Navigation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private static string SessionId

private static AbsolutePath SessionFile => GlobalTemporaryDirectory / $"nuke-{SessionId}.dat";

private static int GetNextDirectory(string[] args, AbsolutePath rootDirectory, AbsolutePath buildScript)
private static int GetNextDirectory()
{
var content = SessionFile.Existing()?.ReadAllLines();
if (content == null || string.IsNullOrWhiteSpace(content[0]))
Expand All @@ -41,7 +41,7 @@ private static int GetNextDirectory(string[] args, AbsolutePath rootDirectory, A
return 0;
}

private static int PopDirectory(string[] args, AbsolutePath rootDirectory, AbsolutePath buildScript)
private static int PopDirectory()
{
var content = SessionFile.Existing()?.ReadAllLines().ToList();
if (content == null || content.Count <= 1)
Expand All @@ -56,18 +56,18 @@ private static int PopDirectory(string[] args, AbsolutePath rootDirectory, Absol
return 0;
}

private static int PushWithCurrentRootDirectory(string[] args, AbsolutePath rootDirectory, AbsolutePath buildScript)
private static int PushWithCurrentRootDirectory(AbsolutePath rootDirectory)
{
return PushAndSetNext(() => rootDirectory.NotNull("No root directory"));
}

private static int PushWithParentRootDirectory(string[] args, AbsolutePath rootDirectory, AbsolutePath buildScript)
private static int PushWithParentRootDirectory(AbsolutePath rootDirectory)
{
return PushAndSetNext(() => TryGetRootDirectoryFrom(Path.GetDirectoryName(rootDirectory.NotNull("No root directory")))
.NotNull("No parent root directory"));
}

private static int PushWithChosenRootDirectory(string[] args, AbsolutePath rootDirectory, AbsolutePath buildScript)
private static int PushWithChosenRootDirectory()
{
return PushAndSetNext(() =>
{
Expand Down
8 changes: 2 additions & 6 deletions src/Fallout.Cli/Program.Setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ public static int Setup(string[] args, AbsolutePath rootDirectory, AbsolutePath

WriteBuildScripts(
scriptDirectory: WorkingDirectory,
rootDirectory,
buildDirectory,
buildProjectName);
rootDirectory);

WriteConfigurationFile(rootDirectory, solutionFile);

Expand Down Expand Up @@ -186,9 +184,7 @@ private static string[] GetTemplate(string templateName)

private static void WriteBuildScripts(
AbsolutePath scriptDirectory,
AbsolutePath rootDirectory,
AbsolutePath buildDirectory,
string buildProjectName)
AbsolutePath rootDirectory)
{
(scriptDirectory / "build.sh").WriteAllLines(
FillTemplate(
Expand Down
5 changes: 1 addition & 4 deletions src/Fallout.Cli/Program.Update.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.IO;
using System.Linq;
using System.Text.Json.Nodes;
using Fallout.Common;
Expand Down Expand Up @@ -42,9 +41,7 @@ private static void UpdateBuildScripts(AbsolutePath rootDirectory, AbsolutePath

WriteBuildScripts(
scriptDirectory: buildScript.Parent,
rootDirectory,
buildDirectory: buildProjectFile.NotNull().Parent,
buildProjectName: Path.GetFileNameWithoutExtension(buildProjectFile));
rootDirectory);
}

private static void UpdateBuildProject(AbsolutePath buildScript)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public GitHubActionsAttribute(
public string PublishCondition { get; set; }

public int TimeoutMinutes { get; set; }

public string EnvironmentName { get; set; }
public string EnvironmentUrl { get; set; }

Expand Down Expand Up @@ -163,15 +163,15 @@ protected virtual GitHubActionsJob GetJobs(GitHubActionsImage image, IReadOnlyCo
Name = image.GetValue().Replace(".", "_"),
EnvironmentName = EnvironmentName,
EnvironmentUrl = EnvironmentUrl,
Steps = GetSteps(image, relevantTargets).ToArray(),
Steps = GetSteps(relevantTargets).ToArray(),
Image = image,
TimeoutMinutes = TimeoutMinutes,
ConcurrencyGroup = JobConcurrencyGroup,
ConcurrencyCancelInProgress = JobConcurrencyCancelInProgress
};
}

private IEnumerable<GitHubActionsStep> GetSteps(GitHubActionsImage image, IReadOnlyCollection<ExecutableTarget> relevantTargets)
private IEnumerable<GitHubActionsStep> GetSteps(IReadOnlyCollection<ExecutableTarget> relevantTargets)
{
yield return new GitHubActionsCheckoutStep
{
Expand Down
3 changes: 1 addition & 2 deletions src/Fallout.Common/Tools/CorFlags/CorFlagsSettings.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System;
using System.Reflection;

namespace Fallout.Common.Tools.CorFlags;

partial class CorFlagsSettings
{
string FormatBoolean(bool? value, PropertyInfo property)
private static string FormatBoolean(bool? value)
=> value switch
{
true => "+",
Expand Down
7 changes: 2 additions & 5 deletions src/Fallout.Tooling.Generator/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static void GenerateCode(
tool.SpecificationFile = specificationFile;
tool.SourceFile = sourceFileProvider?.Invoke(tool);
tool.Namespace = namespaceProvider?.Invoke(tool);
ApplyRuntimeInformation(tool, specificationFile, sourceFileProvider, namespaceProvider);
ApplyRuntimeInformation(tool);

GenerateCode(tool, outputFileProvider?.Invoke(tool) ?? tool.DefaultOutputFile);
}
Expand All @@ -58,10 +58,7 @@ public static void GenerateCode(Tool tool, string outputFile)

// ReSharper disable once CognitiveComplexity
private static void ApplyRuntimeInformation(
Tool tool,
string specificationFile,
Func<Tool, string> sourceFileProvider,
Func<Tool, string> namespaceProvider)
Tool tool)
{
foreach (var task in tool.Tasks)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Fallout.Tooling/ProcessTasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private static IProcess StartProcessInternal(
}

if (logInvocation)
LogInvocation(startInfo, outputFilter, environmentVariables != null);
LogInvocation(startInfo, outputFilter);

var process = Process.Start(startInfo);
if (process == null)
Expand All @@ -166,7 +166,7 @@ private static IProcess StartProcessInternal(
return new Process2(process, outputFilter, timeout, output);
}

private static void LogInvocation(ProcessStartInfo startInfo, Func<string, string> outputFilter, bool hasEnvironmentVariables)
private static void LogInvocation(ProcessStartInfo startInfo, Func<string, string> outputFilter)
{
lock (s_lock)
{
Expand Down
8 changes: 7 additions & 1 deletion src/Fallout.Tooling/ToolOptions.Arguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,13 @@ string Parse(JsonNode token, Type type)
var formatterType = attribute.FormatterType ?? GetType();
var formatterMethod = formatterType.GetMethod(attribute.FormatterMethod, ReflectionUtility.All);
var objValue = type != typeof(object) ? DeserializeWithCoercion(token, type) : NodeToString(token);
value = formatterMethod.GetValue<string>(obj: this, args: [objValue, property]);
// The PropertyInfo is an optional second argument: formatters that don't need it
// can declare just the value parameter. Pass args matching the method's arity so
// both `Format(value)` and `Format(value, PropertyInfo)` shapes are supported.
object[] formatterArgs = formatterMethod.GetParameters().Length == 1
? [objValue]
: [objValue, property];
value = formatterMethod.GetValue<string>(obj: this, args: formatterArgs);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public interface ISolutionSerializer
/// For single file serializers, this checks the file extension.
/// </summary>
/// <param name="moniker">The moniker that represents the solution location.</param>
/// <returns>If this serilizer can open the solution.</returns>
/// <returns>If this serializer can open the solution.</returns>
bool IsSupported(string moniker);
}

Expand Down Expand Up @@ -86,7 +86,7 @@ public interface ISolutionSingleFileSerializer<TSettings> : ISolutionSerializer<
/// <summary>
/// Saves a solution model to a stream.
/// </summary>
/// <param name="stream">The stream to save the file..</param>
/// <param name="stream">The stream to save the file.</param>
/// <param name="model">The model to save.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>Task to track the asynchronous call status.</returns>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ bool ISolutionSerializer.IsSupported(string fullPath)

async Task<SolutionModel> ISolutionSerializer.OpenAsync(string moniker, CancellationToken cancellationToken)
{
using (FileStream reader = File.OpenRead(moniker))
{
return await this.ReadModelAsync(moniker, reader, cancellationToken);
}
// Plain `using` (not `await using`): FileStream does not implement IAsyncDisposable on
// netstandard2.0, so `await using` fails to compile there (CS8417). Synchronous disposal
// of a local read stream is fine across all target frameworks.
using FileStream reader = File.OpenRead(moniker);
return await this.ReadModelAsync(moniker, reader, cancellationToken);
}

async Task ISolutionSerializer.SaveAsync(string moniker, SolutionModel model, CancellationToken cancellationToken)
Expand All @@ -50,10 +51,10 @@ async Task ISolutionSerializer.SaveAsync(string moniker, SolutionModel model, Ca
_ = Directory.CreateDirectory(directory);
}

using (FileStream writer = File.OpenWrite(moniker))
{
await this.WriteModelAsync(moniker, model, writer, cancellationToken);
}
// Plain `using` (not `await using`): see OpenAsync — FileStream is not IAsyncDisposable
// on netstandard2.0 (CS8417). Synchronous disposal of a local write stream is fine here.
using FileStream writer = File.OpenWrite(moniker);
await this.WriteModelAsync(moniker, model, writer, cancellationToken);
}

private protected abstract Task<SolutionModel> ReadModelAsync(string? fullPath, Stream reader, CancellationToken cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ internal bool ApplyModelToXml(SolutionFolderModel modelFolder)

// Projects
List<(string ItemRef, SolutionProjectModel Item)> projectsInFolder = modelSolution.SolutionProjects.WhereToList(
(project, modelFolder) => ReferenceEquals(project.Parent, modelFolder),
(project, modelFolder) => (ItemRef: this.Root.ConvertToUserPath(project.ItemRef), Item: project),
(project, solutionFolderModel) => ReferenceEquals(project.Parent, solutionFolderModel),
(project, _) => (ItemRef: this.Root.ConvertToUserPath(project.ItemRef), Item: project),
modelFolder);
modified |= this.ApplyModelItemsToXml(
modelItems: projectsInFolder,
Expand Down
10 changes: 5 additions & 5 deletions tests/Fallout.Tooling.Tests/ToolOptionsArgumentsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ private class FormatToolOptions : ToolOptions
[Argument(Format = "{value}", FormatterType = typeof(Formatter), FormatterMethod = nameof(Formatter.FormatMinutes))]
public TimeSpan Minutes => Get<TimeSpan>(() => Minutes);

private string FormatTime(DateTime datetime, PropertyInfo property) => datetime.ToString("t", CultureInfo.InvariantCulture);
private string FormatDate(DateTime datetime, PropertyInfo property) => datetime.ToString("d", CultureInfo.InvariantCulture);
private string FormatTime(DateTime datetime) => datetime.ToString("t", CultureInfo.InvariantCulture);
private string FormatDate(DateTime datetime) => datetime.ToString("d", CultureInfo.InvariantCulture);
}

private static class Formatter
Expand All @@ -124,7 +124,7 @@ private class ListToolOptions : ToolOptions
[Argument(Format = "--param:{value}", Separator = " ", QuoteMultiple = true)] public IReadOnlyList<string> QuotedList => Get<List<string>>(() => QuotedList);
[Argument(Format = "--param={value}", FormatterMethod = nameof(Format))] public IReadOnlyList<bool> FormattedList => Get<List<bool>>(() => FormattedList);

private string Format(bool value, PropertyInfo property) => value.ToString().ToUpperInvariant();
private string Format(bool value) => value.ToString().ToUpperInvariant();
}

private readonly Dictionary<string, object> _simpleDictionary = new() { ["key1"] = 1, ["key2"] = "foobar" };
Expand All @@ -143,7 +143,7 @@ private class DictionaryToolOptions : ToolOptions
[Argument(Format = "-- {key}={value}", Separator = " ")] public IReadOnlyDictionary<string, object> WhitespaceDictionary => Get<Dictionary<string, object>>(() => WhitespaceDictionary);
[Argument(Format = "/p:{key}={value}", FormatterMethod = nameof(Format))] public IReadOnlyDictionary<string, object> FormattedDictionary => Get<Dictionary<string, object>>(() => FormattedDictionary);

private string Format(object value, PropertyInfo property) => value?.ToString()?.ToUpperInvariant();
private string Format(object value) => value?.ToString()?.ToUpperInvariant();
}

private readonly LookupTable<string, object> _simpleLookupTable = new() { ["key1"] = [1, 2], ["key2"] = [true, false] };
Expand All @@ -160,7 +160,7 @@ private class LookupToolOptions : ToolOptions
[Argument(Format = "--param:{key}={value}", Separator = ";", InnerSeparator = ",")] public ILookup<string, object> SeparatorLookup => Get<LookupTable<string, object>>(() => SeparatorLookup);
[Argument(Format = "--param {key} {value}", InnerSeparator = "+", FormatterMethod = nameof(Format))] public ILookup<string, object> FormattedLookup => Get<LookupTable<string, object>>(() => FormattedLookup);

private string Format(object value, PropertyInfo property) => value?.ToString()?.ToUpperInvariant();
private string Format(object value) => value?.ToString()?.ToUpperInvariant();
}

[Fact]
Expand Down
Loading