From 4ab66204c453a0005fa8c9cd827d7f88ea7cb6e6 Mon Sep 17 00:00:00 2001 From: Patrick Stevens <3138005+Smaug123@users.noreply.github.com> Date: Sun, 9 Jun 2024 10:03:48 +0100 Subject: [PATCH] Cope with multiple TargetFrameworks (#46) --- TestRunner/Program.fs | 54 +++++++++++++++++++++++++++++------- TestRunner/RuntimeConfig.fs | 3 +- TestRunner/TestRunner.fsproj | 2 +- nix/deps.nix | 4 +-- 4 files changed, 49 insertions(+), 14 deletions(-) diff --git a/TestRunner/Program.fs b/TestRunner/Program.fs index 1fe22e0..fcf8685 100644 --- a/TestRunner/Program.fs +++ b/TestRunner/Program.fs @@ -54,23 +54,57 @@ module Program = |> Option.defaultValue RollForward.Minor | s -> RollForward.Parse s - let desired = Version config.Framework.Version + let desiredVersions = + match config.Framework with + | Some f -> [ Version f.Version, f.Name ] + | None -> + + match config.Frameworks with + | Some f -> f |> List.map (fun f -> Version f.Version, f.Name) + | None -> + failwith + "Could not deduce a framework version due to lack of either Framework or Frameworks in runtimeconfig" + + let compatiblyNamedRuntimes = + f.Frameworks + |> Seq.collect (fun availableFramework -> + desiredVersions + |> List.choose (fun (desiredVersion, desiredName) -> + if desiredName = availableFramework.Name then + Some + {| + Desired = desiredVersion + Name = desiredName + Installed = availableFramework + InstalledVersion = Version availableFramework.Version + |} + else + None + ) + ) + |> Seq.toList match rollForward with | RollForward.Minor -> let available = - f.Frameworks - |> Seq.choose (fun fi -> - if fi.Name = config.Framework.Name then - Some (fi, Version fi.Version) - else - None + compatiblyNamedRuntimes + |> Seq.filter (fun data -> + data.InstalledVersion.Major = data.Desired.Major + && data.InstalledVersion.Minor >= data.Desired.Minor ) - |> Seq.filter (fun (_, version) -> version.Major = desired.Major && version.Minor >= desired.Minor) - |> Seq.tryMinBy (fun (_, version) -> version.Minor, version.Build) + |> Seq.groupBy (fun data -> data.Name) + |> Seq.map (fun (name, data) -> + let data = + data + |> Seq.minBy (fun data -> data.InstalledVersion.Minor, data.InstalledVersion.Build) + + name, data.Installed + ) + // TODO: how do we select between many available frameworks? + |> Seq.tryHead match available with - | Some (f, _) -> Some (Choice1Of2 f) + | Some (_, f) -> Some (Choice1Of2 f) | None -> // TODO: maybe we can ask the SDK. But we keep on trucking: maybe we're self-contained, // and we'll actually find all the runtime next to the DLL. diff --git a/TestRunner/RuntimeConfig.fs b/TestRunner/RuntimeConfig.fs index 5f1517f..9e136be 100644 --- a/TestRunner/RuntimeConfig.fs +++ b/TestRunner/RuntimeConfig.fs @@ -14,7 +14,8 @@ type FrameworkDescription = type RuntimeOptions = { Tfm : string - Framework : FrameworkDescription + Framework : FrameworkDescription option + Frameworks : FrameworkDescription list option RollForward : string option } diff --git a/TestRunner/TestRunner.fsproj b/TestRunner/TestRunner.fsproj index a193c3a..777e385 100644 --- a/TestRunner/TestRunner.fsproj +++ b/TestRunner/TestRunner.fsproj @@ -39,7 +39,7 @@ - + diff --git a/nix/deps.nix b/nix/deps.nix index 2ff18a9..b06c555 100644 --- a/nix/deps.nix +++ b/nix/deps.nix @@ -183,8 +183,8 @@ }) (fetchNuGet { pname = "WoofWare.DotnetRuntimeLocator"; - version = "0.1.2"; - sha256 = "0kwkq28ddzc0bpr22jmgcl8dhnhg776gf6l054rsxw8lrvpwhmv9"; + version = "0.1.3"; + sha256 = "0qw41mcvx4qy012pj1dlpdfwsz036qrx7xnzsirk5fz715f1a45m"; }) (fetchNuGet { pname = "WoofWare.Myriad.Plugins";