コード例 #1
0
        protected override Task <BuildResult> OnBuild(ProgressMonitor monitor, ConfigurationSelector configuration,
                                                      OperationContext operationContext)
        {
            return(Task.Factory.StartNew(() => {
                BuildResult results;

                if (!CheckCMake())
                {
                    results = new BuildResult();
                    results.AddError("CMake cannot be found.");
                    return results;
                }

                FileService.CreateDirectory(file.ParentDirectory.Combine(outputDirectory));

                monitor.BeginStep("Generating build files.");
                Stream generationResult = ExecuteCommand("cmake", "../", outputDirectory, monitor);
                results = ParseGenerationResult(generationResult, monitor);
                monitor.EndStep();

                monitor.BeginStep("Building...");
                Stream buildResult = ExecuteCommand("cmake", "--build ./ --clean-first", outputDirectory, monitor);
                //TODO: Parse results.
                monitor.EndStep();

                return results;
            }));
        }
コード例 #2
0
        void WriteFileInternal(string file, string sourceFile, Solution solution, bool saveProjects, ProgressMonitor monitor)
        {
            if (saveProjects)
            {
                var items = solution.GetAllSolutionItems().ToArray();
                monitor.BeginTask(items.Length + 1);
                foreach (var item in items)
                {
                    try {
                        monitor.BeginStep();
                        item.SavingSolution = true;
                        item.SaveAsync(monitor).Wait();
                    } finally {
                        item.SavingSolution = false;
                    }
                }
            }
            else
            {
                monitor.BeginTask(1);
                monitor.BeginStep();
            }

            SlnFile sln = new SlnFile();

            sln.FileName = file;
            if (File.Exists(sourceFile))
            {
                try {
                    sln.Read(sourceFile);
                } catch (Exception ex) {
                    LoggingService.LogError("Existing solution can't be updated since it can't be read", ex);
                }
            }

            sln.FormatVersion = format.SlnVersion;

            // Don't modify the product description if it already has a value
            if (string.IsNullOrEmpty(sln.ProductDescription))
            {
                sln.ProductDescription = format.ProductDescription;
            }

            solution.WriteSolution(monitor, sln);

            sln.Write(file);
            monitor.EndTask();
        }
コード例 #3
0
        protected override Task <BuildResult> OnBuild(ProgressMonitor monitor, ConfigurationSelector configuration,
                                                      OperationContext operationContext)
        {
            return(Task.Factory.StartNew(() => {
                BuildResult results;

                if (!CheckCMake())
                {
                    results = new BuildResult();
                    results.AddError("CMake cannot be found.");
                    return results;
                }

                FileService.CreateDirectory(file.ParentDirectory.Combine(outputDirectory));

                Stream generationResult;
                int buildFlag = 0;
                monitor.BeginStep("Generating build files.");
                if (guiOptions.default_c_compiler.Name == "msvc")
                {
                    generationResult = ExecuteCommand("cmake", "../ -G \"Visual Studio 15 2017\"", outputDirectory, monitor);
                    buildFlag = 1;
                }
                else
                {
                    generationResult = ExecuteCommand("cmake", "../ -G \"MinGW Makefiles\"", outputDirectory, monitor);                      //Default is gcc.
                }
                results = ParseGenerationResult(generationResult, monitor);
                monitor.EndStep();

                string projectMsvc = string.Format("{0}.{1}", fileFormat.ProjectName, "sln");
                monitor.BeginStep("Building...");
                if (buildFlag == 1)
                {
                    Stream buildResult = ExecuteCommand("msbuild", projectMsvc, outputDirectory, monitor);
                    buildFlag = 0;
                }
                else
                {
                    Stream buildResult = ExecuteCommand("mingw32-make", "", outputDirectory, monitor);
                }
                //TODO: Parse results.
                monitor.EndStep();

                return results;
            }));
        }
コード例 #4
0
        void WriteProjects(SolutionFolder folder, SlnFile sln, ProgressMonitor monitor, HashSet <string> unknownProjects)
        {
            monitor.BeginTask(folder.Items.Count);
            foreach (SolutionFolderItem ce in folder.Items.ToArray())
            {
                monitor.BeginStep();
                if (ce is SolutionItem)
                {
                    SolutionItem item = (SolutionItem)ce;

                    var proj = sln.Projects.GetOrCreateProject(ce.ItemId);
                    proj.TypeGuid = item.TypeGuid;
                    proj.Name     = item.Name;
                    proj.FilePath = FileService.NormalizeRelativePath(FileService.AbsoluteToRelativePath(sln.BaseDirectory, item.FileName)).Replace('/', '\\');

                    var sec = proj.Sections.GetOrCreateSection("MonoDevelopProperties", SlnSectionType.PreProcess);
                    sec.SkipIfEmpty = true;
                    folder.ParentSolution.WriteSolutionFolderItemData(monitor, sec.Properties, ce);

                    if (item.ItemDependencies.Count > 0)
                    {
                        sec = proj.Sections.GetOrCreateSection("ProjectDependencies", SlnSectionType.PostProcess);
                        sec.Properties.ClearExcept(unknownProjects);
                        foreach (var dep in item.ItemDependencies)
                        {
                            sec.Properties.SetValue(dep.ItemId, dep.ItemId);
                        }
                    }
                    else
                    {
                        proj.Sections.RemoveSection("ProjectDependencies");
                    }
                }
                else if (ce is SolutionFolder)
                {
                    var proj = sln.Projects.GetOrCreateProject(ce.ItemId);
                    proj.TypeGuid = MSBuildProjectService.FolderTypeGuid;
                    proj.Name     = ce.Name;
                    proj.FilePath = ce.Name;

                    // Folder files
                    WriteFolderFiles(proj, (SolutionFolder)ce);

                    //Write custom properties
                    var sec = proj.Sections.GetOrCreateSection("MonoDevelopProperties", SlnSectionType.PreProcess);
                    sec.SkipIfEmpty = true;
                    folder.ParentSolution.WriteSolutionFolderItemData(monitor, sec.Properties, ce);
                }
                if (ce is SolutionFolder)
                {
                    WriteProjects(ce as SolutionFolder, sln, monitor, unknownProjects);
                }
            }
            monitor.EndTask();
        }
コード例 #5
0
        //Reader
        public async Task <object> ReadFile(string fileName, ProgressMonitor monitor)
        {
            if (fileName == null || monitor == null)
            {
                return(null);
            }

            var sol = new Solution(true);

            sol.FileName   = fileName;
            sol.FileFormat = format;

            try {
                monitor.BeginTask(string.Format(GettextCatalog.GetString("Loading solution: {0}"), fileName), 1);
                monitor.BeginStep();
                await sol.OnBeginLoad();

                var projectLoadMonitor = monitor as ProjectLoadProgressMonitor;
                if (projectLoadMonitor != null)
                {
                    projectLoadMonitor.CurrentSolution = sol;
                }
                await Task.Factory.StartNew(() => {
                    sol.ReadSolution(monitor);
                });
            } catch (Exception ex) {
                monitor.ReportError(GettextCatalog.GetString("Could not load solution: {0}", fileName), ex);
                await sol.OnEndLoad();

                sol.NotifyItemReady();
                monitor.EndTask();
                throw;
            }
            await sol.OnEndLoad();

            sol.NotifyItemReady();
            monitor.EndTask();
            return(sol);
        }
コード例 #6
0
        internal void WriteFileInternal(SlnFile sln, Solution solution, ProgressMonitor monitor)
        {
            SolutionFolder c = solution.RootFolder;

            // Delete data for projects that have been removed from the solution

            var currentProjects = new HashSet <string> (solution.GetAllItems <SolutionFolderItem> ().Select(it => it.ItemId));
            var removedProjects = new HashSet <string> ();

            if (solution.LoadedProjects != null)
            {
                removedProjects.UnionWith(solution.LoadedProjects.Except(currentProjects));
            }
            var unknownProjects = new HashSet <string> (sln.Projects.Select(p => p.Id).Except(removedProjects).Except(currentProjects));

            foreach (var p in removedProjects)
            {
                var ps = sln.Projects.GetProject(p);
                if (ps != null)
                {
                    sln.Projects.Remove(ps);
                }
                var pc = sln.ProjectConfigurationsSection.GetPropertySet(p, true);
                if (pc != null)
                {
                    sln.ProjectConfigurationsSection.Remove(pc);
                }
            }
            var secNested = sln.Sections.GetSection("NestedProjects");

            if (secNested != null)
            {
                foreach (var np in secNested.Properties.ToArray())
                {
                    if (removedProjects.Contains(np.Key) || removedProjects.Contains(np.Value))
                    {
                        secNested.Properties.Remove(np.Key);
                    }
                }
            }
            solution.LoadedProjects = currentProjects;

            //Write the projects
            using (monitor.BeginTask(GettextCatalog.GetString("Saving projects"), 1)) {
                monitor.BeginStep();
                WriteProjects(c, sln, monitor, unknownProjects);
            }

            //FIXME: SolutionConfigurations?

            var pset = sln.SolutionConfigurationsSection;

            foreach (SolutionConfiguration config in solution.Configurations)
            {
                var cid = ToSlnConfigurationId(config);
                pset.SetValue(cid, cid);
            }

            WriteProjectConfigurations(solution, sln);

            //Write Nested Projects
            ICollection <SolutionFolder> folders = solution.RootFolder.GetAllItems <SolutionFolder> ().ToList();

            if (folders.Count > 1)
            {
                // If folders ==1, that's the root folder
                var sec = sln.Sections.GetSection("NestedProjects", SlnSectionType.PreProcess);
                if (sec == null)
                {
                    sec             = sln.Sections.GetOrCreateSection("NestedProjects", SlnSectionType.PreProcess);
                    sec.SkipIfEmpty = true;                     // don't write the section if there are no nested projects after all
                }
                foreach (SolutionFolder folder in folders)
                {
                    if (folder.IsRoot)
                    {
                        continue;
                    }
                    WriteNestedProjects(folder, solution.RootFolder, sec);
                }
                // Remove items which don't have a parent folder
                var toRemove = solution.GetAllItems <SolutionFolderItem> ().Where(it => it.ParentFolder == solution.RootFolder);
                foreach (var it in toRemove)
                {
                    sec.Properties.Remove(it.ItemId);
                }
            }

            // Write custom properties for configurations
            foreach (SolutionConfiguration conf in solution.Configurations)
            {
                string secId = "MonoDevelopProperties." + conf.Id;
                var    sec   = sln.Sections.GetOrCreateSection(secId, SlnSectionType.PreProcess);
                solution.WriteConfigurationData(monitor, sec.Properties, conf);
                if (sec.IsEmpty)
                {
                    sln.Sections.Remove(sec);
                }
            }
        }