public static void Process(LinkerOptions options, out MonoTouchLinkContext context, out List <AssemblyDefinition> assemblies)
        {
            var pipeline = CreatePipeline(options);

            foreach (var ad in options.MainAssemblies)
            {
                pipeline.PrependStep(new MobileResolveMainAssemblyStep(ad, options.Application.Embeddinator));
            }

            context = CreateLinkContext(options, pipeline);
            context.Resolver.AddSearchDirectory(options.OutputDirectory);

            if (options.DumpDependencies)
            {
                var prepareDependenciesDump = context.Annotations.GetType().GetMethod("PrepareDependenciesDump", new Type[1] {
                    typeof(string)
                });
                if (prepareDependenciesDump != null)
                {
                    prepareDependenciesDump.Invoke(context.Annotations, new object[1] {
                        string.Format("{0}{1}linker-dependencies.xml.gz", options.OutputDirectory, Path.DirectorySeparatorChar)
                    });
                }
            }

            Process(pipeline, context);

            assemblies = ListAssemblies(context);
        }
Пример #2
0
        static MonoTouchLinkContext CreateLinkContext(LinkerOptions options, Pipeline pipeline)
        {
            var context = new MonoTouchLinkContext(pipeline, options.Resolver);

            context.CoreAction      = options.LinkMode == LinkMode.None ? AssemblyAction.Copy : AssemblyAction.Link;
            context.LinkSymbols     = options.LinkSymbols;
            context.OutputDirectory = options.OutputDirectory;
            context.SetParameter("debug-build", options.DebugBuild.ToString());

            options.LinkContext = context;

            return(context);
        }
Пример #3
0
        static MonoTouchLinkContext CreateLinkContext(LinkerOptions options, Pipeline pipeline)
        {
            var context = new MonoTouchLinkContext(pipeline, options.Resolver);

            context.CoreAction      = options.LinkMode == LinkMode.None ? AssemblyAction.Copy : AssemblyAction.Link;
            context.LinkSymbols     = options.LinkSymbols;
            context.OutputDirectory = options.OutputDirectory;
            context.SetParameter("debug-build", options.DebugBuild.ToString());
            context.StaticRegistrar  = options.Target.StaticRegistrar;
            context.Target           = options.Target;
            context.ExcludedFeatures = new [] { "remoting", "com", "sre" };
            options.LinkContext      = context;

            return(context);
        }
        static List <AssemblyDefinition> ListAssemblies(MonoTouchLinkContext context)
        {
            var list = new List <AssemblyDefinition> ();

            foreach (var assembly in context.GetAssemblies())
            {
                if (context.Annotations.GetAction(assembly) == AssemblyAction.Delete)
                {
                    continue;
                }

                list.Add(assembly);
            }

            return(list);
        }
Пример #5
0
        static List <string> ListAssemblies(MonoTouchLinkContext context)
        {
            var list = new List <string> ();

            foreach (var assembly in context.GetAssemblies())
            {
                if (context.Annotations.GetAction(assembly) == AssemblyAction.Delete)
                {
                    continue;
                }

                list.Add(GetFullyQualifiedName(assembly));
            }

            return(list);
        }
Пример #6
0
        public static void Process(LinkerOptions options, out MonoTouchLinkContext context, out List <AssemblyDefinition> assemblies)
        {
            var pipeline = CreatePipeline(options);

            foreach (var ad in options.MainAssemblies)
            {
                pipeline.PrependStep(new MobileResolveMainAssemblyStep(ad));
            }

            context = CreateLinkContext(options, pipeline);
            context.Resolver.AddSearchDirectory(options.OutputDirectory);

            if (options.DumpDependencies)
            {
                var prepareDependenciesDump = context.Annotations.GetType().GetMethod("PrepareDependenciesDump", new Type[1] {
                    typeof(string)
                });
                if (prepareDependenciesDump != null)
                {
                    prepareDependenciesDump.Invoke(context.Annotations, new object[1] {
                        string.Format("{0}{1}linker-dependencies.xml.gz", options.OutputDirectory, Path.DirectorySeparatorChar)
                    });
                }
            }

            try {
                pipeline.Process(context);
            } catch (FileNotFoundException fnfe) {
                // Cecil throw this if the assembly is not found
                throw new MonoTouchException(2002, true, fnfe, fnfe.Message);
            } catch (AggregateException) {
                throw;
            } catch (MonoTouchException) {
                throw;
            } catch (ResolutionException re) {
                TypeReference  tr    = (re.Member as TypeReference);
                IMetadataScope scope = tr == null ? re.Member.DeclaringType.Scope : tr.Scope;
                throw new MonoTouchException(2002, true, re, "Failed to resolve \"{0}\" reference from \"{1}\"", re.Member, scope);
            } catch (XmlResolutionException ex) {
                throw new MonoTouchException(2017, true, ex, "Could not process XML description: {0}", ex?.InnerException?.Message ?? ex.Message);
            } catch (Exception e) {
                throw new MonoTouchException(2001, true, e, "Could not link assemblies. Reason: {0}", e.Message);
            }

            assemblies = ListAssemblies(context);
        }
Пример #7
0
        static MonoTouchLinkContext CreateLinkContext(LinkerOptions options, Pipeline pipeline)
        {
            var context = new MonoTouchLinkContext(pipeline, options.Resolver);

            context.CoreAction      = options.LinkMode == LinkMode.None ? AssemblyAction.Copy : AssemblyAction.Link;
            context.LinkSymbols     = options.LinkSymbols;
            context.OutputDirectory = options.OutputDirectory;
            context.SetParameter("debug-build", options.DebugBuild.ToString());
            context.Target               = options.Target;
            context.ExcludedFeatures     = new [] { "remoting", "com", "sre" };
            context.SymbolWriterProvider = new CustomSymbolWriterProvider();
            if (options.Application.Optimizations.StaticConstructorBeforeFieldInit == false)
            {
                context.DisabledOptimizations |= CodeOptimizations.BeforeFieldInit;
            }
            options.LinkContext = context;

            return(context);
        }
Пример #8
0
        public static void Process(LinkerOptions options, out MonoTouchLinkContext context, out List <AssemblyDefinition> assemblies)
        {
            var pipeline = CreatePipeline(options);

            foreach (var ad in options.MainAssemblies)
            {
                pipeline.PrependStep(new MobileResolveMainAssemblyStep(ad, options.Application.Embeddinator));
            }

            context = CreateLinkContext(options, pipeline);
            context.Resolver.AddSearchDirectory(options.OutputDirectory);

            if (options.DumpDependencies)
            {
                var prepareDependenciesDump = context.Annotations.GetType().GetMethod("PrepareDependenciesDump", new Type[1] {
                    typeof(string)
                });
                if (prepareDependenciesDump != null)
                {
                    prepareDependenciesDump.Invoke(context.Annotations, new object[1] {
                        string.Format("{0}{1}linker-dependencies.xml.gz", options.OutputDirectory, Path.DirectorySeparatorChar)
                    });
                }
            }

            try {
                pipeline.Process(context);
            } catch (FileNotFoundException fnfe) {
                // Cecil throw this if the assembly is not found
                throw new MonoTouchException(2002, true, fnfe, fnfe.Message);
            } catch (AggregateException) {
                throw;
            } catch (MonoTouchException) {
                throw;
            } catch (MarkException me) {
                var re = me.InnerException as ResolutionException;
                if (re == null)
                {
                    if (me.InnerException != null)
                    {
                        throw ErrorHelper.CreateError(2102, me, "Error processing the method '{0}' in the assembly '{1}': {2}", me.Method.FullName, me.Method.Module, me.InnerException.Message);
                    }
                    else
                    {
                        throw ErrorHelper.CreateError(2102, me, "Error processing the method '{0}' in the assembly '{1}'", me.Method.FullName, me.Method.Module);
                    }
                }
                else
                {
                    TypeReference  tr    = (re.Member as TypeReference);
                    IMetadataScope scope = tr == null ? re.Member.DeclaringType.Scope : tr.Scope;
                    throw ErrorHelper.CreateError(2101, me, "Can't resolve the reference '{0}', referenced from the method '{1}' in '{2}'.", re.Member, me.Method.FullName, scope);
                }
            } catch (ResolutionException re) {
                TypeReference  tr    = (re.Member as TypeReference);
                IMetadataScope scope = tr == null ? re.Member.DeclaringType.Scope : tr.Scope;
                throw new MonoTouchException(2002, true, re, "Failed to resolve \"{0}\" reference from \"{1}\"", re.Member, scope);
            } catch (XmlResolutionException ex) {
                throw new MonoTouchException(2017, true, ex, "Could not process XML description: {0}", ex?.InnerException?.Message ?? ex.Message);
            } catch (Exception e) {
                var message = new StringBuilder();
                if (e.Data.Count > 0)
                {
                    message.AppendLine();
                    var m = e.Data ["MethodDefinition"] as string;
                    if (m != null)
                    {
                        message.AppendLine($"\tMethod: `{m}`");
                    }
                    var t = e.Data ["TypeReference"] as string;
                    if (t != null)
                    {
                        message.AppendLine($"\tType: `{t}`");
                    }
                    var a = e.Data ["AssemblyDefinition"] as string;
                    if (a != null)
                    {
                        message.AppendLine($"\tAssembly: `{a}`");
                    }
                }
                message.Append($"Reason: {e.Message}");
                throw new MonoTouchException(2001, true, e, "Could not link assemblies. {0}", message);
            }

            assemblies = ListAssemblies(context);
        }
Пример #9
0
        static List<string> ListAssemblies(MonoTouchLinkContext context)
        {
            var list = new List<string> ();
            foreach (var assembly in context.GetAssemblies ()) {
                if (context.Annotations.GetAction (assembly) == AssemblyAction.Delete)
                    continue;

                list.Add (GetFullyQualifiedName (assembly));
            }

            return list;
        }
Пример #10
0
        static MonoTouchLinkContext CreateLinkContext(LinkerOptions options, Pipeline pipeline)
        {
            var context = new MonoTouchLinkContext (pipeline, options.Resolver);
            context.CoreAction = options.LinkMode == LinkMode.None ? AssemblyAction.Copy : AssemblyAction.Link;
            context.LinkSymbols = options.LinkSymbols;
            context.OutputDirectory = options.OutputDirectory;
            context.SetParameter ("debug-build", options.DebugBuild.ToString ());

            options.LinkContext = context;

            return context;
        }
Пример #11
0
        public static void Process(LinkerOptions options, out MonoTouchLinkContext context, out List<string> assemblies)
        {
            var pipeline = CreatePipeline (options);

            pipeline.PrependStep (new MobileResolveMainAssemblyStep (options.MainAssembly));

            context = CreateLinkContext (options, pipeline);
            context.Resolver.AddSearchDirectory (options.OutputDirectory);

            if (options.DumpDependencies) {
                var prepareDependenciesDump = context.Annotations.GetType ().GetMethod ("PrepareDependenciesDump", new Type[1] { typeof (string) });
                if (prepareDependenciesDump != null)
                    prepareDependenciesDump.Invoke (context.Annotations, new object[1] { string.Format ("{0}{1}linker-dependencies.xml.gz", options.OutputDirectory, Path.DirectorySeparatorChar) });
            }

            try {
                pipeline.Process (context);
            } catch (FileNotFoundException fnfe) {
                // Cecil throw this if the assembly is not found
                throw new MonoTouchException (2002, true, fnfe, fnfe.Message);
            } catch (AggregateException) {
                throw;
            } catch (MonoTouchException) {
                throw;
            } catch (ResolutionException re) {
                TypeReference tr = (re.Member as TypeReference);
                IMetadataScope scope = tr == null ? re.Member.DeclaringType.Scope : tr.Scope;
                throw new MonoTouchException (2002, true, re, "Failed to resolve \"{0}\" reference from \"{1}\"", re.Member, scope);
            } catch (Exception e) {
                throw new MonoTouchException (2001, true, e, "Could not link assemblies. Reason: {0}", e.Message);
            }

            assemblies = ListAssemblies (context);
        }
Пример #12
0
        public void LinkAssemblies(string main, ref List<string> assemblies, string output_dir, out MonoTouchLinkContext link_context)
        {
            if (Driver.Verbosity > 0)
                Console.WriteLine ("Linking {0} into {1} using mode '{2}'", main, output_dir, App.LinkMode);

            var cache = Resolver.ToResolverCache ();
            var resolver = cache != null
                ? new AssemblyResolver (cache)
                : new AssemblyResolver ();

            resolver.AddSearchDirectory (Resolver.RootDirectory);
            resolver.AddSearchDirectory (Resolver.FrameworkDirectory);

            var options = new LinkerOptions {
                MainAssembly = Resolver.Load (main),
                OutputDirectory = output_dir,
                LinkMode = App.LinkMode,
                Resolver = resolver,
                SkippedAssemblies = App.LinkSkipped,
                I18nAssemblies = App.I18n,
                LinkSymbols = true,
                LinkAway = App.LinkAway,
                ExtraDefinitions = App.Definitions,
                Device = App.IsDeviceBuild,
                // by default we keep the code to ensure we're executing on the UI thread (for UI code) for debug builds
                // but this can be overridden to either (a) remove it from debug builds or (b) keep it in release builds
                EnsureUIThread = App.ThreadCheck.HasValue ? App.ThreadCheck.Value : App.EnableDebug,
                OldRegistrar = (App.Registrar == RegistrarMode.LegacyDynamic || App.Registrar == RegistrarMode.LegacyStatic),
                DebugBuild = App.EnableDebug,
                Arch = Is64Build ? 8 : 4,
                IsDualBuild = App.IsDualBuild,
                Unified = App.IsUnified,
                DumpDependencies = App.LinkerDumpDependencies,
                RuntimeOptions = App.RuntimeOptions
            };

            MonoTouch.Tuner.Linker.Process (options, out link_context, out assemblies);

            // reset resolver
            foreach (var file in assemblies) {
                /*				var assembly = */Resolver.Load (file);
                // FIXME assembly.MainModule.AssemblyResolver = Resolver;
            }
            Driver.Watch ("Link Assemblies", 1);
        }