Пример #1
0
        /// <summary>
        ///   Creates the Info.plist file.
        /// </summary>
        /// <param name = 'monitor'>The progress monitor.</param>
        /// <param name = 'project'>The project.</param>
        /// <param name = 'configuration'>The configuration.</param>
        /// <param name = 'maker'>The bundle maker.</param>
        public static void CreateInfoPList(IProgressMonitor monitor, MonobjcProject project, ConfigurationSelector configuration, BundleMaker maker)
        {
            monitor.BeginTask (GettextCatalog.GetString ("Generating the Info.plist..."), 0);

            InfoPListGenerator pListGenerator = new InfoPListGenerator ();

            // If an Info.plist exists in the project then use it
            FilePath infoPListFile = project.BaseDirectory.Combine (Constants.INFO_PLIST);
            if (File.Exists (infoPListFile)) {
                pListGenerator.Content = File.ReadAllText (infoPListFile);
            }

            String mainAssembly = project.GetOutputFileName (configuration);
            Assembly assembly = Assembly.ReflectionOnlyLoadFrom (mainAssembly);
            AssemblyName assemblyName = assembly.GetName ();

            // TODO: Review to use new parameters
            pListGenerator.DevelopmentRegion = project.DevelopmentRegion;
            pListGenerator.ApplicationName = assemblyName.Name;
            pListGenerator.Identifier = project.BundleId;
            pListGenerator.Version = project.BundleVersion;
            pListGenerator.Icon = project.BundleIcon.IsNullOrEmpty ? null : project.BundleIcon.FileNameWithoutExtension;
            pListGenerator.MainNibFile = project.MainNibFile.IsNullOrEmpty ? null : project.MainNibFile.FileNameWithoutExtension;
            pListGenerator.TargetOSVersion = project.TargetOSVersion;
            pListGenerator.PrincipalClass = "NSApplication";
            pListGenerator.WriteTo (Path.Combine (maker.ContentsDirectory, Constants.INFO_PLIST));

            monitor.EndTask ();
        }
        private static void GenerateNative(IProgressMonitor monitor, BuildResult result, MonobjcProject project, ConfigurationSelector configuration, BundleMaker maker)
        {
            // Create a directory for generation
            String tempDir = Path.Combine(project.GetOutputFileName(configuration).ParentDirectory, ".native");
            Directory.CreateDirectory(tempDir);

            // Build a list of all folders to visit when collecting managed references
            String mainAssembly = project.GetOutputFileName(configuration);
            String configurationDir = Path.GetDirectoryName(mainAssembly);
            List<String> searchDirs = new List<String>();
            searchDirs.Add(configurationDir);

            // For each reference, add its base dir
            foreach (ProjectReference reference in project.References)
            {
                String[] files = reference.GetReferencedFileNames(configuration);
                foreach (string file in files)
                {
                    String dir = Path.GetDirectoryName(file);
                    searchDirs.Add(dir);
                }
            }

            // Remove redundant entries
            searchDirs = searchDirs.Distinct().ToList();

            // Collect all the assemblies
            monitor.BeginTask(GettextCatalog.GetString("Collecting assemblies..."), 0);
            ManagedReferenceCollector collector = new ManagedReferenceCollector();
            collector.Logger = new BuildLogger(monitor, result);
            collector.SearchDirectories = searchDirs;
            monitor.EndTask();

            // Collect the main assembly references
            List<String> assemblies = new List<String>();
            assemblies.AddRange(collector.Collect(mainAssembly));

            // Remove redundant entries
            assemblies = assemblies.Distinct().ToList();

            // Generate the embedded executable
            monitor.BeginTask(GettextCatalog.GetString("Generating native code..."), 0);
            NativeCodeGenerator codeGenerator = new NativeCodeGenerator();
            codeGenerator.Logger = new BuildLogger(monitor, result);
            codeGenerator.Assemblies = assemblies;
            codeGenerator.DeveloperToolsFolder = DeveloperToolsDesktopApplication.DeveloperToolsFolder;
            codeGenerator.TargetOSVersion = project.TargetOSVersion;
            codeGenerator.TargetArchitecture = project.TargetOSArch;

            // We embed the machine.config file; it depends on the target framework
            int version = (int) project.TargetFramework.ClrVersion;
            switch (version)
            {
                case 2: // ClrVersion.Net_2_0:
                    codeGenerator.MachineConfiguration = "/Library/Frameworks/Mono.framework/Home/etc/mono/2.0/machine.config";
                    break;
                case 4: // ClrVersion.Net_4_0:
                    codeGenerator.MachineConfiguration = "/Library/Frameworks/Mono.framework/Home/etc/mono/4.0/machine.config";
                    break;
                case 5: // ClrVersion.Net_4_5:
                    codeGenerator.MachineConfiguration = "/Library/Frameworks/Mono.framework/Home/etc/mono/4.5/machine.config";
                    break;
            }

            // Launch the generation
            String executableFile = codeGenerator.Generate(tempDir);
            String libraryFile = Path.Combine(tempDir, "libmonobjc.dylib");
            monitor.EndTask();

            // Copy the native parts into the bundle
            monitor.BeginTask(GettextCatalog.GetString("Copying native code..."), 0);
            maker.CopyTo(executableFile, maker.MacOSDirectory);
            maker.CopyTo(libraryFile, maker.MacOSDirectory);
            monitor.EndTask();

            // Change the paths
            executableFile = maker.Combine(maker.MacOSDirectory, executableFile);
            libraryFile = maker.Combine(maker.MacOSDirectory, libraryFile);

            // Relocate the libraries
            monitor.BeginTask(GettextCatalog.GetString("Relocating native code..."), 0);
            NativeCodeRelocator relocator = new NativeCodeRelocator();
            relocator.Logger = new BuildLogger(monitor, result);
            relocator.DependencyPattern = new List<string> {"Mono.framework"};
            relocator.Relocate(executableFile, maker.MacOSDirectory);
            relocator.Relocate(libraryFile, maker.MacOSDirectory);
            monitor.EndTask();
        }