about summary refs log tree commit diff
path: root/pkgs/games
diff options
context:
space:
mode:
authoraszlig <aszlig@nix.build>2018-07-17 08:14:25 +0200
committeraszlig <aszlig@nix.build>2018-07-19 06:35:20 +0200
commitcf243359e3b0a607a74cbc2cf7c7eb268a46b945 (patch)
treee15756dcde2ab21027de0b13fe1cc24e47953e63 /pkgs/games
parent6ed68d3e6d7bfd519293e772de794c3b3460773e (diff)
monogame-patcher: Fix assembly search directory
By default the assemblies are searched in the current working directory,
but when patching an assembly in some other directory than the current
the patcher will fail to resolve assemblies residing beneath the target
file.

So we just add the directory of the target file to the search path.

I also moved all of the assemblies in the test to be in a subdir so we
can verify that this indeed works and we won't regress in the future.

Signed-off-by: aszlig <aszlig@nix.build>
Diffstat (limited to 'pkgs/games')
-rw-r--r--pkgs/games/build-support/monogame-patcher/src/patcher.cs6
-rw-r--r--pkgs/games/build-support/monogame-patcher/src/test.sh21
2 files changed, 16 insertions, 11 deletions
diff --git a/pkgs/games/build-support/monogame-patcher/src/patcher.cs b/pkgs/games/build-support/monogame-patcher/src/patcher.cs
index b35e44d6..6aeaa324 100644
--- a/pkgs/games/build-support/monogame-patcher/src/patcher.cs
+++ b/pkgs/games/build-support/monogame-patcher/src/patcher.cs
@@ -21,8 +21,12 @@ class Command {
             this.outfile = options.outputFile;
         this.infile = options.inputFile;
 
+        var resolver = new DefaultAssemblyResolver();
+        resolver.AddSearchDirectory(Path.GetDirectoryName(this.infile));
+
         var rp = new ReaderParameters {
-            ReadWrite = this.infile == this.outfile
+            ReadWrite = this.infile == this.outfile,
+            AssemblyResolver = resolver
         };
         this.module = ModuleDefinition.ReadModule(this.infile, rp);
     }
diff --git a/pkgs/games/build-support/monogame-patcher/src/test.sh b/pkgs/games/build-support/monogame-patcher/src/test.sh
index 9c51cd7e..b19457d4 100644
--- a/pkgs/games/build-support/monogame-patcher/src/test.sh
+++ b/pkgs/games/build-support/monogame-patcher/src/test.sh
@@ -51,30 +51,31 @@ class test1 {
 }
 EOF
 
-mcs a.cs -target:library -out:a.dll
-mcs b.cs -target:library -out:b.dll
+mkdir subdir
+mcs a.cs -target:library -out:subdir/a.dll
+mcs b.cs -target:library -out:subdir/b.dll
 
-mcs test1.cs -r:a -r:b -out:test1.exe
-mcs test2.cs -r:a -r:b -out:test2.exe
+mcs test1.cs -r:subdir/a -r:subdir/b -out:subdir/test1.exe
+mcs test2.cs -r:subdir/a -r:subdir/b -out:subdir/test2.exe
 
-! "$out/bin/monogame-patcher" replace-call -i test1.exe \
+! "$out/bin/monogame-patcher" replace-call -i subdir/test1.exe \
     "System.String a::replaceMe(System.String)" \
     "System.String b::notfound(System.String)" \
     test1 2> /dev/null
 
-"$out/bin/monogame-patcher" replace-call -i test1.exe \
+"$out/bin/monogame-patcher" replace-call -i subdir/test1.exe \
     "System.String a::replaceMe(System.String)" \
     "System.String b::replacement(System.String)" \
     test1
 
-test "$(mono test1.exe)" = "bar called: xxx"
+test "$(mono subdir/test1.exe)" = "bar called: xxx"
 
 echo foo > write_test.txt
 
-test "$(mono test2.exe)" = "can write"
+test "$(mono subdir/test2.exe)" = "can write"
 
-"$out/bin/monogame-patcher" fix-filestreams -i b.dll b
+"$out/bin/monogame-patcher" fix-filestreams -i subdir/b.dll b
 
-test "$(mono test2.exe)" = "can not write"
+test "$(mono subdir/test2.exe)" = "can not write"
 
 "$out/bin/monogame-patcher" --help 2>&1 | grep -q fix-filestreams