protected override BuildResult Build(IProgressMonitor monitor, SolutionEntityItem item, ConfigurationSelector configuration)
        {
            var proj = item as MonoMacProject;

            if (proj == null || proj.CompileTarget != CompileTarget.Exe)
            {
                return(base.Build(monitor, item, configuration));
            }

            var conf   = (MonoMacProjectConfiguration)configuration.GetConfiguration(item);
            var resDir = conf.AppDirectory.Combine("Contents", "Resources");
            var appDir = conf.AppDirectory;

            //make sure the codebehind files are updated before building
            var res = MacBuildUtilities.UpdateCodeBehind(monitor, proj.CodeBehindGenerator, proj.Files);

            if (res.ErrorCount > 0)
            {
                return(res);
            }

            res = res.Append(base.Build(monitor, item, configuration));
            if (res.ErrorCount > 0)
            {
                return(res);
            }

            //copy exe, mdb, refs, copy-to-output, Content files to Resources
            var filesToCopy = GetCopyFiles(proj, configuration, conf).Where(NeedsBuilding).ToList();

            if (filesToCopy.Count > 0)
            {
                monitor.BeginTask("Copying resource files to app bundle", filesToCopy.Count);
                foreach (var f in filesToCopy)
                {
                    f.EnsureOutputDirectory();
                    File.Copy(f.Input, f.Output, true);
                    monitor.Log.WriteLine("Copied {0}", f.Output.ToRelative(appDir));
                    monitor.Step(1);
                }
                monitor.EndTask();
            }

            if (!PropertyService.IsMac)
            {
                res.AddWarning("Cannot compile xib files on non-Mac platforms");
            }
            else
            {
                //Interface Builder files
                if (res.Append(MacBuildUtilities.CompileXibFiles(monitor, proj.Files, resDir)).ErrorCount > 0)
                {
                    return(res);
                }
            }

            //info.plist
            var plistOut  = conf.AppDirectory.Combine("Contents", "Info.plist");
            var appInfoIn = proj.Files.GetFile(proj.BaseDirectory.Combine("Info.plist"));

            if (new FilePair(proj.FileName, plistOut).NeedsBuilding() ||
                (appInfoIn != null && new FilePair(appInfoIn.FilePath, plistOut).NeedsBuilding()))
            {
                if (res.Append(MergeInfoPlist(monitor, proj, conf, appInfoIn, plistOut)).ErrorCount > 0)
                {
                    return(res);
                }
            }

            //launch script
            var ls = conf.LaunchScript;

            if (!File.Exists(ls))
            {
                if (!Directory.Exists(ls.ParentDirectory))
                {
                    Directory.CreateDirectory(ls.ParentDirectory);
                }
                var src = AddinManager.CurrentAddin.GetFilePath("MonoMacLaunchScript.sh");
                File.Copy(src, ls, true);
                var fi = new UnixFileInfo(ls);
                fi.FileAccessPermissions |= FileAccessPermissions.UserExecute
                                            | FileAccessPermissions.GroupExecute | FileAccessPermissions.OtherExecute;
            }

            //pkginfo
            var pkgInfo = conf.AppDirectory.Combine("Contents", "PkgInfo");

            if (!File.Exists(pkgInfo))
            {
                using (var f = File.OpenWrite(pkgInfo))
                    f.Write(new byte [] { 0X41, 0X50, 0X50, 0X4C, 0x3f, 0x3f, 0x3f, 0x3f }, 0, 8);                     // "APPL???"
            }
            return(res);
        }
Esempio n. 2
0
        protected override BuildResult Build(IProgressMonitor monitor, SolutionEntityItem item, ConfigurationSelector configuration)
        {
            var proj = item as MonoMacProject;

            if (proj == null || proj.CompileTarget != CompileTarget.Exe)
            {
                return(base.Build(monitor, item, configuration));
            }

            var conf   = (MonoMacProjectConfiguration)configuration.GetConfiguration(item);
            var resDir = conf.AppDirectory.Combine("Contents", "Resources");
            var appDir = conf.AppDirectory;

            //make sure the codebehind files are updated before building
            var res = MacBuildUtilities.UpdateCodeBehind(monitor, proj.CodeBehindGenerator, proj.Files);

            if (res.ErrorCount > 0)
            {
                return(res);
            }

            res = res.Append(base.Build(monitor, item, configuration));
            if (res.ErrorCount > 0)
            {
                return(res);
            }

            //copy exe, mdb, refs, copy-to-output, Content files to Resources
            var filesToCopy = GetCopyFiles(proj, configuration, conf).Where(NeedsBuilding).ToList();

            if (filesToCopy.Count > 0)
            {
                monitor.BeginTask("Copying resource files to app bundle", filesToCopy.Count);
                foreach (var f in filesToCopy)
                {
                    f.EnsureOutputDirectory();
                    File.Copy(f.Input, f.Output, true);
                    monitor.Log.WriteLine("Copied {0}", f.Output.ToRelative(appDir));
                    monitor.Step(1);
                }
                monitor.EndTask();
            }

            //FIXME: only do this check if there are actually xib files
            if (!PropertyService.IsMac)
            {
                res.AddWarning("Cannot compile xib files on non-Mac platforms");
            }
            else
            {
                //Interface Builder files
                if (res.Append(MacBuildUtilities.CompileXibFiles(monitor, proj.Files, resDir)).ErrorCount > 0)
                {
                    return(res);
                }
            }

            //info.plist
            var plistOut  = conf.AppDirectory.Combine("Contents", "Info.plist");
            var appInfoIn = proj.Files.GetFile(proj.BaseDirectory.Combine("Info.plist"));

            if (new FilePair(proj.FileName, plistOut).NeedsBuilding() ||
                (appInfoIn != null && new FilePair(appInfoIn.FilePath, plistOut).NeedsBuilding()))
            {
                if (res.Append(MergeInfoPlist(monitor, proj, conf, appInfoIn, plistOut)).ErrorCount > 0)
                {
                    return(res);
                }
            }

            if (PropertyService.IsWindows)
            {
                res.AddWarning("Cannot create app bundle on Windows");
            }
            else
            {
                //launch script
                var macOSDir = appDir.Combine("Contents", "MacOS");
                CopyExecutableFile(AddinManager.CurrentAddin.GetFilePath("MonoMacLaunchScript.sh"), conf.LaunchScript);
                CopyExecutableFile(AddinManager.CurrentAddin.GetFilePath("mono-version-check"),
                                   macOSDir.Combine("mono-version-check"));

                var si = new UnixSymbolicLinkInfo(appDir.Combine(conf.AppName));
                if (!si.Exists)
                {
                    si.CreateSymbolicLinkTo("/Library/Frameworks/Mono.framework/Versions/Current/bin/mono");
                }
            }

            //pkginfo
            var pkgInfo = conf.AppDirectory.Combine("Contents", "PkgInfo");

            if (!File.Exists(pkgInfo))
            {
                using (var f = File.OpenWrite(pkgInfo))
                    f.Write(new byte [] { 0X41, 0X50, 0X50, 0X4C, 0x3f, 0x3f, 0x3f, 0x3f }, 0, 8);                     // "APPL???"
            }
            return(res);
        }