コード例 #1
0
        public static void Create(List<BuildTask> tasks, Target target, Abi abi, IEnumerable<Assembly> assemblies, string assemblyName, IList<string> registration_methods)
        {
            var arch = abi.AsArchString ();
            var ofile = Path.Combine (Cache.Location, "main." + arch + ".o");
            var ifile = Path.Combine (Cache.Location, "main." + arch + ".m");

            var files = assemblies.Select (v => v.FullPath);

            if (!Application.IsUptodate (files, new string [] { ifile })) {
                Driver.GenerateMain (assemblies, assemblyName, abi, ifile, registration_methods);
            } else {
                Driver.Log (3, "Target '{0}' is up-to-date.", ifile);
            }

            if (!Application.IsUptodate (ifile, ofile)) {
                var main = new MainTask ()
                {
                    Target = target,
                    Abi = abi,
                    AssemblyName = assemblyName,
                    InputFile = ifile,
                    OutputFile = ofile,
                    SharedLibrary = false,
                    Language = "objective-c++",
                };
                main.CompilerFlags.AddDefine ("MONOTOUCH");
                tasks.Add (main);
            } else {
                Driver.Log (3, "Target '{0}' is up-to-date.", ofile);
            }

            target.LinkWith (ofile);
        }
コード例 #2
0
        public void Compile()
        {
            var tasks = new List <BuildTask> ();

            // Compile the managed assemblies into object files or shared libraries
            if (App.IsDeviceBuild)
            {
                foreach (var a in Assemblies)
                {
                    a.CreateCompilationTasks(tasks, BuildDirectory, Abis);
                }
            }

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

            if (App.Registrar == RegistrarMode.Static || App.Registrar == RegistrarMode.LegacyStatic)
            {
                var registrar_m = Path.Combine(ArchDirectory, "registrar.m");
                if (!Application.IsUptodate(Assemblies.Select(v => v.FullPath), new string[] { registrar_m }))
                {
                    registrar_m          = Driver.RunRegistrar(this, Assemblies, BuildDirectory, BuildDirectory, App.Registrar == RegistrarMode.LegacyStatic, Is64Build, 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);
                }

                foreach (var abi in Abis)
                {
                    RegistrarTask.Create(tasks, abi, this, registrar_m);
                }
            }

            if (App.Registrar == RegistrarMode.Dynamic && App.IsSimulatorBuild && App.LinkMode == LinkMode.None && App.IsUnified)
            {
                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.ProductSdkDirectory, "usr", "lib", library));

                if (App.Platform == ApplePlatform.iOS)
                {
                    foreach (var assembly in Assemblies)
                    {
                        if (!assembly.IsFrameworkAssembly)
                        {
                            continue;
                        }

                        switch (Path.GetFileNameWithoutExtension(assembly.FileName))
                        {
                        case "MonoTouch.Dialog-1":
                            registration_methods.Add("xamarin_create_classes_MonoTouch_Dialog_1");
                            link_with.Add(Path.Combine(Driver.ProductSdkDirectory, "usr", "lib", "MonoTouch.Dialog-1.registrar.a"));
                            break;
                            // MonoTouch.NUnitLite doesn't quite work yet, because its generated registrar code uses types
                            // from the generated registrar code for MonoTouch.Dialog-1 (and there is no header file (yet)
                            // for those types).
                            //					case "MonoTouch.NUnitLite":
                            //						registration_methods.Add ("xamarin_create_classes_MonoTouch_NUnitLite");
                            //						link_with.Add (Path.Combine (MTouch.MonoTouchIPhoneSimulatorDirectory, "usr", "lib", "MonoTouch.NUnitLite.registrar.a"));
                            //						break;
                        }
                    }
                }
            }

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

            // Start compiling.
            if (tasks.Count > 0)
            {
                Action <BuildTask> action = null;
                action = (v) => {
                    var next = v.Execute();
                    if (next != null)
                    {
                        Parallel.ForEach(next, new ParallelOptions()
                        {
                            MaxDegreeOfParallelism = Environment.ProcessorCount
                        }, action);
                    }
                };

                Parallel.ForEach(tasks, new ParallelOptions()
                {
                    MaxDegreeOfParallelism = Environment.ProcessorCount
                }, action);
            }

            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);
        }