diff --git a/Makefile b/Makefile index 8b47b4507..1caa2f69a 100644 --- a/Makefile +++ b/Makefile @@ -159,9 +159,7 @@ run-android: $(ATESTS) run-test-jnimarshal: bin/Test$(CONFIGURATION)/Java.Interop.Export-Tests.dll bin/Test$(CONFIGURATION)/$(JAVA_INTEROP_LIB) MONO_TRACE_LISTENER=Console.Out \ $(RUNTIME) bin/$(CONFIGURATION)/jnimarshalmethod-gen.exe -v -L $(JI_MONO_LIB_PATH)mono/4.5 -L $(JI_MONO_LIB_PATH)mono/4.5/Facades "$<" - $(RM) "$<" "$(basename $<)-JniMarshalMethods.dll" - mv "$(basename $<)-new.dll" "$<" - mv "$(basename $<)-new.pdb" "$(basename $<).pdb" + $(RM) "$(basename $<)-JniMarshalMethods.dll" $(call RUN_TEST,$<) diff --git a/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs b/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs index c596fed86..921e9bef9 100644 --- a/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs +++ b/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs @@ -110,6 +110,18 @@ public Dictionary<string, AssemblyDefinition> ToResolverCache () return new Dictionary<string, AssemblyDefinition>(cache); } + public bool AddToCache (AssemblyDefinition assembly) + { + var name = Path.GetFileNameWithoutExtension (assembly.MainModule.FileName); + + if (cache.ContainsKey (name)) + return false; + + cache [name] = assembly; + + return true; + } + public virtual AssemblyDefinition Load (string fileName, bool forceLoad = false) { if (!File.Exists (fileName)) diff --git a/tools/jnimarshalmethod-gen/App.cs b/tools/jnimarshalmethod-gen/App.cs index 0c1902ac9..b098dac5e 100644 --- a/tools/jnimarshalmethod-gen/App.cs +++ b/tools/jnimarshalmethod-gen/App.cs @@ -62,6 +62,11 @@ public static int Main (string [] args) return 0; } + var readWriteParameters = new ReaderParameters { + AssemblyResolver = resolver, + ReadSymbols = true, + ReadWrite = true, + }; foreach (var assembly in assemblies) { if (!File.Exists (assembly)) { Error ($"Path '{assembly}' does not exist."); @@ -69,7 +74,8 @@ public static int Main (string [] args) } resolver.SearchDirectories.Add (Path.GetDirectoryName (assembly)); - resolver.Load (assembly); + var ad = AssemblyDefinition.ReadAssembly (assembly, readWriteParameters); + resolver.AddToCache (ad); try { CreateMarshalMethodAssembly (assembly); diff --git a/tools/jnimarshalmethod-gen/TypeMover.cs b/tools/jnimarshalmethod-gen/TypeMover.cs index 0ba1baacf..e2e425666 100644 --- a/tools/jnimarshalmethod-gen/TypeMover.cs +++ b/tools/jnimarshalmethod-gen/TypeMover.cs @@ -46,11 +46,10 @@ public void Move () return; } - var newName = $"{Path.Combine (Path.GetDirectoryName (Destination.MainModule.FileName), Path.GetFileNameWithoutExtension (Destination.MainModule.FileName))}-new{Path.GetExtension (Destination.MainModule.FileName)}"; - Destination.Write (newName, new WriterParameters () { WriteSymbols = true }); + Destination.Write (new WriterParameters () { WriteSymbols = true }); if (App.Verbose) - App.ColorWriteLine ($"Wrote {newName} assembly", ConsoleColor.Cyan); + App.ColorWriteLine ($"Wrote updated {Destination.MainModule.FileName} assembly", ConsoleColor.Cyan); } static readonly string nestedName = "__<$>_jni_marshal_methods";