From 06e1ca2ffc36051551e4a9df38566528530f7164 Mon Sep 17 00:00:00 2001 From: Zev Spitz Date: Mon, 17 Jan 2022 23:09:30 +0200 Subject: [PATCH] Script -- output ports with no code files; replace !...Any with None --- .../DotnetUtils/DotnetUtils/Extensions.cs | 5 +++++ .../DotnetUtils/DotnetUtils/Program.cs | 22 ++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/00_Utilities/DotnetUtils/DotnetUtils/Extensions.cs b/00_Utilities/DotnetUtils/DotnetUtils/Extensions.cs index a0f52bee..11f05177 100644 --- a/00_Utilities/DotnetUtils/DotnetUtils/Extensions.cs +++ b/00_Utilities/DotnetUtils/DotnetUtils/Extensions.cs @@ -10,6 +10,11 @@ public static class Extensions { src.Select(x => selector(x.Item1, x.Item2, x.Item3)); public static IEnumerable<(T1, T2, int)> WithIndex(this IEnumerable<(T1, T2)> src) => src.Select((x, index) => (x.Item1, x.Item2, index)); + public static bool None(this IEnumerable src, Func? predicate = null) => + predicate is null ? + !src.Any() : + !src.Any(predicate); + public static bool IsNullOrWhitespace([NotNullWhen(false)] this string? s) => string.IsNullOrWhiteSpace(s); [return: NotNullIfNotNull("path")] diff --git a/00_Utilities/DotnetUtils/DotnetUtils/Program.cs b/00_Utilities/DotnetUtils/DotnetUtils/Program.cs index 5a3a70e5..560a7207 100644 --- a/00_Utilities/DotnetUtils/DotnetUtils/Program.cs +++ b/00_Utilities/DotnetUtils/DotnetUtils/Program.cs @@ -17,6 +17,7 @@ var actions = new (Action action, string description)[] { (multipleProjs, "Output multiple project files"), (checkProjects, "Check .csproj/.vbproj files for target framework, nullability etc."), (checkExecutableProject, "Check that there is at least one executable project per port"), + (noCodeFiles, "Output ports without any code files"), (printPortInfo, "Print info about a single port"), (generateMissingSlns, "Generate solution files when missing"), @@ -87,7 +88,7 @@ void printInfos() { } void missingSln() { - var data = infos.Where(x => !x.Slns.Any()).ToArray(); + var data = infos.Where(x => x.Slns.None()).ToArray(); foreach (var item in data) { WriteLine(item.LangPath); } @@ -98,7 +99,7 @@ void missingSln() { void unexpectedSlnName() { var counter = 0; foreach (var item in infos) { - if (!item.Slns.Any()) { continue; } + if (item.Slns.None()) { continue; } var expectedSlnName = $"{item.GameName}.sln"; if (item.Slns.Contains(Combine(item.LangPath, expectedSlnName), StringComparer.InvariantCultureIgnoreCase)) { continue; } @@ -125,7 +126,7 @@ void multipleSlns() { } void missingProj() { - var data = infos.Where(x => !x.Projs.Any()).ToArray(); + var data = infos.Where(x => x.Projs.None()).ToArray(); foreach (var item in data) { WriteLine(item.LangPath); } @@ -136,7 +137,7 @@ void missingProj() { void unexpectedProjName() { var counter = 0; foreach (var item in infos) { - if (!item.Projs.Any()) { continue; } + if (item.Projs.None()) { continue; } var expectedProjName = $"{item.GameName}.{item.ProjExt}"; if (item.Projs.Contains(Combine(item.LangPath, expectedProjName))) { continue; } @@ -164,7 +165,7 @@ void multipleProjs() { } void generateMissingSlns() { - foreach (var item in infos.Where(x => !x.Slns.Any())) { + foreach (var item in infos.Where(x => x.Slns.None())) { var result = RunProcess("dotnet", $"new sln -n {item.GameName} -o {item.LangPath}"); WriteLine(result); @@ -177,7 +178,7 @@ void generateMissingSlns() { } void generateMissingProjs() { - foreach (var item in infos.Where(x => !x.Projs.Any())) { + foreach (var item in infos.Where(x => x.Projs.None())) { // We can't use the dotnet command to create a new project using the built-in console template, because part of that template // is a Program.cs / Program.vb file. If there already are code files, there's no need to add a new empty one; and // if there's already such a file, it might try to overwrite it. @@ -284,6 +285,15 @@ void checkExecutableProject() { } } +void noCodeFiles() { + var qry = infos + .Where(x => x.CodeFiles.None()) + .OrderBy(x => x.Lang); + foreach (var item in qry) { + WriteLine(item.LangPath); + } +} + void tryBuild() { // if has code files, try to build }