Exemplo n.º 1
0
 public void SelectStaticRegistrar()
 {
     switch (App.Registrar)
     {
     case RegistrarMode.Static:
     case RegistrarMode.Dynamic:
     case RegistrarMode.Default:
         StaticRegistrar = new StaticRegistrar(this)
         {
             LinkContext = LinkContext,
         };
         break;
     }
 }
Exemplo n.º 2
0
        static void SetupInit(CoreApplication application, InitializationOptions options = null)
        {
            Context = application;

            if (!IsInitialized)
            {
                Internals.Log.Listeners.Add(new XamarinLogListener());
                if (System.Threading.SynchronizationContext.Current == null)
                {
                    TizenSynchronizationContext.Initialize();
                }

                Elementary.Initialize();
                Elementary.ThemeOverlay();
                Utility.AppendGlobalFontPath(@"/usr/share/fonts");
            }

            Device.PlatformServices = new TizenPlatformServices();
            if (Device.info != null)
            {
                ((TizenDeviceInfo)Device.info).Dispose();
                Device.info = null;
            }

            Device.Info = new Forms.TizenDeviceInfo();
            Device.SetFlags(s_flags);

            string profile = ((TizenDeviceInfo)Device.Info).Profile;

            if (profile == "mobile")
            {
                Device.SetIdiom(TargetIdiom.Phone);
            }
            else if (profile == "tv")
            {
                Device.SetIdiom(TargetIdiom.TV);
            }
            else if (profile == "desktop")
            {
                Device.SetIdiom(TargetIdiom.Desktop);
            }
            else if (profile == "wearable")
            {
                Device.SetIdiom(TargetIdiom.Watch);
            }
            else
            {
                Device.SetIdiom(TargetIdiom.Unsupported);
            }

            if (!Forms.IsInitialized)
            {
                if (options != null)
                {
                    s_platformType       = options.PlatformType;
                    s_useMessagingCenter = options.UseMessagingCenter;

                    if (options.Assemblies != null && options.Assemblies.Length > 0)
                    {
                        TizenPlatformServices.AppDomain.CurrentDomain.AddAssemblies(options.Assemblies);
                    }

                    // renderers
                    if (options.Handlers != null)
                    {
                        Registrar.RegisterRenderers(options.Handlers);
                    }
                    else
                    {
                        // Add Xamarin.Forms.Core assembly by default to apply the styles.
                        TizenPlatformServices.AppDomain.CurrentDomain.AddAssembly(Assembly.GetAssembly(typeof(Xamarin.Forms.View)));

                        // static registrar
                        if (options.StaticRegistarStrategy != StaticRegistrarStrategy.None)
                        {
                            s_staticRegistrarStrategy = options.StaticRegistarStrategy;
                            StaticRegistrar.RegisterHandlers(options.CustomHandlers);

                            if (options.StaticRegistarStrategy == StaticRegistrarStrategy.All)
                            {
                                Registrar.RegisterAll(new Type[]
                                {
                                    typeof(ExportRendererAttribute),
                                    typeof(ExportImageSourceHandlerAttribute),
                                    typeof(ExportCellAttribute),
                                    typeof(ExportHandlerAttribute),
                                    typeof(ExportFontAttribute)
                                });
                            }
                        }
                        else
                        {
                            Registrar.RegisterAll(new Type[]
                            {
                                typeof(ExportRendererAttribute),
                                typeof(ExportImageSourceHandlerAttribute),
                                typeof(ExportCellAttribute),
                                typeof(ExportHandlerAttribute),
                                typeof(ExportFontAttribute)
                            });
                        }
                    }

                    // effects
                    var effectScopes = options.EffectScopes;
                    if (effectScopes != null)
                    {
                        for (var i = 0; i < effectScopes.Length; i++)
                        {
                            var effectScope = effectScopes[0];
                            Registrar.RegisterEffects(effectScope.Name, effectScope.Effects);
                        }
                    }

                    // css
                    Registrar.RegisterStylesheets(options.Flags);
                }
                else
                {
                    // In .NETCore, AppDomain feature is not supported.
                    // The list of assemblies returned by AppDomain.GetAssemblies() method should be registered manually.
                    // The assembly of the executing application and referenced assemblies of it are added into the list here.
                    TizenPlatformServices.AppDomain.CurrentDomain.RegisterAssemblyRecursively(application.GetType().GetTypeInfo().Assembly);

                    Registrar.RegisterAll(new Type[]
                    {
                        typeof(ExportRendererAttribute),
                        typeof(ExportImageSourceHandlerAttribute),
                        typeof(ExportCellAttribute),
                        typeof(ExportHandlerAttribute),
                        typeof(ExportFontAttribute)
                    });
                }
            }

            Color.SetAccent(GetAccentColor(profile));
            ExpressionSearch.Default = new TizenExpressionSearch();

            if (application is WatchApplication)
            {
                s_platformType = PlatformType.Lightweight;
            }

            IsInitialized = true;
        }
Exemplo n.º 3
0
        public void Compile()
        {
            // Compile the managed assemblies into object files or shared libraries
            if (App.IsDeviceBuild)
            {
                foreach (var a in Assemblies)
                {
                    a.CreateCompilationTasks(compile_tasks, BuildDirectory, Abis);
                }
            }

            // The static registrar.
            List <string> registration_methods = null;

            if (App.Registrar == RegistrarMode.Static)
            {
                var registrar_m = Path.Combine(ArchDirectory, "registrar.m");
                var registrar_h = Path.Combine(ArchDirectory, "registrar.h");
                if (!Application.IsUptodate(Assemblies.Select(v => v.FullPath), new string[] { registrar_m, registrar_h }))
                {
                    StaticRegistrar.Generate(Assemblies.Select((a) => a.AssemblyDefinition), registrar_h, registrar_m);
                    registration_methods = new List <string> ();
                    registration_methods.Add("xamarin_create_classes");
                    Driver.Watch("Registrar", 1);
                }
                else
                {
                    Driver.Log(3, "Target '{0}' is up-to-date.", registrar_m);
                }

                RegistrarTask.Create(compile_tasks, Abis, this, registrar_m);
            }

            if (App.Registrar == RegistrarMode.Dynamic && App.IsSimulatorBuild && App.LinkMode == LinkMode.None)
            {
                if (registration_methods == null)
                {
                    registration_methods = new List <string> ();
                }

                string method;
                string library;
                switch (App.Platform)
                {
                case ApplePlatform.iOS:
                    method  = "xamarin_create_classes_Xamarin_iOS";
                    library = "Xamarin.iOS.registrar.a";
                    break;

                case ApplePlatform.WatchOS:
                    method  = "xamarin_create_classes_Xamarin_WatchOS";
                    library = "Xamarin.WatchOS.registrar.a";
                    break;

                case ApplePlatform.TVOS:
                    method  = "xamarin_create_classes_Xamarin_TVOS";
                    library = "Xamarin.TVOS.registrar.a";
                    break;

                default:
                    throw ErrorHelper.CreateError(71, "Unknown platform: {0}. This usually indicates a bug in Xamarin.iOS; please file a bug report at http://bugzilla.xamarin.com with a test case.", App.Platform);
                }

                registration_methods.Add(method);
                link_with.Add(Path.Combine(Driver.GetProductSdkDirectory(App), "usr", "lib", library));
            }

            // The main method.
            foreach (var abi in Abis)
            {
                MainTask.Create(compile_tasks, this, abi, Assemblies, App.AssemblyName, registration_methods);
            }

            // Start compiling.
            compile_tasks.ExecuteInParallel();

            if (App.FastDev)
            {
                foreach (var a in Assemblies)
                {
                    if (a.Dylibs == null)
                    {
                        continue;
                    }
                    foreach (var dylib in a.Dylibs)
                    {
                        LinkWith(dylib);
                    }
                }
            }

            Driver.Watch("Compile", 1);
        }
Exemplo n.º 4
0
        protected override MethodDefinition MarkMethod(MethodReference reference)
        {
            var method = base.MarkMethod(reference);

            if (method == null)
            {
                return(null);
            }

            var t = method.DeclaringType;

            // We have special processing that prevents protocol interfaces from being marked if they're
            // only used by being implemented by a class, but the linker will not mark interfaces if a method implemented by an interface
            // is marked: this means we need special processing to preserve a protocol interface whose methods have been implemented.
            if (RegisterProtocols && t.HasInterfaces && method.IsVirtual)
            {
                foreach (var r in t.Interfaces)
                {
                    var i = r.InterfaceType.Resolve();
                    if (i == null)
                    {
                        continue;
                    }
                    if (Annotations.IsMarked(i))
                    {
                        continue;
                    }
                    if (!LinkContext.StaticRegistrar.HasAttribute(i, Namespaces.Foundation, "ProtocolAttribute"))
                    {
                        continue;
                    }

                    var isProtocolImplementation = false;
                    // Are there any explicit overrides?
                    foreach (var @override in method.Overrides)
                    {
                        if (!i.Methods.Contains(@override.Resolve()))
                        {
                            continue;
                        }
                        isProtocolImplementation = true;
                        break;
                    }
                    if (!isProtocolImplementation)
                    {
                        // Are there any implicit overrides (identical name and signature)?
                        foreach (var imethod in i.Methods)
                        {
                            if (!StaticRegistrar.MethodMatch(imethod, method))
                            {
                                continue;
                            }
                            isProtocolImplementation = true;
                            break;
                        }
                    }
                    if (isProtocolImplementation)
                    {
                        MarkType(r.InterfaceType);
                        Bundler.Driver.Log(9, "Marking {0} because the method {1} implements one of its methods.", r.InterfaceType, method.FullName);
                    }
                }
            }

            // special processing to find [BlockProxy] attributes in _Extensions types
            // ref: https://bugzilla.xamarin.com/show_bug.cgi?id=23540
            if (LinkContext.Target.StaticRegistrar.MapProtocolMember(method, out var extensionMethod))
            {
                // one cannot simply mark the `ca.ConstructorArguments [0].Value` type,
                // e.g. Trampolines.NIDActionArity1V26
                // as the relation to *_Extensions will be reflected at runtime
                MarkMethod(extensionMethod);
            }

            return(method);
        }
Exemplo n.º 5
0
        protected override MethodDefinition MarkMethod(MethodReference reference)
        {
            var method = base.MarkMethod(reference);

            if (method == null)
            {
                return(null);
            }

            var t = method.DeclaringType;

            // We have special processing that prevents protocol interfaces from being marked if they're
            // only used by being implemented by a class, but the linker will not mark interfaces if a method implemented by an interface
            // is marked: this means we need special processing to preserve a protocol interface whose methods have been implemented.
            if (RegisterProtocols && t.HasInterfaces && method.IsVirtual)
            {
                foreach (var r in t.Interfaces)
                {
                    var i = r.InterfaceType.Resolve();
                    if (i == null)
                    {
                        continue;
                    }
                    if (Annotations.IsMarked(i))
                    {
                        continue;
                    }
                    if (!LinkContext.StaticRegistrar.HasAttribute(i, Namespaces.Foundation, "ProtocolAttribute"))
                    {
                        continue;
                    }

                    var isProtocolImplementation = false;
                    // Are there any explicit overrides?
                    foreach (var @override in method.Overrides)
                    {
                        if (!i.Methods.Contains(@override.Resolve()))
                        {
                            continue;
                        }
                        isProtocolImplementation = true;
                        break;
                    }
                    if (!isProtocolImplementation)
                    {
                        // Are there any implicit overrides (identical name and signature)?
                        foreach (var imethod in i.Methods)
                        {
                            if (!StaticRegistrar.MethodMatch(imethod, method))
                            {
                                continue;
                            }
                            isProtocolImplementation = true;
                            break;
                        }
                    }
                    if (isProtocolImplementation)
                    {
                        MarkType(r.InterfaceType);
                        Bundler.Driver.Log(9, "Marking {0} because the method {1} implements one of its methods.", r.InterfaceType, method.FullName);
                    }
                }
            }

            // special processing to find [BlockProxy] attributes in _Extensions types
            // ref: https://bugzilla.xamarin.com/show_bug.cgi?id=23540
            if (method.HasCustomAttributes && t.HasInterfaces)
            {
                string selector = null;
                foreach (var r in t.Interfaces)
                {
                    var i = r.InterfaceType.Resolve();
                    if (i == null || !i.HasCustomAttribute(Namespaces.Foundation, "ProtocolAttribute"))
                    {
                        continue;
                    }
                    if (selector == null)
                    {
                        // delay and don't compute each time
                        foreach (var ca in method.CustomAttributes)
                        {
                            if (!ca.Constructor.DeclaringType.Is(Namespaces.Foundation, "ExportAttribute"))
                            {
                                continue;
                            }
                            selector = ca.ConstructorArguments [0].Value as string;
                            break;
                        }
                    }
                    string name  = null;
                    bool   match = false;
                    foreach (var ca in i.CustomAttributes)
                    {
                        if (!ca.Constructor.DeclaringType.Is(Namespaces.Foundation, "ProtocolMemberAttribute"))
                        {
                            continue;
                        }
                        foreach (var p in ca.Properties)
                        {
                            switch (p.Name)
                            {
                            case "Selector":
                                match = (p.Argument.Value as string == selector);
                                break;

                            case "Name":
                                name = p.Argument.Value as string;
                                break;
                            }
                        }
                        if (match)
                        {
                            break;
                        }
                    }
                    if (!match || name == null)
                    {
                        continue;
                    }
                    // _Extensions time...
                    var td = i.Module.GetType(i.Namespace, i.Name.Substring(1) + "_Extensions");
                    if (td != null && td.HasMethods)
                    {
                        foreach (var m in td.Methods)
                        {
                            if (!m.HasParameters || (m.Name != name) || !m.IsOptimizableCode(LinkContext))
                            {
                                continue;
                            }
                            bool proxy = false;
                            match = method.Parameters.Count == m.Parameters.Count - 1;
                            if (match)
                            {
                                for (int n = 1; n < m.Parameters.Count; n++)
                                {
                                    var p  = m.Parameters [n];
                                    var pt = p.ParameterType;
                                    match &= method.Parameters [n - 1].ParameterType.Is(pt.Namespace, pt.Name);
                                    proxy |= p.HasCustomAttribute(Namespaces.ObjCRuntime, "BlockProxyAttribute");
                                }
                            }
                            if (match && proxy)
                            {
                                // one cannot simply mark the `ca.ConstructorArguments [0].Value` type,
                                // e.g. Trampolines.NIDActionArity1V26
                                // as the relation to *_Extensions will be reflected at runtime
                                MarkMethod(m);
                            }
                        }
                    }
                }
            }
            return(method);
        }