Skip to content

Commit

Permalink
Move unmanaged assemblies check to centralized location
Browse files Browse the repository at this point in the history
  • Loading branch information
GeertvanHorrik committed Sep 20, 2024
1 parent 7ae469c commit bf3c7ac
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions src/Costura.Fody/ResourceEmbedder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using Fody;
using Mono.Cecil;
Expand Down Expand Up @@ -268,8 +269,7 @@ private IEnumerable<Reference> GetFilteredReferences(IEnumerable<Reference> refe
var assemblyName = Path.GetFileNameWithoutExtension(reference.FileName);

if (includeList.Any(x => CompareAssemblyName(x, assemblyName)) &&
config.UnmanagedWinX86Assemblies.All(x => !CompareAssemblyName(x, assemblyName)) &&
config.UnmanagedWinX64Assemblies.All(x => !CompareAssemblyName(x, assemblyName)))
!IsUnmanagedAssemblyReference(reference, config))
{
skippedAssemblies.Remove(includeList.First(x => CompareAssemblyName(x, assemblyName)));
yield return reference;
Expand Down Expand Up @@ -313,8 +313,7 @@ private IEnumerable<Reference> GetFilteredReferences(IEnumerable<Reference> refe
var assemblyName = Path.GetFileNameWithoutExtension(reference.FileName);

if (excludeList.Any(x => CompareAssemblyName(x, assemblyName)) ||
config.UnmanagedWinX86Assemblies.Any(x => CompareAssemblyName(x, assemblyName)) ||
config.UnmanagedWinX64Assemblies.Any(x => CompareAssemblyName(x, assemblyName)))
IsUnmanagedAssemblyReference(reference, config))
{
continue;
}
Expand All @@ -331,15 +330,36 @@ private IEnumerable<Reference> GetFilteredReferences(IEnumerable<Reference> refe
{
var assemblyName = Path.GetFileNameWithoutExtension(reference.FileName);

if (config.UnmanagedWinX86Assemblies.All(x => !CompareAssemblyName(x, assemblyName)) &&
config.UnmanagedWinX64Assemblies.All(x => !CompareAssemblyName(x, assemblyName)))
if (!IsUnmanagedAssemblyReference(reference, config))
{
yield return reference;
}
}
}
}

private bool IsUnmanagedAssemblyReference(Reference reference, Configuration config)
{
var assemblyName = Path.GetFileNameWithoutExtension(reference.FileName);

var listsToCheck = new[]
{
config.UnmanagedWinX86Assemblies,
config.UnmanagedWinX64Assemblies,
config.UnmanagedWinArm64Assemblies
};

foreach (var listToCheck in listsToCheck)
{
if (listToCheck.Any(x => CompareAssemblyName(x, assemblyName)))
{
return true;
}
}

return false;
}

private IEnumerable<Reference> GetFilteredRuntimeReferences(IEnumerable<Reference> references, Configuration config)
{
references = references.Where(_ => _.IsRuntimeReference);
Expand Down Expand Up @@ -413,8 +433,7 @@ private IEnumerable<Reference> GetFilteredRuntimeReferences(IEnumerable<Referenc
{
var assemblyName = Path.GetFileNameWithoutExtension(reference.FileName);

if (config.UnmanagedWinX86Assemblies.All(x => !CompareAssemblyName(x, assemblyName)) &&
config.UnmanagedWinX64Assemblies.All(x => !CompareAssemblyName(x, assemblyName)))
if (IsUnmanagedAssemblyReference(reference, config))
{
yield return reference;
}
Expand Down

0 comments on commit bf3c7ac

Please sign in to comment.