Skip to content
Merged
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
18 changes: 9 additions & 9 deletions src/build/ShimGen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
// first, arrange the lookups in a reasonable manner
// pkgPath -> framework -> dllPaths
var packageLayout = new Dictionary<string, Dictionary<NuGetFramework, List<(string dllPath, string dllName)>>>();
var dllsByDllName = new Dictionary<string, Dictionary<NuGetFramework, List<string>>>();
var dllsByDllName = new Dictionary<string, Dictionary<NuGetFramework, List<ModuleDefinition>>>();
foreach (var (pkgPath, libPath, framework, dllPath) in pkgList
.SelectMany(ta
=> ta.Item2.SelectMany(tb
Expand All @@ -85,6 +85,8 @@
continue;
}

var dll = ModuleDefinition.FromFile(dllPath, readerParams);

pathList.Add((dllPath, dllName));

if (!dllsByDllName.TryGetValue(dllName, out var dllPathList))
Expand All @@ -97,7 +99,7 @@
dllPathList.Add(framework, dllPathSet = new());
}

dllPathSet.Add(dllPath);
dllPathSet.Add(dll);
}

// collect the list of ALL target frameworks that we might care about
Expand Down Expand Up @@ -172,17 +174,17 @@
var importedSet = new Dictionary<string, ExportedType>();
foreach (var (targetTfm, assemblies) in frameworkAssemblies)
{
foreach (var (dllName, _) in assemblies)
foreach (var dllName in assemblies.Select(x => x.Item1).Distinct())
{
importedSet.Clear();

ModuleDefinition? backportsShim = null;
AssemblyDefinition? backportsShimAssembly = null;
AssemblyReference? backportsReference = null;

var bclShimPath = GetFrameworkKey(dllsByDllName[dllName], targetTfm, fwReducer).First();
var allDlls = dllsByDllName[dllName].Values.SelectMany(x => x).ToArray();

var bclShim = ModuleDefinition.FromFile(bclShimPath, readerParams);
var bclShim = allDlls.OrderByDescending(x => x.Assembly!.Version).First();

var bcl = KnownCorLibs.FromRuntimeInfo(
DotNetRuntimeInfo.Parse(
Expand All @@ -204,12 +206,10 @@

backportsReference = backportsReferenceBase.ImportWith(backportsShim.DefaultImporter);

foreach (var file in dllsByDllName[dllName].Values.SelectMany(x => x))
foreach (var file in allDlls)
{
bclShim = ModuleDefinition.FromFile(file, readerParams);

// go through all public types, make sure they exist in the shim, and generate the forwarder
foreach (var type in bclShim.TopLevelTypes)
foreach (var type in file.TopLevelTypes)
{
void ExportType(TypeDefinition type, bool nested, IImplementation impl)
{
Expand Down Expand Up @@ -297,7 +297,7 @@
}


static T GetFrameworkKey<T>(Dictionary<NuGetFramework, T> dict, NuGetFramework key, FrameworkReducer reducer)

Check warning on line 300 in src/build/ShimGen/Program.cs

View workflow job for this annotation

GitHub Actions / Build #26.3.1.89.1 / Build

The local function 'GetFrameworkKey' is declared but never used

Check warning on line 300 in src/build/ShimGen/Program.cs

View workflow job for this annotation

GitHub Actions / Build #26.3.1.89.1 / Build

The local function 'GetFrameworkKey' is declared but never used
{
var best = reducer.GetNearest(key, dict.Keys);
return dict[best!];
Expand Down