Skip to content

Commit

Permalink
refactoring coreclrembedding.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
agracio committed Nov 28, 2024
1 parent 22d4b57 commit 886886d
Showing 1 changed file with 27 additions and 33 deletions.
60 changes: 27 additions & 33 deletions src/double/Edge.js/dotnetcore/coreclrembedding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,6 @@ private void AddDependencies(DependencyContext dependencyContext, bool standalon

AddCompileDependencies(dependencyContext, standalone);

var runtimePath = Path.GetDirectoryName(RuntimeEnvironment.RuntimePath);

foreach (RuntimeLibrary runtimeLibrary in dependencyContext.RuntimeLibraries)
{
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Processing runtime dependency {1} {0}", runtimeLibrary.Name, runtimeLibrary.Type);
Expand All @@ -268,8 +266,6 @@ private void AddDependencies(DependencyContext dependencyContext, bool standalon
if (_libraries.ContainsKey(runtimeLibrary.Name) && CompileAssemblies.ContainsKey(runtimeLibrary.Name))
{
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Already present in the runtime assemblies list, skipping");
AddNativeAssemblies(dependencyContext, runtimeLibrary);
AddSupplementaryRuntime(runtimeLibrary);
continue;
}

Expand Down Expand Up @@ -412,60 +408,39 @@ private void AddDependencyFromRuntime(RuntimeLibrary runtimeLibrary)
if (CompileAssemblies.ContainsKey(runtimeLibrary.Name) && _libraries.ContainsKey(runtimeLibrary.Name)) return;

var runtimePath = Path.GetDirectoryName(RuntimeEnvironment.RuntimePath);
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Processing dependency {1} {0} using runtime path {2}", runtimeLibrary.Name, runtimeLibrary.Type, runtimePath);
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Processing runtime dependency {1} {0} using runtime path {2}", runtimeLibrary.Name, runtimeLibrary.Type, runtimePath);
if (string.IsNullOrEmpty(runtimePath))
{
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - runtime path could not be resolved, skipping");
return;
}

var asset = runtimeLibrary.Name;
if (!asset.EndsWith(".dll") && !asset.EndsWith(".sni"))
{
asset += ".dll";
}

if (asset == "runtime.native.System.dll")
{
asset = "System.dll";
}

if (asset == "NETStandard.Library.dll")
{
asset = "netstandard.dll";
}
asset = ReplaceAssetName(asset);

var assemblyPath = Path.Combine(runtimePath, Path.GetFileName(asset));
if (File.Exists(assemblyPath))
{
CompileAssemblies.TryAdd(runtimeLibrary.Name, assemblyPath);
_libraries.TryAdd(runtimeLibrary.Name, assemblyPath);

DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added dependency {1} from {0}", assemblyPath, runtimeLibrary.Name);
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added runtime dependency {1} from {0}", assemblyPath, runtimeLibrary.Name);
AddSupplementaryRuntime(runtimeLibrary);
}
else
{
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Could not add dependency {0}", assemblyPath);
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Could not runtime add dependency {0}", assemblyPath);
}
}

private void AddDependencyFromAppDirectory(RuntimeLibrary runtimeLibrary)
{
if (CompileAssemblies.ContainsKey(runtimeLibrary.Name) && _libraries.ContainsKey(runtimeLibrary.Name)) return;

DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Processing dependency {1} {0} using .nuget packages and ApplicationDirectory path.", runtimeLibrary.Name, runtimeLibrary.Type);
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Processing runtime dependency {1} {0} using .nuget packages and ApplicationDirectory path.", runtimeLibrary.Name, runtimeLibrary.Type);

var asset = runtimeLibrary.Name;
if (!asset.EndsWith(".dll") && !asset.EndsWith(".sni"))
{
asset += ".dll";
}

if (asset == "runtime.native.System.dll")
{
asset = "System.dll";
}
asset = ReplaceAssetName(asset);

var assemblyPath = Path.Combine(_packagesPath, runtimeLibrary.Name.ToLower(), runtimeLibrary.Version, Path.GetFileName(asset));

Expand All @@ -478,13 +453,32 @@ private void AddDependencyFromAppDirectory(RuntimeLibrary runtimeLibrary)
CompileAssemblies.TryAdd(runtimeLibrary.Name, assemblyPath);
_libraries.TryAdd(runtimeLibrary.Name, assemblyPath);

DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added dependency {1} from {0}", assemblyPath, runtimeLibrary.Name);
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added runtime dependency {1} from {0}", assemblyPath, runtimeLibrary.Name);
AddSupplementaryRuntime(runtimeLibrary);
}
else
{
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Could not add dependency {0}", assemblyPath);
DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Could not runtime add dependency {0}", assemblyPath);
}
}

private string ReplaceAssetName(string asset)
{
if (!asset.EndsWith(".dll") && !asset.EndsWith(".sni"))
{
asset += ".dll";
}

if (asset == "runtime.native.System.dll")
{
asset = "System.dll";
}

if (asset == "NETStandard.Library.dll")
{
asset = "netstandard.dll";
}
return asset;
}

private void AddCompileDependencies(DependencyContext dependencyContext, bool standalone)
Expand Down

0 comments on commit 886886d

Please sign in to comment.