Skip to content

Commit

Permalink
Adjust ApiDiffHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkatz6 committed Feb 8, 2024
1 parent 84e2fa9 commit 1bc946d
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions nukebuild/ApiDiffHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Nuke.Common.Tooling;
using Serilog;
using static Serilog.Log;

public static class ApiDiffHelper
Expand Down Expand Up @@ -47,13 +48,18 @@ public static async Task GetDiff(
var baselineDllPath = await ExtractDll("baseline", baselineDll, tempFolder);

var targetTfm = baselineDll.target;
if (s_tfmRedirects.FirstOrDefault(t => baselineDll.target.StartsWith(t.oldTfm)).newTfm is {} newTfm)
var targetDll = targetDlls.FirstOrDefault(e =>
e.target.StartsWith(targetTfm) && e.entry.Name == baselineDll.entry.Name);
if (targetDll is null)
{
targetTfm = newTfm;
if (s_tfmRedirects.FirstOrDefault(t => baselineDll.target.StartsWith(t.oldTfm)).newTfm is {} newTfm)
{
targetTfm = newTfm;
targetDll = targetDlls.FirstOrDefault(e =>
e.target.StartsWith(targetTfm) && e.entry.Name == baselineDll.entry.Name);
}
}

var targetDll = targetDlls.FirstOrDefault(e =>
e.target.StartsWith(targetTfm) && e.entry.Name == baselineDll.entry.Name);
if (targetDll?.entry is null)
{
throw new InvalidOperationException($"Some assemblies are missing in the new package {packageId}: {baselineDll.entry.Name} for {baselineDll.target}");
Expand Down Expand Up @@ -142,16 +148,32 @@ public static async Task ValidatePackage(
var baselineDllPath = await ExtractDll("baseline", baselineDll, tempFolder);

var targetTfm = baselineDll.target;
if (s_tfmRedirects.FirstOrDefault(t => baselineDll.target.StartsWith(t.oldTfm)).newTfm is {} newTfm)
var targetDll = targetDlls.FirstOrDefault(e =>
e.target.StartsWith(targetTfm) && e.entry.Name == baselineDll.entry.Name);
if (targetDll?.entry is null)
{
targetTfm = newTfm;
if (s_tfmRedirects.FirstOrDefault(t => baselineDll.target.StartsWith(t.oldTfm)).newTfm is {} newTfm)
{
targetTfm = newTfm;
targetDll = targetDlls.FirstOrDefault(e =>
e.target.StartsWith(targetTfm) && e.entry.Name == baselineDll.entry.Name);
}
}
if (targetDll?.entry is null && targetDlls.Count == 1)
{
targetDll = targetDlls.First();
Warning(
$"Some assemblies are missing in the new package {packageId}: {baselineDll.entry.Name} for {baselineDll.target}." +
$"Resolved: {targetDll.target} ({targetDll.entry.Name})");
}

var targetDll = targetDlls.FirstOrDefault(e =>
e.target.StartsWith(targetTfm) && e.entry.Name == baselineDll.entry.Name);
if (targetDll.entry is null)
if (targetDll?.entry is null)
{
throw new InvalidOperationException($"Some assemblies are missing in the new package {packageId}: {baselineDll.entry.Name} for {baselineDll.target}");
var actualTargets = string.Join(", ",
targetDlls.Select(d => $"{d.target} ({baselineDll.entry.Name})"));
throw new InvalidOperationException(
$"Some assemblies are missing in the new package {packageId}: {baselineDll.entry.Name} for {baselineDll.target}."
+ $"\r\nActual targets: {actualTargets}.");
}

var targetDllPath = await ExtractDll("target", targetDll, tempFolder);
Expand Down

0 comments on commit 1bc946d

Please sign in to comment.