diff options
Diffstat (limited to 'main/src/addins/CBinding/Project')
-rw-r--r-- | main/src/addins/CBinding/Project/CProject.cs | 55 | ||||
-rw-r--r-- | main/src/addins/CBinding/Project/CProjectBinding.cs | 85 | ||||
-rw-r--r-- | main/src/addins/CBinding/Project/CProjectServiceExtension.cs | 70 |
3 files changed, 35 insertions, 175 deletions
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); - } - } -} |