Browse Source

Ported CppBackendBinding sample project to SD5.

pull/297/head
Andreas Weizel 12 years ago
parent
commit
6d3d971ba9
  1. 22
      samples/CppBackendBinding/CppBackendBinding.csproj
  2. 6
      samples/CppBackendBinding/CppBackendBinding.sln
  3. 177
      samples/CppBackendBinding/CppProject.cs
  4. 4
      samples/CppBackendBinding/CppProjectBinding.cs
  5. 4
      src/Automated.proj

22
samples/CppBackendBinding/CppBackendBinding.csproj

@ -7,12 +7,14 @@
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<RootNamespace>CppBackendBinding</RootNamespace> <RootNamespace>CppBackendBinding</RootNamespace>
<AssemblyName>CppBackendBinding</AssemblyName> <AssemblyName>CppBackendBinding</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<OutputPath>..\..\AddIns\Samples\CppBinding\</OutputPath> <OutputPath>..\..\AddIns\Samples\CppBinding\</OutputPath>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks> <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<NoStdLib>False</NoStdLib> <NoStdLib>False</NoStdLib>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> <TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<TargetFrameworkProfile />
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
@ -20,6 +22,7 @@
<Optimize>False</Optimize> <Optimize>False</Optimize>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> <CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugSymbols>False</DebugSymbols> <DebugSymbols>False</DebugSymbols>
@ -37,16 +40,20 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<ItemGroup> <ItemGroup>
<Reference Include="ICSharpCode.AvalonEdit">
<HintPath>..\..\bin\ICSharpCode.AvalonEdit.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="ICSharpCode.Core"> <Reference Include="ICSharpCode.Core">
<HintPath>..\..\bin\ICSharpCode.Core.dll</HintPath> <HintPath>..\..\bin\ICSharpCode.Core.dll</HintPath>
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="ICSharpCode.SharpDevelop"> <Reference Include="ICSharpCode.NRefactory">
<HintPath>..\..\bin\ICSharpCode.SharpDevelop.dll</HintPath> <HintPath>..\..\bin\ICSharpCode.NRefactory.dll</HintPath>
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="ICSharpCode.SharpDevelop.Dom"> <Reference Include="ICSharpCode.SharpDevelop">
<HintPath>..\..\bin\ICSharpCode.SharpDevelop.Dom.dll</HintPath> <HintPath>..\..\bin\ICSharpCode.SharpDevelop.dll</HintPath>
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
@ -56,6 +63,9 @@
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="CppBackendBinding.addin"> <None Include="CppBackendBinding.addin">

6
samples/CppBackendBinding/CppBackendBinding.sln

@ -1,7 +1,7 @@
 
Microsoft Visual Studio Solution File, Format Version 11.00 Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010 # Visual Studio 2010
# SharpDevelop 4.0.0.5571 # SharpDevelop 5.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CppBackendBinding", "CppBackendBinding.csproj", "{F279DD27-21A9-4D69-AAE3-00DB403257CB}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CppBackendBinding", "CppBackendBinding.csproj", "{F279DD27-21A9-4D69-AAE3-00DB403257CB}"
EndProject EndProject
Global Global
@ -10,9 +10,9 @@ Global
Release|Any CPU = Release|Any CPU Release|Any CPU = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F279DD27-21A9-4D69-AAE3-00DB403257CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F279DD27-21A9-4D69-AAE3-00DB403257CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {F279DD27-21A9-4D69-AAE3-00DB403257CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F279DD27-21A9-4D69-AAE3-00DB403257CB}.Release|Any CPU.Build.0 = Release|Any CPU {F279DD27-21A9-4D69-AAE3-00DB403257CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F279DD27-21A9-4D69-AAE3-00DB403257CB}.Release|Any CPU.ActiveCfg = Release|Any CPU {F279DD27-21A9-4D69-AAE3-00DB403257CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F279DD27-21A9-4D69-AAE3-00DB403257CB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

177
samples/CppBackendBinding/CppProject.cs

@ -13,10 +13,13 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml; using System.Xml;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
using Microsoft.Win32; using Microsoft.Win32;
@ -25,20 +28,92 @@ namespace CppBackendBinding
/// <summary> /// <summary>
/// C++ project class. Handlings project loading and saving. /// C++ project class. Handlings project loading and saving.
/// </summary> /// </summary>
public class CppProject : AbstractProject, IProjectItemListProvider, IProjectAllowChangeConfigurations public class CppProject : AbstractProject, IProject
{ {
sealed class ReadOnlyConfigurationOrPlatformNameCollection : ImmutableModelCollection<string>, IConfigurationOrPlatformNameCollection
{
public ReadOnlyConfigurationOrPlatformNameCollection(IEnumerable<string> items)
: base(items)
{
}
public string ValidateName(string name)
{
return Contains(name) ? name : null;
}
public void Add(string newName, string copyFrom)
{
throw new NotSupportedException();
}
public void Remove(string name)
{
throw new NotSupportedException();
}
public void Rename(string oldName, string newName)
{
throw new NotSupportedException();
}
}
class CppProjectItemsCollection : SimpleModelCollection<ProjectItem>
{
readonly CppProject project;
readonly bool internalUpdating;
public CppProjectItemsCollection(CppProject project)
{
internalUpdating = true;
this.project = project;
this.AddRange(this.project.items.Select(item => item.ProjectItem));
internalUpdating = false;
}
protected override void OnAdd(ProjectItem item)
{
base.OnAdd(item);
lock (project.SyncRoot) {
if (!internalUpdating) {
if (project.items.Exists(fi => fi.ProjectItem == item))
throw new ArgumentException("Project item already exists in project!");
project.items.Add(new FileItem(project.document, item));
}
}
}
protected override void OnRemove(ProjectItem item)
{
base.OnRemove(item);
lock (project.SyncRoot) {
if (!internalUpdating) {
var removedFileItems = new List<FileItem>(project.items.Where(fi => fi.ProjectItem == item));
foreach (var fileItem in removedFileItems) {
if (fileItem.XmlElement.ParentNode != null)
fileItem.XmlElement.ParentNode.RemoveChild(fileItem.XmlElement);
project.items.Remove(fileItem);
}
}
}
}
}
XmlDocument document = new XmlDocument(); XmlDocument document = new XmlDocument();
List<FileGroup> groups = new List<FileGroup>(); List<FileGroup> groups = new List<FileGroup>();
List<FileItem> items = new List<FileItem>(); List<FileItem> items = new List<FileItem>();
CppProjectItemsCollection projectItems;
/// <summary> /// <summary>
/// Create a new C++ project that loads the specified .vcproj file. /// Create a new C++ project that loads the specified .vcproj file.
/// </summary> /// </summary>
public CppProject(ProjectLoadInformation info) public CppProject(ProjectLoadInformation info)
: base(info)
{ {
this.Name = info.ProjectName; this.Name = info.ProjectName;
this.FileName = info.FileName; this.FileName = info.FileName;
this.TypeGuid = "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}";
using (StreamReader r = new StreamReader(info.FileName, Encoding.Default)) { using (StreamReader r = new StreamReader(info.FileName, Encoding.Default)) {
try { try {
@ -63,6 +138,8 @@ namespace CppBackendBinding
} }
} }
} }
this.projectItems = new CppProjectItemsCollection(this);
} }
public override string Language { public override string Language {
@ -87,6 +164,8 @@ namespace CppBackendBinding
LoggingService.Warn("Couldn't find filter for item type " + item.ProjectItem.ItemType + ", the item was not saved!"); LoggingService.Warn("Couldn't find filter for item type " + item.ProjectItem.ItemType + ", the item was not saved!");
} }
} }
watcher.Disable();
using (XmlWriter writer = XmlWriter.Create(fileName, new XmlWriterSettings { using (XmlWriter writer = XmlWriter.Create(fileName, new XmlWriterSettings {
NewLineOnAttributes = true, NewLineOnAttributes = true,
Indent = true, Indent = true,
@ -96,13 +175,14 @@ namespace CppBackendBinding
{ {
document.Save(writer); document.Save(writer);
} }
watcher.Enable();
} }
} }
/// <summary> /// <summary>
/// Gets the list of available file item types. This member is thread-safe. /// Gets the list of available file item types. This member is thread-safe.
/// </summary> /// </summary>
public override ICollection<ItemType> AvailableFileItemTypes { public override IReadOnlyCollection<ItemType> AvailableFileItemTypes {
get { get {
lock (SyncRoot) { lock (SyncRoot) {
return groups.ConvertAll(fg => fg.ItemType).AsReadOnly(); return groups.ConvertAll(fg => fg.ItemType).AsReadOnly();
@ -112,13 +192,11 @@ namespace CppBackendBinding
/// <summary> /// <summary>
/// Gets the list of items in the project. This member is thread-safe. /// Gets the list of items in the project. This member is thread-safe.
/// The returned collection is guaranteed not to change - adding new items or removing existing items
/// will create a new collection.
/// </summary> /// </summary>
public override ReadOnlyCollection<ProjectItem> Items { public override IMutableModelCollection<ProjectItem> Items {
get { get {
lock (SyncRoot) { lock (SyncRoot) {
return new ReadOnlyCollection<ProjectItem>(items.ConvertAll(fi => fi.ProjectItem)); return projectItems;
} }
} }
} }
@ -134,59 +212,6 @@ namespace CppBackendBinding
return base.GetDefaultItemType(fileName); return base.GetDefaultItemType(fileName);
} }
#region IProjectAllowChangeConfigurations
// TODO: Configuration/Platform handling
bool IProjectAllowChangeConfigurations.RenameProjectConfiguration(string oldName, string newName)
{
throw new NotImplementedException();
}
bool IProjectAllowChangeConfigurations.RenameProjectPlatform(string oldName, string newName)
{
throw new NotImplementedException();
}
bool IProjectAllowChangeConfigurations.AddProjectConfiguration(string newName, string copyFrom)
{
throw new NotImplementedException();
}
bool IProjectAllowChangeConfigurations.AddProjectPlatform(string newName, string copyFrom)
{
throw new NotImplementedException();
}
bool IProjectAllowChangeConfigurations.RemoveProjectConfiguration(string name)
{
throw new NotImplementedException();
}
bool IProjectAllowChangeConfigurations.RemoveProjectPlatform(string name)
{
throw new NotImplementedException();
}
#endregion
#region IProjectItemListProvider
void IProjectItemListProvider.AddProjectItem(ProjectItem item)
{
if (item == null)
throw new ArgumentNullException("item");
lock (SyncRoot) {
if (items.Exists(fi => fi.ProjectItem == item))
throw new ArgumentException("Project item already exists in project!");
items.Add(new FileItem(document, item));
}
}
bool IProjectItemListProvider.RemoveProjectItem(ProjectItem item)
{
lock (SyncRoot) {
return items.RemoveAll(fi => fi.ProjectItem == item) > 0;
}
}
#endregion
static string GetFile(string filename) static string GetFile(string filename)
{ {
if (string.IsNullOrEmpty(filename)) if (string.IsNullOrEmpty(filename))
@ -213,13 +238,20 @@ namespace CppBackendBinding
return null; return null;
} }
public override void StartBuild(ProjectBuildOptions options, IBuildFeedbackSink feedbackSink) public override Task<bool> BuildAsync(ProjectBuildOptions options, IBuildFeedbackSink feedbackSink, IProgressMonitor progressMonitor)
{
TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
StartBuild(tcs, options, feedbackSink, progressMonitor);
return tcs.Task;
}
void StartBuild(TaskCompletionSource<bool> tcs, ProjectBuildOptions options, IBuildFeedbackSink feedbackSink, IProgressMonitor progressMonitor)
{ {
string productDir = GetPathFromRegistry(@"SOFTWARE\Microsoft\VisualStudio\9.0\Setup\VC", "ProductDir"); string productDir = GetPathFromRegistry(@"SOFTWARE\Microsoft\VisualStudio\9.0\Setup\VC", "ProductDir");
string batFile = "vcvars32.bat"; string batFile = "vcvars32.bat";
if (options.Platform == "x64") { if (options.Platform == "x64") {
batFile = "vcvars64.bat"; batFile = "amd64\\vcvars64.bat";
} }
string commonTools = string commonTools =
@ -255,13 +287,16 @@ namespace CppBackendBinding
p.StartInfo.EnvironmentVariables["SolutionPath"] = ParentSolution.FileName; p.StartInfo.EnvironmentVariables["SolutionPath"] = ParentSolution.FileName;
p.EnableRaisingEvents = true; p.EnableRaisingEvents = true;
bool buildErrors = false;
p.OutputDataReceived += delegate(object sender, DataReceivedEventArgs e) { p.OutputDataReceived += delegate(object sender, DataReceivedEventArgs e) {
if (!string.IsNullOrEmpty(e.Data)) { if (!string.IsNullOrEmpty(e.Data)) {
BuildError error = ParseError(e.Data); BuildError error = ParseError(e.Data);
if (error != null) if (error != null) {
feedbackSink.ReportError(error); feedbackSink.ReportError(error);
else buildErrors = true;
feedbackSink.ReportMessage(e.Data); } else {
feedbackSink.ReportMessage(new RichText(e.Data));
}
} }
}; };
p.ErrorDataReceived += delegate(object sender, DataReceivedEventArgs e) { p.ErrorDataReceived += delegate(object sender, DataReceivedEventArgs e) {
@ -271,17 +306,19 @@ namespace CppBackendBinding
feedbackSink.ReportError(error); feedbackSink.ReportError(error);
else else
feedbackSink.ReportError(new BuildError(null, e.Data)); feedbackSink.ReportError(new BuildError(null, e.Data));
buildErrors = true;
} }
}; };
p.Exited += delegate(object sender, EventArgs e) { p.Exited += delegate(object sender, EventArgs e) {
p.CancelErrorRead(); p.CancelErrorRead();
p.CancelOutputRead(); p.CancelOutputRead();
feedbackSink.Done(p.ExitCode == 0); progressMonitor.Progress = 1;
p.Dispose(); p.Dispose();
tcs.SetResult(buildErrors);
}; };
feedbackSink.ReportMessage("Building " + this.Name); feedbackSink.ReportMessage(new RichText("Building " + this.Name));
feedbackSink.ReportMessage(p.StartInfo.FileName + " " + p.StartInfo.Arguments); feedbackSink.ReportMessage(new RichText(p.StartInfo.FileName + " " + p.StartInfo.Arguments));
p.Start(); p.Start();
p.BeginOutputReadLine(); p.BeginOutputReadLine();
p.BeginErrorReadLine(); p.BeginErrorReadLine();
@ -334,13 +371,13 @@ namespace CppBackendBinding
} }
} }
public override ICollection<string> PlatformNames { public override IConfigurationOrPlatformNameCollection PlatformNames {
get { get {
List<string> l = new List<string>(); List<string> l = new List<string>();
foreach (XmlElement platformElement in document.DocumentElement["Platforms"]) { foreach (XmlElement platformElement in document.DocumentElement["Platforms"]) {
l.Add(platformElement.GetAttribute("Name")); l.Add(platformElement.GetAttribute("Name"));
} }
return l.AsReadOnly(); return new ReadOnlyConfigurationOrPlatformNameCollection(l);
} }
} }
} }

4
samples/CppBackendBinding/CppProjectBinding.cs

@ -6,10 +6,6 @@
// </file> // </file>
using System; using System;
using System.IO;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Internal.Templates;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
namespace CppBackendBinding namespace CppBackendBinding

4
src/Automated.proj

@ -94,9 +94,9 @@
<MSBuild Projects="$(SamplesSrc)\ComponentInspector\ComponentInspector.sln" <MSBuild Projects="$(SamplesSrc)\ComponentInspector\ComponentInspector.sln"
Targets="build;clean" Targets="build;clean"
Properties="Configuration=Release;BranchName=$(BranchName)"/> Properties="Configuration=Release;BranchName=$(BranchName)"/>
<!-- <MSBuild Projects="$(SamplesSrc)\CppBackendBinding\CppBackendBinding.sln" <MSBuild Projects="$(SamplesSrc)\CppBackendBinding\CppBackendBinding.sln"
Targets="build;clean" Targets="build;clean"
Properties="Configuration=Release;BranchName=$(BranchName)"/>--> Properties="Configuration=Release;BranchName=$(BranchName)"/>
<MSBuild Projects="$(SamplesSrc)\CustomPad\CustomPad.sln" <MSBuild Projects="$(SamplesSrc)\CustomPad\CustomPad.sln"
Targets="build;clean" Targets="build;clean"
Properties="Configuration=Release;BranchName=$(BranchName)"/> Properties="Configuration=Release;BranchName=$(BranchName)"/>

Loading…
Cancel
Save