コード例 #1
0
        static bool UpdateCompleted(ProgressMonitor monitor,
                                    ProjectFile file, ProjectFile genFile, SingleFileCustomToolResult result,
                                    bool runMultipleFiles)
        {
            monitor.EndTask();

            if (monitor.CancellationToken.IsCancellationRequested)
            {
                monitor.ReportError(GettextCatalog.GetString("Cancelled"), null);
                monitor.Dispose();
                return(false);
            }

            string genFileName;

            try {
                bool broken = false;

                if (result.UnhandledException != null)
                {
                    broken = true;
                    string msg = GettextCatalog.GetString("The '{0}' code generator crashed", file.Generator);
                    result.Errors.Add(new CompilerError(file.Name, 0, 0, "",
                                                        msg +
                                                        ": " +
                                                        result.UnhandledException.Message +
                                                        Environment.NewLine +
                                                        result.UnhandledException.StackTrace));
                    monitor.ReportError(msg, result.UnhandledException);
                    LoggingService.LogError(msg, result.UnhandledException);
                }

                genFileName = result.GeneratedFilePath.IsNullOrEmpty?
                              null : result.GeneratedFilePath.ToRelative(file.FilePath.ParentDirectory);

                if (!string.IsNullOrEmpty(genFileName))
                {
                    bool validName = genFileName.IndexOfAny(new [] { '/', '\\' }) < 0 &&
                                     FileService.IsValidFileName(genFileName);

                    if (!broken && !validName)
                    {
                        broken = true;
                        string msg = GettextCatalog.GetString("The '{0}' code generator output invalid filename '{1}'",
                                                              file.Generator, result.GeneratedFilePath);
                        result.Errors.Add(new CompilerError(file.Name, 0, 0, "", msg));
                        monitor.ReportError(msg, null);
                    }
                }

                if (result.Errors.Count > 0)
                {
                    Runtime.RunInMainThread(delegate {
                        foreach (CompilerError err in result.Errors)
                        {
                            TaskService.Errors.Add(new TaskListEntry(file.FilePath, err.ErrorText, err.Column, err.Line,
                                                                     err.IsWarning? TaskSeverity.Warning : TaskSeverity.Error,
                                                                     TaskPriority.Normal, file.Project.ParentSolution, file));
                        }
                    });
                }

                if (broken)
                {
                    return(true);
                }

                if (!runMultipleFiles)
                {
                    if (result.Success)
                    {
                        monitor.ReportSuccess("Generated file successfully.");
                    }
                    else if (result.SuccessWithWarnings)
                    {
                        monitor.ReportSuccess("Warnings in file generation.");
                    }
                    else
                    {
                        monitor.ReportError("Errors in file generation.", null);
                    }
                }
            } finally {
                if (!runMultipleFiles)
                {
                    monitor.Dispose();
                }
            }

            if (result.GeneratedFilePath.IsNullOrEmpty || !File.Exists(result.GeneratedFilePath))
            {
                return(true);
            }

            // broadcast a change event so text editors etc reload the file
            FileService.NotifyFileChanged(result.GeneratedFilePath);

            // add file to project, update file properties, etc
            Gtk.Application.Invoke(async(o, args) => {
                bool projectChanged = false;
                if (genFile == null)
                {
                    genFile        = file.Project.AddFile(result.GeneratedFilePath, result.OverrideBuildAction);
                    projectChanged = true;
                }
                else if (result.GeneratedFilePath != genFile.FilePath)
                {
                    genFile.Name   = result.GeneratedFilePath;
                    projectChanged = true;
                }

                if (file.LastGenOutput != genFileName)
                {
                    file.LastGenOutput = genFileName;
                    projectChanged     = true;
                }

                if (genFile.DependsOn != file.FilePath.FileName)
                {
                    genFile.DependsOn = file.FilePath.FileName;
                    projectChanged    = true;
                }

                if (projectChanged)
                {
                    await IdeApp.ProjectOperations.SaveAsync(file.Project);
                }
            });

            return(true);
        }
コード例 #2
0
        protected override bool OnBuild(ProgressMonitor monitor, DeployContext ctx)
        {
            string tmpFolder = null;

            try {
                SolutionConfigurationSelector conf = (SolutionConfigurationSelector)configuration;
                var bt = RootSolutionItem as IBuildTarget;
                if (bt != null)
                {
                    BuildResult res = bt.Build(monitor, conf).Result;
                    if (res.ErrorCount > 0)
                    {
                        foreach (BuildError e in res.Errors)
                        {
                            monitor.ReportError(e.ToString(), null);
                        }
                        monitor.ReportError(GettextCatalog.GetString("The source project failed to build."), null);
                        return(false);
                    }
                }

                tmpFolder = FileService.CreateTempDirectory();

                string tf = Path.GetFileNameWithoutExtension(targetFile);
                if (tf.EndsWith(".tar"))
                {
                    tf = Path.GetFileNameWithoutExtension(tf);
                }
                string folder = FileService.GetFullPath(Path.Combine(tmpFolder, tf));

                // Export the binary files
                DeployFileCollection deployFiles = GetDeployFiles(ctx, conf);
                foreach (DeployFile file in deployFiles)
                {
                    string tfile = Path.Combine(folder, file.ResolvedTargetFile);
                    string tdir  = FileService.GetFullPath(Path.GetDirectoryName(tfile));
                    if (!Directory.Exists(tdir))
                    {
                        Directory.CreateDirectory(tdir);
                    }
                    File.Copy(file.SourcePath, tfile, true);
                }

                // Create the archive
                string td = Path.GetDirectoryName(targetFile);
                if (!Directory.Exists(td))
                {
                    Directory.CreateDirectory(td);
                }
                DeployService.CreateArchive(monitor, tmpFolder, targetFile);
            }
            catch (Exception ex) {
                monitor.ReportError("Package creation failed", ex);
                LoggingService.LogError("Package creation failed", ex);
                return(false);
            }
            finally {
                if (tmpFolder != null)
                {
                    Directory.Delete(tmpFolder, true);
                }
            }
            monitor.Log.WriteLine(GettextCatalog.GetString("Created file: {0}", targetFile));
            return(true);
        }
コード例 #3
0
        protected override bool OnBuild(ProgressMonitor monitor, DeployContext ctx)
        {
            string             tmpFolder = FileService.CreateTempDirectory();
            Solution           solution  = null;
            SolutionFolderItem entry     = RootSolutionItem;

            try {
                if (generateFiles)
                {
                    List <string> childEntries = new List <string> ();
                    if (entry is SolutionFolder)
                    {
                        SolutionFolderItem[] ents = GetChildEntries();
                        foreach (SolutionFolderItem it in ents)
                        {
                            childEntries.Add(it.ItemId);
                        }
                    }
                    else
                    {
                        // If the entry is not a combine, use the parent combine as base combine
                        childEntries.Add(entry.ItemId);
                        entry = entry.ParentFolder;
                    }

                    string sourceFile;
                    if (entry is SolutionFolder)
                    {
                        sourceFile = entry.ParentSolution.FileName;
                    }
                    else
                    {
                        sourceFile = ((SolutionItem)entry).FileName;
                    }

                    string efile = Services.ProjectService.Export(new FilteredProgressMonitor(monitor), sourceFile, childEntries.ToArray(), tmpFolder, null).Result;
                    if (efile == null)
                    {
                        monitor.ReportError(GettextCatalog.GetString("The project could not be exported."), null);
                        return(false);
                    }
                    solution = Services.ProjectService.ReadWorkspaceItem(new ProgressMonitor(), efile).Result as Solution;
                }
                else
                {
                    solution = entry.ParentSolution;
                }

                var res = solution.Build(monitor, (SolutionConfigurationSelector)defaultConfig).Result;
                if (res.HasErrors || monitor.CancellationToken.IsCancellationRequested)
                {
                    return(false);
                }

                SolutionDeployer deployer = new SolutionDeployer(generateAutotools);
                deployer.AddSwitches(switchs);

                if (!deployer.Deploy(ctx, solution, DefaultConfiguration, TargetDir, generateFiles, monitor))
                {
                    return(false);
                }
            } finally {
                if (solution != null)
                {
                    solution.Dispose();
                }
                Directory.Delete(tmpFolder, true);
            }
            return(true);
        }
コード例 #4
0
        public async Task <bool> Execute(ProgressMonitor monitor, WorkspaceObject entry, ExecutionContext context,
                                         ConfigurationSelector configuration)
        {
            ProcessExecutionCommand cmd = CreateExecutionCommand(entry, configuration);

            monitor.Log.WriteLine(GettextCatalog.GetString("Executing: {0} {1}", cmd.Command, cmd.Arguments));

            if (!Directory.Exists(cmd.WorkingDirectory))
            {
                monitor.ReportError(GettextCatalog.GetString("Custom command working directory does not exist"), null);
                return(false);
            }

            ProcessAsyncOperation oper    = null;
            OperationConsole      console = null;
            var result = true;

            try {
                if (context != null)
                {
                    if (externalConsole)
                    {
                        console = context.ExternalConsoleFactory.CreateConsole(!pauseExternalConsole, monitor.CancellationToken);
                    }
                    else
                    {
                        console = context.ConsoleFactory.CreateConsole(monitor.CancellationToken);
                    }
                    oper = context.ExecutionHandler.Execute(cmd, console);
                }
                else
                {
                    if (externalConsole)
                    {
                        console = context.ExternalConsoleFactory.CreateConsole(!pauseExternalConsole, monitor.CancellationToken);
                        oper    = Runtime.ProcessService.StartConsoleProcess(cmd.Command, cmd.Arguments,
                                                                             cmd.WorkingDirectory, console, null);
                    }
                    else
                    {
                        oper = Runtime.ProcessService.StartProcess(cmd.Command, cmd.Arguments,
                                                                   cmd.WorkingDirectory, monitor.Log, monitor.Log, null, false).ProcessAsyncOperation;
                    }
                }

                var stopper = monitor.CancellationToken.Register(oper.Cancel);

                await oper.Task;

                stopper.Dispose();

                if (oper.ExitCode != 0)
                {
                    monitor.ReportError(GettextCatalog.GetString("Custom command failed (exit code: {0})", oper.ExitCode), null);
                }
            } catch (Win32Exception w32ex) {
                monitor.ReportError(GettextCatalog.GetString("Failed to execute custom command '{0}': {1}",
                                                             cmd.Command, w32ex.Message), null);
                return(false);
            } catch (Exception ex) {
                LoggingService.LogError("Command execution failed", ex);
                throw new UserException(GettextCatalog.GetString("Command execution failed: {0}", ex.Message));
            } finally {
                result = oper != null && oper.ExitCode == 0;
                if (console != null)
                {
                    console.Dispose();
                }
            }
            return(result);
        }