Ejemplo n.º 1
0
        static LinkContext CreateLinkContext(LinkerOptions options, Pipeline pipeline)
        {
            var context = new MonoMacLinkContext(pipeline, options.Resolver);

            context.CoreAction  = AssemblyAction.Link;
            context.LinkSymbols = options.LinkSymbols;
            if (options.LinkSymbols)
            {
                context.SymbolReaderProvider = new MdbReaderProvider();
                context.SymbolWriterProvider = new MdbWriterProvider();
            }
            context.OutputDirectory = options.OutputDirectory;
            return(context);
        }
Ejemplo n.º 2
0
        public static void Process(LinkerOptions options, out MonoMacLinkContext context, out List <string> assemblies)
        {
            var pipeline = CreatePipeline(options);

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

            context = CreateLinkContext(options, pipeline);
            context.Resolver.AddSearchDirectory(options.OutputDirectory);
            context.KeepTypeForwarderOnlyAssemblies = (Profile.Current is XamarinMacProfile);
            options.Target.LinkContext = (context as MonoMacLinkContext);

            Process(pipeline, context);

            assemblies = ListAssemblies(context);
        }
Ejemplo n.º 3
0
        static MonoMacLinkContext CreateLinkContext(LinkerOptions options, Pipeline pipeline)
        {
            var context = new MonoMacLinkContext(pipeline, options.Resolver);

            context.CoreAction  = AssemblyAction.Link;
            context.LinkSymbols = options.LinkSymbols;
            if (options.LinkSymbols)
            {
                context.SymbolReaderProvider = new DefaultSymbolReaderProvider();
                context.SymbolWriterProvider = new DefaultSymbolWriterProvider();
            }
            context.OutputDirectory = options.OutputDirectory;
            context.StaticRegistrar = options.Target.StaticRegistrar;
            context.Target          = options.Target;
            options.LinkContext     = context;
            return(context);
        }
Ejemplo n.º 4
0
        public static void Process(LinkerOptions options, out LinkContext context, out List <string> assemblies)
        {
            switch (options.TargetFramework.Identifier)
            {
            case "Xamarin.Mac":
                Profile.Current = new MacMobileProfile(options.Architecture == "x86_64" ? 64 : 32);
                break;

            default:
                Profile.Current = new MonoMacProfile();
                break;
            }
            Namespaces.Initialize();

            var pipeline = CreatePipeline(options);

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

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

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

            assemblies = ListAssemblies(context);
        }
Ejemplo n.º 5
0
        static Pipeline CreatePipeline(LinkerOptions options)
        {
            var pipeline = new Pipeline();

            pipeline.Append(options.LinkMode == LinkMode.None ? new LoadOptionalReferencesStep() : new LoadReferencesStep());

            if (options.I18nAssemblies != I18nAssemblies.None)
            {
                pipeline.Append(new LoadI18nAssemblies(options.I18nAssemblies));
            }

            // that must be done early since the XML files can "add" new assemblies [#15878]
            // and some of the assemblies might be (directly or referenced) SDK assemblies
            foreach (string definition in options.ExtraDefinitions)
            {
                pipeline.Append(GetResolveStep(definition));
            }

            if (options.LinkMode != LinkMode.None)
            {
                pipeline.Append(new BlacklistStep());
            }

            if (options.WarnOnTypeRef.Count > 0)
            {
                pipeline.Append(new PreLinkScanTypeReferenceStep(options.WarnOnTypeRef));
            }

            pipeline.Append(new CustomizeMacActions(options.LinkMode, options.SkippedAssemblies));

            // We need to store the Field attribute in annotations, since it may end up removed.
            pipeline.Append(new ProcessExportedFields());

            if (options.LinkMode != LinkMode.None)
            {
                pipeline.Append(new CoreTypeMapStep());

                pipeline.Append(GetSubSteps());

                pipeline.Append(new CorePreserveCode(options.I18nAssemblies));
                pipeline.Append(new PreserveCrypto());

                pipeline.Append(new MonoMacMarkStep());
                pipeline.Append(new MacRemoveResources(options));
                pipeline.Append(new CoreSweepStep(options.LinkSymbols));
                pipeline.Append(new CleanStep());

                pipeline.Append(new MonoMacNamespaces());
                pipeline.Append(new RemoveSelectors());

                pipeline.Append(new RegenerateGuidStep());
            }
            else
            {
                SubStepDispatcher sub = new SubStepDispatcher()
                {
                    new RemoveUserResourcesSubStep()
                };
                pipeline.Append(sub);
            }

            pipeline.Append(new ListExportedSymbols(options.MarshalNativeExceptionsState, options.SkipExportedSymbolsInSdkAssemblies));

            pipeline.Append(new OutputStep());

            // expect that changes can occur until it's all saved back to disk
            if (options.WarnOnTypeRef.Count > 0)
            {
                pipeline.Append(new PostLinkScanTypeReferenceStep(options.WarnOnTypeRef));
            }

            return(pipeline);
        }
Ejemplo n.º 6
0
 public MacRemoveResources(LinkerOptions options) :
     base(options.I18nAssemblies)
 {
 }
Ejemplo n.º 7
0
        static Pipeline CreatePipeline(LinkerOptions options)
        {
            var pipeline = new Pipeline();

            pipeline.AppendStep(options.LinkMode == LinkMode.None ? new LoadOptionalReferencesStep() : new LoadReferencesStep());

            if (options.I18nAssemblies != I18nAssemblies.None)
            {
                pipeline.AppendStep(new LoadI18nAssemblies(options.I18nAssemblies));
            }

            // that must be done early since the XML files can "add" new assemblies [#15878]
            // and some of the assemblies might be (directly or referenced) SDK assemblies
            foreach (string definition in options.ExtraDefinitions)
            {
                pipeline.AppendStep(GetResolveStep(definition));
            }

            if (options.LinkMode != LinkMode.None)
            {
                pipeline.AppendStep(new BlacklistStep());
            }

            pipeline.AppendStep(new CustomizeMacActions(options.LinkMode, options.SkippedAssemblies));

            // We need to store the Field attribute in annotations, since it may end up removed.
            pipeline.AppendStep(new ProcessExportedFields());

            if (options.LinkMode != LinkMode.None)
            {
                pipeline.AppendStep(new TypeMapStep());

                pipeline.AppendStep(new SubStepDispatcher {
                    new ApplyPreserveAttribute(),
                    new CoreRemoveSecurity(),
                    new OptimizeGeneratedCodeSubStep(options.EnsureUIThread),
                    new RemoveUserResourcesSubStep(),
                    new CoreRemoveAttributes(),
                    new CoreHttpMessageHandler(options),
                    new MarkNSObjects(),
                });

                pipeline.AppendStep(new MonoMacPreserveCode(options));
                pipeline.AppendStep(new PreserveCrypto());

                pipeline.AppendStep(new MonoMacMarkStep());
                pipeline.AppendStep(new MacRemoveResources(options));
                pipeline.AppendStep(new MobileSweepStep(options.LinkSymbols));
                pipeline.AppendStep(new CleanStep());

                pipeline.AppendStep(new MonoMacNamespaces());
                pipeline.AppendStep(new RemoveSelectors());

                pipeline.AppendStep(new RegenerateGuidStep());
            }
            else
            {
                SubStepDispatcher sub = new SubStepDispatcher()
                {
                    new RemoveUserResourcesSubStep()
                };
                pipeline.AppendStep(sub);
            }

            pipeline.AppendStep(new ListExportedSymbols(options.MarshalNativeExceptionsState, options.SkipExportedSymbolsInSdkAssemblies));

            pipeline.AppendStep(new OutputStep());

            return(pipeline);
        }
 public OptimizeGeneratedCodeSubStep(LinkerOptions options)
     : base(options)
 {
 }
Ejemplo n.º 9
0
        static IDictionary<string, List<MethodDefinition>> Link()
        {
            var cache = BuildTarget.Resolver.ToResolverCache ();
            var resolver = cache != null
                ? new Mono.Linker.AssemblyResolver (cache)
                : new Mono.Linker.AssemblyResolver ();

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

            var options = new LinkerOptions {
                MainAssembly = BuildTarget.Resolver.GetAssembly (references [references.Count - 1]),
                OutputDirectory = mmp_dir,
                LinkSymbols = App.EnableDebug,
                LinkMode = App.LinkMode,
                Resolver = resolver,
                SkippedAssemblies = App.LinkSkipped,
                I18nAssemblies = App.I18n,
                ExtraDefinitions = App.Definitions,
                TargetFramework = TargetFramework,
                Architecture = arch,
                RuntimeOptions = App.RuntimeOptions,
                // 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 = thread_check.HasValue ? thread_check.Value : App.EnableDebug,
            };

            Mono.Linker.LinkContext context;
            MonoMac.Tuner.Linker.Process (options, out context, out resolved_assemblies);
            BuildTarget.LinkContext = (context as MonoMacLinkContext);
            return BuildTarget.LinkContext.PInvokeModules;
        }
Ejemplo n.º 10
0
 public MonoMacPreserveCode(LinkerOptions options) :
     base(options.I18nAssemblies)
 {
 }
Ejemplo n.º 11
0
 public MonoMacPreserveCode(LinkerOptions options)
     : base(options.I18nAssemblies)
 {
 }
Ejemplo n.º 12
0
 public MacRemoveResources(LinkerOptions options)
     : base(options.I18nAssemblies)
 {
 }