From 22d4b573bcec190e1551fc2fbc1808bac85092ee Mon Sep 17 00:00:00 2001 From: agracio Date: Wed, 27 Nov 2024 14:10:56 +0000 Subject: [PATCH] refactoring coreclrembedding.cs, updating test.js --- package-lock.json | 4 +- package.json | 2 +- .../Edge.js/dotnetcore/coreclrembedding.cs | 144 ++++++++---------- tools/test.js | 44 +++--- 4 files changed, 90 insertions(+), 104 deletions(-) diff --git a/package-lock.json b/package-lock.json index 334fa4ef..a419e12c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "edge-js", - "version": "23.1.2", + "version": "23.1.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "edge-js", - "version": "23.1.2", + "version": "23.1.3", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 05f78381..21e182ad 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "url": "http://tomasz.janczuk.org", "twitter": "tjanczuk" }, - "version": "23.1.2", + "version": "23.1.3", "description": "Edge.js: run .NET and Node.js in-process on Windows, Mac OS, and Linux", "tags": [ "owin", diff --git a/src/double/Edge.js/dotnetcore/coreclrembedding.cs b/src/double/Edge.js/dotnetcore/coreclrembedding.cs index b7cc41fb..5c149582 100644 --- a/src/double/Edge.js/dotnetcore/coreclrembedding.cs +++ b/src/double/Edge.js/dotnetcore/coreclrembedding.cs @@ -259,10 +259,15 @@ private void AddDependencies(DependencyContext dependencyContext, bool standalon { DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added runtime assembly {1} from {0}", CompileAssemblies[runtimeLibrary.Name], runtimeLibrary.Name); _libraries[runtimeLibrary.Name] = CompileAssemblies[runtimeLibrary.Name]; + AddNativeAssemblies(dependencyContext, runtimeLibrary); + AddSupplementaryRuntime(runtimeLibrary); + continue; + } 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; @@ -278,25 +283,8 @@ private void AddDependencies(DependencyContext dependencyContext, bool standalon if (assets.Any()) { string assetPath = assets[0]; - - string assemblyPath; - if(runtimeLibrary.Type == "project") - assemblyPath = Path.Combine(RuntimeEnvironment.ApplicationDirectory, assetPath); - else if (standalone) - assemblyPath = Path.Combine(RuntimeEnvironment.ApplicationDirectory, Path.GetFileName(assetPath)); - else - { - assemblyPath = Path.Combine(_packagesPath, runtimeLibrary.Name.ToLower(), runtimeLibrary.Version, assetPath.Replace('/', Path.DirectorySeparatorChar).ToLower()); - if(!File.Exists(assemblyPath)) - assemblyPath = Path.Combine(_packagesPath, runtimeLibrary.Name.ToLower(), runtimeLibrary.Version, assetPath.Replace('/', Path.DirectorySeparatorChar)); - - } - string libraryNameFromPath = Path.GetFileNameWithoutExtension(assemblyPath); - - if (!File.Exists(assemblyPath) && !string.IsNullOrEmpty(runtimePath)) - { - assemblyPath = Path.Combine(runtimePath, Path.GetFileName(assemblyPath)); - } + + var assemblyPath = ResolveAssemblyPath(assetPath, runtimeLibrary.Version, runtimeLibrary.Type, standalone); if (!_libraries.ContainsKey(runtimeLibrary.Name)) { @@ -305,12 +293,7 @@ private void AddDependencies(DependencyContext dependencyContext, bool standalon _libraries[runtimeLibrary.Name] = assemblyPath; DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added runtime assembly {1} from {0}", assemblyPath, runtimeLibrary.Name); CompileAssemblies.TryAdd(runtimeLibrary.Name, assemblyPath); - if (!string.Equals(runtimeLibrary.Name, libraryNameFromPath, StringComparison.CurrentCultureIgnoreCase)) - { - _libraries.TryAdd(libraryNameFromPath, assemblyPath); - CompileAssemblies.TryAdd(libraryNameFromPath, assemblyPath); - DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added supplementary runtime assembly {1} from {0}", assemblyPath, libraryNameFromPath); - } + AddSupplementaryRuntime(runtimeLibrary); } else { @@ -332,6 +315,52 @@ private void AddDependencies(DependencyContext dependencyContext, bool standalon AddNativeAssemblies(dependencyContext, runtimeLibrary); } } + + private string ResolveAssemblyPath(string libraryName, string libraryVersion, string libraryType, bool standalone) + { + var runtimePath = Path.GetDirectoryName(RuntimeEnvironment.RuntimePath); + var assemblyPath = libraryName.Replace('/', Path.DirectorySeparatorChar); + var normalizedPath = libraryName.Replace('/', Path.DirectorySeparatorChar); + + if (libraryType == "project") + { + assemblyPath = Path.Combine(RuntimeEnvironment.ApplicationDirectory, Path.GetFileName(normalizedPath)); + } + if (standalone) + { + if (File.Exists(Path.Combine(RuntimeEnvironment.ApplicationDirectory, Path.GetFileName(normalizedPath)))) + { + assemblyPath = Path.Combine(RuntimeEnvironment.ApplicationDirectory, Path.GetFileName(normalizedPath)); + } + else if (File.Exists(Path.Combine(RuntimeEnvironment.ApplicationDirectory, "refs", Path.GetFileName(normalizedPath)))) + { + assemblyPath = Path.Combine(RuntimeEnvironment.ApplicationDirectory, "refs", Path.GetFileName(normalizedPath)); + } + else if(!string.IsNullOrEmpty(runtimePath)) + { + assemblyPath = Path.Combine(runtimePath, Path.GetFileName(normalizedPath)); + } + } + else + { + assemblyPath = Path.Combine(_packagesPath, libraryName.ToLower(), libraryVersion, normalizedPath.ToLower()); + if(!File.Exists(assemblyPath)) + { + assemblyPath = Path.Combine(_packagesPath, libraryName.ToLower(), libraryVersion, normalizedPath); + } + if(!File.Exists(assemblyPath) && File.Exists(Path.Combine(RuntimeEnvironment.ApplicationDirectory, Path.GetFileName(normalizedPath)))) + { + assemblyPath = Path.Combine(RuntimeEnvironment.ApplicationDirectory, Path.GetFileName(normalizedPath)); + } + } + + if (!File.Exists(assemblyPath) && !string.IsNullOrEmpty(runtimePath)) + { + assemblyPath = Path.Combine(runtimePath, Path.GetFileName(assemblyPath)); + } + + return assemblyPath; + } private void AddSupplementaryRuntime(RuntimeLibrary runtimeLibrary) { @@ -360,6 +389,10 @@ private void AddNativeAssemblies(DependencyContext dependencyContext, RuntimeLib { nativeAssemblyPath = Path.Combine(runtimePath, nativeAssembly.Replace('/', Path.DirectorySeparatorChar)); } + if (!File.Exists(nativeAssemblyPath) && !string.IsNullOrEmpty(runtimePath)) + { + nativeAssemblyPath = Path.Combine(runtimePath, Path.GetFileName(nativeAssembly.Replace('/', Path.DirectorySeparatorChar))); + } if (File.Exists(nativeAssemblyPath)) { @@ -409,20 +442,12 @@ private void AddDependencyFromRuntime(RuntimeLibrary runtimeLibrary) _libraries.TryAdd(runtimeLibrary.Name, assemblyPath); DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added dependency {1} from {0}", assemblyPath, runtimeLibrary.Name); - - var libraryNameFromPath = Path.GetFileNameWithoutExtension(assemblyPath); - if (!string.Equals(runtimeLibrary.Name, libraryNameFromPath, StringComparison.CurrentCultureIgnoreCase)) - { - DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added supplementary assembly {1} from {0}", assemblyPath, libraryNameFromPath); - CompileAssemblies.TryAdd(libraryNameFromPath, assemblyPath); - _libraries.TryAdd(libraryNameFromPath, assemblyPath); - } + AddSupplementaryRuntime(runtimeLibrary); } else { DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Could not add dependency {0}", assemblyPath); } - } private void AddDependencyFromAppDirectory(RuntimeLibrary runtimeLibrary) @@ -454,14 +479,7 @@ private void AddDependencyFromAppDirectory(RuntimeLibrary runtimeLibrary) _libraries.TryAdd(runtimeLibrary.Name, assemblyPath); DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added dependency {1} from {0}", assemblyPath, runtimeLibrary.Name); - - var libraryNameFromPath = Path.GetFileNameWithoutExtension(assemblyPath); - if (!string.Equals(runtimeLibrary.Name, libraryNameFromPath, StringComparison.CurrentCultureIgnoreCase)) - { - DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added supplementary assembly {1} from {0}", assemblyPath, libraryNameFromPath); - CompileAssemblies.TryAdd(libraryNameFromPath, assemblyPath); - _libraries.TryAdd(libraryNameFromPath, assemblyPath); - } + AddSupplementaryRuntime(runtimeLibrary); } else { @@ -471,57 +489,21 @@ private void AddDependencyFromAppDirectory(RuntimeLibrary runtimeLibrary) private void AddCompileDependencies(DependencyContext dependencyContext, bool standalone) { - var runtimePath = Path.GetDirectoryName(RuntimeEnvironment.RuntimePath); foreach (CompilationLibrary compileLibrary in dependencyContext.CompileLibraries) { if (compileLibrary.Assemblies.Count == 0 || CompileAssemblies.ContainsKey(compileLibrary.Name)) { continue; } - - var assemblyPath = compileLibrary.Assemblies[0].Replace('/', Path.DirectorySeparatorChar); - var normalizedPath = compileLibrary.Assemblies[0].Replace('/', Path.DirectorySeparatorChar); - - DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Processing compile assembly {1} {0} {2}", compileLibrary.Name, compileLibrary.Type, compileLibrary.Assemblies[0]); - - if (standalone) - { - if (File.Exists(Path.Combine(RuntimeEnvironment.ApplicationDirectory, Path.GetFileName(normalizedPath)))) - { - assemblyPath = Path.Combine(RuntimeEnvironment.ApplicationDirectory, Path.GetFileName(normalizedPath)); - } - else if (File.Exists(Path.Combine(RuntimeEnvironment.ApplicationDirectory, "refs", Path.GetFileName(normalizedPath)))) - { - assemblyPath = Path.Combine(RuntimeEnvironment.ApplicationDirectory, "refs", Path.GetFileName(normalizedPath)); - } - else if(!string.IsNullOrEmpty(runtimePath) && File.Exists(Path.Combine(runtimePath, Path.GetFileName(normalizedPath)))) - { - assemblyPath = Path.Combine(runtimePath, Path.GetFileName(normalizedPath)); - } - } - else - { - assemblyPath = Path.Combine(_packagesPath, compileLibrary.Name.ToLower(), compileLibrary.Version, normalizedPath.ToLower()); - if(!File.Exists(assemblyPath)) - { - assemblyPath = Path.Combine(_packagesPath, compileLibrary.Name.ToLower(), compileLibrary.Version, normalizedPath); - } - if(!File.Exists(assemblyPath) && File.Exists(Path.Combine(RuntimeEnvironment.ApplicationDirectory, Path.GetFileName(normalizedPath)))) - { - assemblyPath = Path.Combine(RuntimeEnvironment.ApplicationDirectory, Path.GetFileName(normalizedPath)); - } - } - if (!File.Exists(assemblyPath) && !string.IsNullOrEmpty(runtimePath)) - { - assemblyPath = Path.Combine(runtimePath, Path.GetFileName(assemblyPath)); - } + DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Processing compile assembly {1} {0} {2}", compileLibrary.Name, compileLibrary.Type, compileLibrary.Assemblies[0]); + var assemblyPath = ResolveAssemblyPath(compileLibrary.Assemblies[0], compileLibrary.Version, compileLibrary.Type, standalone); if (!CompileAssemblies.ContainsKey(compileLibrary.Name)) { - var libraryNameFromPath = Path.GetFileNameWithoutExtension(assemblyPath); if (File.Exists(assemblyPath)) { + var libraryNameFromPath = Path.GetFileNameWithoutExtension(assemblyPath); CompileAssemblies[compileLibrary.Name] = assemblyPath; DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added compile assembly {1} from {0}", assemblyPath, compileLibrary.Name); if (!string.Equals(compileLibrary.Name, libraryNameFromPath, StringComparison.CurrentCultureIgnoreCase)) diff --git a/tools/test.js b/tools/test.js index e14b1b81..a7760463 100644 --- a/tools/test.js +++ b/tools/test.js @@ -24,28 +24,32 @@ if(runner === 'all' && process.platform === 'win32'){ delete process.env.EDGE_USE_CORECLR } -if (!process.env.EDGE_USE_CORECLR) { - if (process.platform !== 'win32') { - buildParameters = buildParameters.concat(['-sdk:4.5']); - } +function build(){ + if (!process.env.EDGE_USE_CORECLR) { + if (process.platform !== 'win32') { + buildParameters = buildParameters.concat(['-sdk:4.5']); + } - var compiler = 'C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\csc.exe' + var compiler = 'C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\csc.exe' - run(process.platform === 'win32' ? compiler : 'mcs', buildParameters, runOnSuccess); -} + run(process.platform === 'win32' ? compiler : 'mcs', buildParameters, runOnSuccess); + } -else { - run(process.platform === 'win32' ? 'dotnet.exe' : 'dotnet', ['restore'], function(code, signal) { - if (code === 0) { - run(process.platform === 'win32' ? 'dotnet.exe' : 'dotnet', ['build'], function(code, signal) { - if (code === 0) { - run('cp', ['../test/bin/Debug/net6.0/test.dll', '../test/Edge.Tests.CoreClr.dll'], runOnSuccess); - } - }); - } - }); + else { + run(process.platform === 'win32' ? 'dotnet.exe' : 'dotnet', ['restore'], function(code, signal) { + if (code === 0) { + run(process.platform === 'win32' ? 'dotnet.exe' : 'dotnet', ['build'], function(code, signal) { + if (code === 0) { + run('cp', ['../test/bin/Debug/net6.0/test.dll', '../test/Edge.Tests.CoreClr.dll'], runOnSuccess); + } + }); + } + }); + } } +build(); + function run(cmd, args, onClose){ var params = process.env.EDGE_USE_CORECLR ? {cwd: testDir} : {}; @@ -92,7 +96,7 @@ function runOnSuccess(code, signal) { if(!runner) { - spawn('node', [mocha, testDir, '-R', 'spec', '-t', '10000', '-n', 'expose-gc'], { + spawn('node', [mocha, testDir, '-R', 'spec', '-t', '15000', '-n', 'expose-gc'], { stdio: 'inherit' }).on('error', function(err) { console.log(err); @@ -113,7 +117,7 @@ function runOnSuccess(code, signal) { testDir, '--reporter', 'mocha-multi-reporters', '--reporter-options', `configFile=./test/${config},cmrOutput=mocha-junit-reporter+mochaFile+${framework}:mochawesome+reportFilename+${framework}`, - '-t', '10000', + '-t', '15000', '-n', 'expose-gc' ], { stdio: 'inherit' @@ -122,7 +126,7 @@ function runOnSuccess(code, signal) { { if(!process.env.EDGE_USE_CORECLR){ process.env.EDGE_USE_CORECLR = 1; - runOnSuccess(0, signal); + build(); } else{ mergeFiles();