diff options
Diffstat (limited to 'main/src/addins/CBinding')
11 files changed, 73 insertions, 224 deletions
diff --git a/main/src/addins/CBinding/CBinding.addin.xml b/main/src/addins/CBinding/CBinding.addin.xml index 35cb77e26d..1fef8d00e9 100644 --- a/main/src/addins/CBinding/CBinding.addin.xml +++ b/main/src/addins/CBinding/CBinding.addin.xml @@ -190,12 +190,6 @@ <CommandItem id = "MonoDevelop.Ide.Commands.EditCommands.Delete"/> </Extension> - <Extension path = "/MonoDevelop/ProjectModel/ProjectServiceExtensions"> - <Condition id="ItemType" value="CBinding.CProject"> - <Class id = "ExtraSteps" class = "CBinding.CProjectServiceExtension"/> - </Condition> - </Extension> - <Extension path = "/MonoDevelop/Ide/TextEditorExtensions"> <Class fileExtensions=".c,.cpp,.cxx,.cc,.h,.hpp,.hh,.hxx,.m,.mm,.M" class = "CBinding.CTextEditorExtension" /> </Extension> @@ -207,11 +201,7 @@ <DataType class = "CBinding.GppCompiler"/> <DataType class = "CBinding.Package"/> </Extension> - - <Extension path = "/MonoDevelop/ProjectModel/MSBuildItemTypes"> - <SolutionItem type="CBinding.CProject" extension="cproj" guid="{2857B73E-F847-4B02-9238-064979017E93}"/> - </Extension> - + <!-- Current Autotools AddIn is very .NET specific <Module> <Runtime> diff --git a/main/src/addins/CBinding/CBinding.csproj b/main/src/addins/CBinding/CBinding.csproj index 94f0eb7bb6..7962736351 100644 --- a/main/src/addins/CBinding/CBinding.csproj +++ b/main/src/addins/CBinding/CBinding.csproj @@ -200,7 +200,6 @@ </ItemGroup> <ItemGroup> <Compile Include="Project\CProject.cs" /> - <Compile Include="Project\CProjectBinding.cs" /> <Compile Include="Project\CProjectConfiguration.cs" /> <Compile Include="gtk-gui\generated.cs" /> <Compile Include="Gui\CodeGenerationPanel.cs" /> @@ -220,7 +219,6 @@ <Compile Include="Project\ProjectPackageEventArgs.cs" /> <Compile Include="Gui\OutputOptionsPanel.cs" /> <Compile Include="gtk-gui\CBinding.OutputOptionsPanel.cs" /> - <Compile Include="Project\CProjectServiceExtension.cs" /> <Compile Include="Navigation\ProjectNodeBuilderExtension.cs" /> <Compile Include="Navigation\NamespaceNodeBuilder.cs" /> <Compile Include="ProjectPad\ProjectReferencesExtension.cs" /> diff --git a/main/src/addins/CBinding/Compiler/CCompiler.cs b/main/src/addins/CBinding/Compiler/CCompiler.cs index b094faf03f..4a92d92bc2 100644 --- a/main/src/addins/CBinding/Compiler/CCompiler.cs +++ b/main/src/addins/CBinding/Compiler/CCompiler.cs @@ -75,9 +75,9 @@ namespace CBinding ProjectFileCollection projectFiles, ProjectPackageCollection packages, CProjectConfiguration configuration, - IProgressMonitor monitor); + ProgressMonitor monitor); - public abstract void Clean (ProjectFileCollection projectFiles, CProjectConfiguration configuration, IProgressMonitor monitor); + public abstract void Clean (ProjectFileCollection projectFiles, CProjectConfiguration configuration, ProgressMonitor monitor); protected abstract void ParseCompilerOutput (string errorString, CompilerResults cr); diff --git a/main/src/addins/CBinding/Compiler/GNUCompiler.cs b/main/src/addins/CBinding/Compiler/GNUCompiler.cs index b75471a9ff..be4a0bc5f8 100644 --- a/main/src/addins/CBinding/Compiler/GNUCompiler.cs +++ b/main/src/addins/CBinding/Compiler/GNUCompiler.cs @@ -56,7 +56,7 @@ namespace CBinding ProjectFileCollection projectFiles, ProjectPackageCollection packages, CProjectConfiguration configuration, - IProgressMonitor monitor) + ProgressMonitor monitor) { if (!appsChecked) { appsChecked = true; @@ -271,7 +271,7 @@ namespace CBinding private bool PrecompileHeaders (ProjectFileCollection projectFiles, CProjectConfiguration configuration, string args, - IProgressMonitor monitor, + ProgressMonitor monitor, CompilerResults cr) { monitor.BeginTask (GettextCatalog.GetString ("Precompiling headers"), 1); @@ -303,7 +303,7 @@ namespace CBinding return success; } - private bool DoPrecompileHeader (ProjectFile file, string output, string args, IProgressMonitor monitor, CompilerResults cr) + private bool DoPrecompileHeader (ProjectFile file, string output, string args, ProgressMonitor monitor, CompilerResults cr) { string completeArgs = String.Format ("\"{0}\" {1} -o {2}", file.Name, args, output); string errorOutput; @@ -353,7 +353,7 @@ namespace CBinding CProjectConfiguration configuration, ProjectPackageCollection packages, CompilerResults cr, - IProgressMonitor monitor, string outputName) + ProgressMonitor monitor, string outputName) { if (!NeedsUpdate (projectFiles, configuration, outputName)) return; @@ -406,7 +406,7 @@ namespace CBinding CProjectConfiguration configuration, ProjectPackageCollection packages, CompilerResults cr, - IProgressMonitor monitor, string outputName) + ProgressMonitor monitor, string outputName) { if (!NeedsUpdate (projectFiles, configuration, outputName)) return; @@ -431,7 +431,7 @@ namespace CBinding CProjectConfiguration configuration, ProjectPackageCollection packages, CompilerResults cr, - IProgressMonitor monitor, string outputName) + ProgressMonitor monitor, string outputName) { if (!NeedsUpdate (projectFiles, configuration, outputName)) return; @@ -479,7 +479,7 @@ namespace CBinding CheckReturnCode (exitCode, cr); } - int ExecuteCommand (string command, string args, string baseDirectory, IProgressMonitor monitor, out string errorOutput) + int ExecuteCommand (string command, string args, string baseDirectory, ProgressMonitor monitor, out string errorOutput) { errorOutput = string.Empty; int exitCode = -1; @@ -491,23 +491,20 @@ namespace CBinding monitor.Log.WriteLine ("{0} {1}", command, args); - using (var operationMonitor = new AggregatedOperationMonitor (monitor)) { - using (ProcessWrapper p = Runtime.ProcessService.StartProcess (command, args, baseDirectory, monitor.Log, chainedError, null)) { - operationMonitor.AddOperation (p); //handles cancellation - - p.WaitForOutput (); - chainedError.UnchainWriter (monitor.Log); - chainedError.UnchainWriter (swError); + using (ProcessWrapper p = Runtime.ProcessService.StartProcess (command, args, baseDirectory, monitor.Log, chainedError, null)) + using (monitor.CancellationToken.Register (p.Cancel)) { + p.WaitForOutput (); + chainedError.UnchainWriter (monitor.Log); + chainedError.UnchainWriter (swError); - errorOutput = swError.ToString (); - exitCode = p.ExitCode; - - if (monitor.IsCancelRequested) { - monitor.Log.WriteLine (GettextCatalog.GetString ("Build cancelled")); - monitor.ReportError (GettextCatalog.GetString ("Build cancelled"), null); - if (exitCode == 0) - exitCode = -1; - } + errorOutput = swError.ToString (); + exitCode = p.ExitCode; + + if (monitor.CancellationToken.IsCancellationRequested) { + monitor.Log.WriteLine (GettextCatalog.GetString ("Build cancelled")); + monitor.ReportError (GettextCatalog.GetString ("Build cancelled"), null); + if (exitCode == 0) + exitCode = -1; } } } @@ -542,7 +539,7 @@ namespace CBinding private bool DoCompilation (ProjectFile file, CProjectConfiguration configuration, string args, - IProgressMonitor monitor, + ProgressMonitor monitor, CompilerResults cr, bool use_ccache) { @@ -605,7 +602,7 @@ namespace CBinding return objectFiles.ToArray (); } - public override void Clean (ProjectFileCollection projectFiles, CProjectConfiguration configuration, IProgressMonitor monitor) + public override void Clean (ProjectFileCollection projectFiles, CProjectConfiguration configuration, ProgressMonitor monitor) { //clean up object files foreach (string oFile in ObjectFiles(projectFiles, configuration, false)) { diff --git a/main/src/addins/CBinding/Compiler/ICompiler.cs b/main/src/addins/CBinding/Compiler/ICompiler.cs index edb2b80c96..a3b7ad7a0e 100644 --- a/main/src/addins/CBinding/Compiler/ICompiler.cs +++ b/main/src/addins/CBinding/Compiler/ICompiler.cs @@ -69,8 +69,8 @@ namespace CBinding ProjectFileCollection projectFiles, ProjectPackageCollection packages, CProjectConfiguration configuration, - IProgressMonitor monitor); + ProgressMonitor monitor); - void Clean (ProjectFileCollection projectFiles, CProjectConfiguration configuration, IProgressMonitor monitor); + void Clean (ProjectFileCollection projectFiles, CProjectConfiguration configuration, ProgressMonitor monitor); } } diff --git a/main/src/addins/CBinding/Gui/EditPackagesDialog.cs b/main/src/addins/CBinding/Gui/EditPackagesDialog.cs index d7cd1f8adb..b43001e1b3 100644 --- a/main/src/addins/CBinding/Gui/EditPackagesDialog.cs +++ b/main/src/addins/CBinding/Gui/EditPackagesDialog.cs @@ -192,7 +192,7 @@ namespace CBinding List<Package> packages = new List<Package>(); Package package; - foreach (SolutionItem c in project.ParentFolder.Items) { + foreach (SolutionFolderItem c in project.ParentFolder.Items) { if (null != c && c is CProject) { CProject cproj = (CProject)c; CProjectConfiguration conf = (CProjectConfiguration)cproj.GetConfiguration (IdeApp.Workspace.ActiveConfiguration); diff --git a/main/src/addins/CBinding/Project/CProject.cs b/main/src/addins/CBinding/Project/CProject.cs index 231830b4f0..79e1bc2535 100644 --- a/main/src/addins/CBinding/Project/CProject.cs +++ b/main/src/addins/CBinding/Project/CProject.cs @@ -46,6 +46,7 @@ using MonoDevelop.Deployment; using MonoDevelop.Deployment.Linux; using CBinding.Parser; using MonoDevelop.Ide; +using System.Threading.Tasks; namespace CBinding { @@ -62,8 +63,8 @@ namespace CBinding ShowPackageDetails, GotoDeclaration, } - - [DataInclude(typeof(CProjectConfiguration))] + + [RegisterProjectType ("{2857B73E-F847-4B02-9238-064979017E93}", Extension="cproj", Alias="C/C++")] public class CProject : Project, IDeployable { [ItemProperty ("Compiler", ValueType = typeof(CCompiler))] @@ -177,9 +178,9 @@ namespace CBinding } } - public override IEnumerable<string> GetProjectTypes () + protected override void OnGetProjectTypes (HashSet<string> types) { - yield return "Native"; + types.Add ("Native"); } public override string[] SupportedLanguages { @@ -202,7 +203,7 @@ namespace CBinding } } - public override IEnumerable<SolutionItem> GetReferencedItems (ConfigurationSelector configuration) + protected override IEnumerable<SolutionItem> OnGetReferencedItems (ConfigurationSelector configuration) { foreach (var p in base.GetReferencedItems (configuration)) yield return p; @@ -302,15 +303,33 @@ namespace CBinding return pkgfile; } - protected override BuildResult DoBuild (IProgressMonitor monitor, ConfigurationSelector configuration) + protected override Task<BuildResult> DoBuild (ProgressMonitor monitor, ConfigurationSelector configuration) { CProjectConfiguration pc = (CProjectConfiguration) GetConfiguration (configuration); pc.SourceDirectory = BaseDirectory; - - return compiler_manager.Compile (this, - Files, packages, - pc, - monitor); + + return Task<BuildResult>.Factory.StartNew (delegate { + if (pc.CompileTarget != CompileTarget.Bin) + WriteMDPkgPackage (configuration); + + return compiler_manager.Compile (this, + Files, packages, + pc, + monitor); + }); + } + + protected async override Task<BuildResult> OnClean (ProgressMonitor monitor, ConfigurationSelector configuration) + { + CProjectConfiguration conf = (CProjectConfiguration) GetConfiguration (configuration); + + var res = await base.OnClean (monitor, configuration); + if (res.HasErrors) + return res; + + await Task.Factory.StartNew (() => Compiler.Clean (Files, conf, monitor)); + + return res; } protected virtual ExecutionCommand CreateExecutionCommand (CProjectConfiguration conf) @@ -330,7 +349,7 @@ namespace CBinding return (target == CBinding.CompileTarget.Bin) && context.ExecutionHandler.CanExecute (cmd); } - protected override void DoExecute (IProgressMonitor monitor, ExecutionContext context, ConfigurationSelector configuration) + protected async override Task DoExecute (ProgressMonitor monitor, ExecutionContext context, ConfigurationSelector configuration) { CProjectConfiguration conf = (CProjectConfiguration) GetConfiguration (configuration); bool pause = conf.PauseConsoleOutput; @@ -348,26 +367,22 @@ namespace CBinding else console = context.ConsoleFactory.CreateConsole (!pause); - AggregatedOperationMonitor operationMonitor = new AggregatedOperationMonitor (monitor); - try { ExecutionCommand cmd = CreateExecutionCommand (conf); if (!context.ExecutionHandler.CanExecute (cmd)) { monitor.ReportError ("Cannot execute \"" + conf.Output + "\". The selected execution mode is not supported for C projects.", null); return; } - - IProcessAsyncOperation op = context.ExecutionHandler.Execute (cmd, console); - - operationMonitor.AddOperation (op); - op.WaitForCompleted (); + + ProcessAsyncOperation op = context.ExecutionHandler.Execute (cmd, console); + using (var t = monitor.CancellationToken.Register (op.Cancel)) + await op.Task; monitor.Log.WriteLine ("The operation exited with code: {0}", op.ExitCode); } catch (Exception ex) { LoggingService.LogError (string.Format ("Cannot execute \"{0}\"", conf.Output), ex); monitor.ReportError ("Cannot execute \"" + conf.Output + "\"", ex); } finally { - operationMonitor.Dispose (); console.Dispose (); } } diff --git a/main/src/addins/CBinding/Project/CProjectBinding.cs b/main/src/addins/CBinding/Project/CProjectBinding.cs deleted file mode 100644 index db379d8763..0000000000 --- a/main/src/addins/CBinding/Project/CProjectBinding.cs +++ /dev/null @@ -1,85 +0,0 @@ -// -// CProjectBinding.cs: binding with the CProject -// -// Authors: -// Marcos David Marin Amador <MarcosMarin@gmail.com> -// -// Copyright (C) 2007 Marcos David Marin Amador -// -// -// This source code is licenced under The MIT License: -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System.Xml; -using System.IO; - -using Mono.Addins; - -using MonoDevelop.Projects; - -namespace CBinding -{ - public class CProjectBinding : IProjectBinding - { - public string Name { - get { return "C/C++"; } - } - - public Project CreateProject (ProjectCreateInformation info, - XmlElement projectOptions) - { - string language = projectOptions.GetAttribute ("language"); - return new CProject (info, projectOptions, language); - } - - public Project CreateSingleFileProject (string sourceFile) - { - var info = new ProjectCreateInformation () { - ProjectName = Path.GetFileNameWithoutExtension (sourceFile), - SolutionPath = Path.GetDirectoryName (sourceFile), - ProjectBasePath = Path.GetDirectoryName (sourceFile), - }; - - Project project = new CProject (info, null, GetLanguage (sourceFile)); - project.Files.Add (new ProjectFile (sourceFile)); - return project; - } - - string GetLanguage (string filename) - { - switch (Path.GetExtension (filename.ToLower ())) { - case ".c": - return "C"; - case ".cpp": - case ".cxx": - return "CPP"; - default: - return null; - } - } - - public bool CanCreateSingleFileProject (string sourceFile) - { - return GetLanguage (sourceFile) != null; - } - } -} diff --git a/main/src/addins/CBinding/Project/CProjectServiceExtension.cs b/main/src/addins/CBinding/Project/CProjectServiceExtension.cs deleted file mode 100644 index 22775dc090..0000000000 --- a/main/src/addins/CBinding/Project/CProjectServiceExtension.cs +++ /dev/null @@ -1,70 +0,0 @@ -// -// CProjectServiceExtension.cs -// -// Authors: -// Marcos David Marin Amador <MarcosMarin@gmail.com> -// -// Copyright (C) 2007 Marcos David Marin Amador -// -// -// This source code is licenced under The MIT License: -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.IO; -using System.Text; - -using Mono.Addins; - -using MonoDevelop.Core; -using MonoDevelop.Projects; -using MonoDevelop.Core.Execution; - -namespace CBinding -{ - public class CProjectServiceExtension : ProjectServiceExtension - { - public override bool SupportsItem (IBuildTarget item) - { - return item is CProject; - } - - protected override BuildResult Build (IProgressMonitor monitor, SolutionEntityItem entry, ConfigurationSelector configuration) - { - CProject project = (CProject) entry; - CProjectConfiguration conf = (CProjectConfiguration) project.GetConfiguration (configuration); - if (conf.CompileTarget != CompileTarget.Bin) - project.WriteMDPkgPackage (configuration); - - return base.Build (monitor, entry, configuration); - } - - protected override void Clean (IProgressMonitor monitor, SolutionEntityItem entry, ConfigurationSelector configuration) - { - base.Clean (monitor, entry, configuration); - - CProject project = (CProject) entry; - CProjectConfiguration conf = (CProjectConfiguration) project.GetConfiguration (configuration); - project.Compiler.Clean (project.Files, conf, monitor); - } - } -} diff --git a/main/src/addins/CBinding/ProjectPad/ProjectPackageNodeBuilder.cs b/main/src/addins/CBinding/ProjectPad/ProjectPackageNodeBuilder.cs index 6c460d9aac..42cbc28768 100644 --- a/main/src/addins/CBinding/ProjectPad/ProjectPackageNodeBuilder.cs +++ b/main/src/addins/CBinding/ProjectPad/ProjectPackageNodeBuilder.cs @@ -81,7 +81,7 @@ namespace CBinding.ProjectPad project.Packages.Remove (package); - IdeApp.ProjectOperations.Save (project); + IdeApp.ProjectOperations.SaveAsync (project); } public override DragOperation CanDragNode () diff --git a/main/src/addins/CBinding/ProjectPad/ProjectPackagesFolderNodeBuilder.cs b/main/src/addins/CBinding/ProjectPad/ProjectPackagesFolderNodeBuilder.cs index dc3dd1e117..9e86d90b68 100644 --- a/main/src/addins/CBinding/ProjectPad/ProjectPackagesFolderNodeBuilder.cs +++ b/main/src/addins/CBinding/ProjectPad/ProjectPackagesFolderNodeBuilder.cs @@ -35,6 +35,8 @@ using MonoDevelop.Components.Commands; using MonoDevelop.Ide.Gui; using MonoDevelop.Ide.Gui.Components; using MonoDevelop.Ide; +using MonoDevelop.Projects; +using System.Collections.Generic; namespace CBinding.ProjectPad { @@ -132,7 +134,7 @@ namespace CBinding.ProjectPad MessageService.ShowCustomDialog (new EditPackagesDialog (project)); - IdeApp.ProjectOperations.Save (project); + IdeApp.ProjectOperations.SaveAsync (project); CurrentNode.Expanded = true; } @@ -164,6 +166,7 @@ namespace CBinding.ProjectPad public override void OnNodeDrop (object dataObject, DragOperation operation) { + List<IWorkspaceFileObject> toSave = new List<IWorkspaceFileObject> (); if (dataObject is Package) { Package package = (Package)dataObject; ITreeNavigator nav = CurrentNode; @@ -173,11 +176,11 @@ namespace CBinding.ProjectPad CProject source = nav.GetParentDataItem (typeof(CProject), true) as CProject; dest.Packages.Add (package); - IdeApp.ProjectOperations.Save (dest); - + toSave.Add (dest); + if (operation == DragOperation.Move) { source.Packages.Remove (package); - IdeApp.ProjectOperations.Save (source); + toSave.Add (source); } } else if (dataObject is CProject) { CProject draggedProject = (CProject)dataObject; @@ -189,9 +192,10 @@ namespace CBinding.ProjectPad if (!destProject.Packages.Contains (package)) { destProject.Packages.Add (package); - IdeApp.ProjectOperations.Save (destProject); + toSave.Add (destProject); } } + IdeApp.ProjectOperations.SaveAsync (toSave); } } } |