Skip to content

Commit 8ed9677

Browse files
authored
[jnimarshalmethod-gen] When using -o DIR, put temp assembly in DIR (#483)
Instead of trying to create it in the location of the original assembly as that might not be writable. Added test for -o, --keeptemp and -f parameters to test whether the new and temporary assemblies were created in the output directory
1 parent d39699f commit 8ed9677

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,16 @@ JRE_DLL_CONFIG=bin/$(CONFIGURATION)/Java.Runtime.Environment.dll.config
172172
$(JRE_DLL_CONFIG): src/Java.Runtime.Environment/Java.Runtime.Environment.csproj
173173
$(MSBUILD) $(MSBUILD_FLAGS) $<
174174

175-
run-test-jnimarshal: bin/Test$(CONFIGURATION)/Java.Interop.Export-Tests.dll bin/Test$(CONFIGURATION)/$(JAVA_INTEROP_LIB) $(JRE_DLL_CONFIG)
175+
define run-jnimarshalmethod-gen
176176
MONO_TRACE_LISTENER=Console.Out \
177-
$(RUNTIME) bin/$(CONFIGURATION)/jnimarshalmethod-gen.exe -v --jvm "$(JI_JVM_PATH)" -L "$(JI_MONO_LIB_PATH)mono/4.5" -L "$(JI_MONO_LIB_PATH)mono/4.5/Facades" "$<"
177+
$(RUNTIME) bin/$(CONFIGURATION)/jnimarshalmethod-gen.exe -v --jvm "$(JI_JVM_PATH)" -L "$(JI_MONO_LIB_PATH)mono/4.5" -L "$(JI_MONO_LIB_PATH)mono/4.5/Facades" $(2) $(1)
178+
endef
179+
180+
run-test-jnimarshal: bin/Test$(CONFIGURATION)/Java.Interop.Export-Tests.dll bin/Test$(CONFIGURATION)/$(JAVA_INTEROP_LIB) $(JRE_DLL_CONFIG)
181+
mkdir -p test-jni-output
182+
$(call run-jnimarshalmethod-gen,"$<",-f -o test-jni-output --keeptemp)
183+
(test -f test-jni-output/$(notdir $<) && test -f test-jni-output/Java.Interop.Export-Tests-JniMarshalMethods.dll) || { echo "jnimarshalmethod-gen did not create the expected assemblies in the test-jni-output directory"; exit 1; }
184+
$(call run-jnimarshalmethod-gen,"$<")
178185
$(call RUN_TEST,$<)
179186

180187
# $(call GEN_CORE_OUTPUT, outdir, suffix, extra)

tools/jnimarshalmethod-gen/App.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ void CreateMarshalMethodAssembly (string path)
287287

288288
var baseName = Path.GetFileNameWithoutExtension (path);
289289
var assemblyName = new AssemblyName (baseName + "-JniMarshalMethods");
290-
var destPath = assemblyName.Name + ".dll";
290+
var fileName = assemblyName.Name + ".dll";
291+
var destDir = string.IsNullOrEmpty (outDirectory) ? Path.GetDirectoryName (path) : outDirectory;
291292
var builder = CreateExportedMemberBuilder ();
292293
var matchType = typeNameRegexes.Count > 0;
293294

@@ -297,9 +298,9 @@ void CreateMarshalMethodAssembly (string path)
297298
var da = AppDomain.CurrentDomain.DefineDynamicAssembly (
298299
assemblyName,
299300
AssemblyBuilderAccess.Save,
300-
Path.GetDirectoryName (path));
301+
destDir);
301302

302-
var dm = da.DefineDynamicModule ("<default>", destPath);
303+
var dm = da.DefineDynamicModule ("<default>", fileName);
303304

304305
var ad = resolver.GetAssembly (path);
305306

@@ -428,12 +429,13 @@ void CreateMarshalMethodAssembly (string path)
428429
foreach (var tb in definedTypes)
429430
tb.Value.CreateType ();
430431

431-
da.Save (destPath);
432+
da.Save (fileName);
432433

433434
if (Verbose)
434435
ColorWriteLine ($"Marshal method assembly '{assemblyName}' created", ConsoleColor.Cyan);
435436

436-
var dstAssembly = resolver.GetAssembly (destPath);
437+
resolver.SearchDirectories.Add (destDir);
438+
var dstAssembly = resolver.GetAssembly (fileName);
437439

438440
if (!string.IsNullOrEmpty (outDirectory))
439441
path = Path.Combine (outDirectory, Path.GetFileName (path));

0 commit comments

Comments
 (0)