Skip to content

Instantly share code, notes, and snippets.

@chamons

chamons/foo.diff Secret

Created May 4, 2017 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chamons/579b408517a4546a5b2c98790ec2777f to your computer and use it in GitHub Desktop.
Save chamons/579b408517a4546a5b2c98790ec2777f to your computer and use it in GitHub Desktop.
diff --git a/tools/mmp/.gitignore b/tools/mmp/.gitignore
index d1a4664..7a86768 100644
--- a/tools/mmp/.gitignore
+++ b/tools/mmp/.gitignore
@@ -1,3 +1,4 @@
mmp
temp-dir-mmp
Xamarin.Mac.registrar.*
+monoExclusionList.txt
diff --git a/tools/mmp/Makefile b/tools/mmp/Makefile
index 9eb4821..0daa5cb 100644
--- a/tools/mmp/Makefile
+++ b/tools/mmp/Makefile
@@ -131,8 +131,8 @@ LOCAL_MMP = \
Mono.Cecil.dll \
Mono.Cecil.Mdb.dll \
-mmp.exe: Makefile $(MONO_CECIL_DLL) $(MONO_CECIL_MDB_DLL) $(mmp_sources) config config_mobile Info.plist.tmpl $(tuner_sources) $(linker_resources)
- $(Q_MCS) $(SYSTEM_MCS) -unsafe -out:mmp.exe $(DEFINES) -r:$(MONO_CECIL_DLL) -r:$(MONO_CECIL_MDB_DLL) -r:Mono.Security.dll -resource:config -resource:config_mobile -resource:machine.4_5.config -resource:Info.plist.tmpl $(linker_resources:%=-resource:%) $(tuner_sources) $(mmp_sources)
+mmp.exe: Makefile $(MONO_CECIL_DLL) $(MONO_CECIL_MDB_DLL) $(mmp_sources) config config_mobile Info.plist.tmpl $(tuner_sources) $(linker_resources) monoExclusionList.txt
+ $(Q_MCS) $(SYSTEM_MCS) -unsafe -out:mmp.exe $(DEFINES) -r:$(MONO_CECIL_DLL) -r:$(MONO_CECIL_MDB_DLL) -r:Mono.Security.dll -resource:monoExclusionList.txt -resource:config -resource:config_mobile -resource:machine.4_5.config -resource:Info.plist.tmpl $(linker_resources:%=-resource:%) $(tuner_sources) $(mmp_sources)
$(Q) cp $(MONO_CECIL_DLL) $(MONO_CECIL_MDB_DLL) .
Mono.Cecil.dll: $(MONO_CECIL_DLL)
@@ -205,6 +205,9 @@ install-local:: $(MMP_TARGETS)
all-local:: $(MMP_TARGETS)
endif
+monoExclusionList.txt: ./generateExclusionLish.sh
+ $(Q) ./generateExclusionLish.sh
+
clean-local::
rm -f mmp mmp.exe mmp.exe.mdb mmp-uninstalled
rm -f mmp.stub.c mmp.helper.o
diff --git a/tools/mmp/driver.cs b/tools/mmp/driver.cs
index be1a0c0..dd224dc 100644
--- a/tools/mmp/driver.cs
+++ b/tools/mmp/driver.cs
@@ -442,6 +442,31 @@ namespace Xamarin.Bundler {
}
+ if (IsUnified) {
+ List<ExclusionItem> exclusionItems = ReadExclusionList ();
+ List<string> referencesToFix = new List<string> ();
+
+ foreach (var asm in references) {
+ List<ExclusionItem> possibleMatches = exclusionItems.Where (x => x.Name == Path.GetFileName (asm)).ToList ();
+ if (possibleMatches.Count > 0) {
+ var module = ModuleDefinition.ReadModule (asm);
+ if (possibleMatches.Any (x => x.GUID == module.Mvid))
+ referencesToFix.Add (asm);
+ }
+ }
+ if (referencesToFix.Count > 0) {
+ string facadeRoot = string.Format ("/Library/Frameworks/Xamarin.Mac.framework/Versions/Current/lib/mono/{0}/Facades/", IsUnifiedMobile ? "Xamarin.Mac" : "4.5");
+
+ FixReferences (asm => referencesToFix.Contains (asm), asm => {
+ string replacement = Path.Combine (facadeRoot, Path.GetFileName (asm));
+ ErrorHelper.Warning (9999/*FIXME*/, string.Format ("{0} is a facade mono has declared problematic and refuses to load. Replacing reference with {1}.", asm, replacement));
+
+ Console.WriteLine ("{0} is a facade mono has declared problematic and refuses to load. Replacing reference with {1}.", asm, replacement);
+ return replacement;
+ });
+ }
+ }
+
if (IsUnifiedFullSystemFramework || IsClassic) {
// With newer Mono builds, the system assemblies passed to us by msbuild are
// no longer safe to copy into the bundle. They are stripped "fake" BCL
@@ -517,6 +542,30 @@ namespace Xamarin.Bundler {
Log ("bundling complete");
}
+ struct ExclusionItem
+ {
+ public string Name;
+ public Guid GUID;
+ }
+
+ static List<ExclusionItem> ReadExclusionList ()
+ {
+ List<ExclusionItem> exclusionList = new List<ExclusionItem> ();
+ using (var exclusionStream = typeof (Driver).Assembly.GetManifestResourceStream ("monoExclusionList.txt")) {
+ if (exclusionStream == null) {
+ ErrorHelper.Warning (9999/*FIXME*/, "Internal Warning \"Unable to load mono exclusion list.\" .Please file a bug report with a test case (http://bugzilla.xamarin.com).");
+ return exclusionList;
+ }
+ using (var sr = new StreamReader (exclusionStream)) {
+ while (!sr.EndOfStream) {
+ string [] lineParts = sr.ReadLine().Split (new char [] { ':' });
+ exclusionList.Add (new ExclusionItem () { Name = lineParts[0], GUID = new Guid (lineParts[1]) });
+ }
+ }
+ }
+ return exclusionList;
+ }
+
static void FixReferences (Func<string, bool> match, Func<string, string> fix)
{
var assembliesToFix = references.Where (x => match(x)).ToList ();
diff --git a/tools/mmp/generateExclusionLish.sh b/tools/mmp/generateExclusionLish.sh
new file mode 100755
index 0000000..d08b394
--- /dev/null
+++ b/tools/mmp/generateExclusionLish.sh
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+cat ../../external/mono/mono/metadata/image.c | grep IGNORED_ASSEMBLY |grep -v define | cut -d ',' -f 2,3 | sed -e 's/^[[:space:]]*//' | tr -d '"' > temp.txt
+
+rm monoExclusionList.txt
+cat temp.txt | while read line
+do
+ AssemblyName=`echo $line | cut -d ',' -f 1`
+ GUID=`echo $line | cut -d ',' -f 2 | tr -d '[:space:]'`
+ case $AssemblyName in
+ SYS_RT_INTEROP_RUNTIME_INFO)
+ echo System.Runtime.InteropServices.RuntimeInformation.dll:$GUID >> monoExclusionList.txt
+ ;;
+ SYS_GLOBALIZATION_EXT)
+ echo System.Globalization.Extensions.dll:$GUID >> monoExclusionList.txt
+ ;;
+ SYS_IO_COMPRESSION)
+ echo System.IO.Compression.dll:$GUID >> monoExclusionList.txt
+ ;;
+ SYS_NET_HTTP)
+ echo System.Net.Http.dll:$GUID >> monoExclusionList.txt
+ ;;
+ SYS_TEXT_ENC_CODEPAGES)
+ echo System.Text.Encoding.CodePages.dll:$GUID >> monoExclusionList.txt
+ ;;
+ SYS_REF_DISP_PROXY)
+ echo System.Reflection.DispatchProxy.dll:$GUID >> monoExclusionList.txt
+ ;;
+ SYS_VALUE_TUPLE)
+ echo System.ValueTuple.dll:$GUID >> monoExclusionList.txt
+ ;;
+ *)
+ echo "Unknown name: $AssemblyName"
+ exit 1
+ ;;
+ esac
+done
+
+rm temp.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment