From b7cab5f225378b6a1197c11e4da57ff9ef1b8867 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Thu, 10 Jul 2008 19:46:22 +0000 Subject: [PATCH] Support building C++ projects using Windows SDK 6.1. Solution.GetActiveConfigurationsAndPlatformsForProjects: Use .ActiveCfg entry instead of .Build.0 entry. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3214 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- samples/CppBackendBinding/CppProject.cs | 53 +++++++++++++------ .../Project/Src/Project/Solution/Solution.cs | 40 ++++++-------- 2 files changed, 52 insertions(+), 41 deletions(-) diff --git a/samples/CppBackendBinding/CppProject.cs b/samples/CppBackendBinding/CppProject.cs index a7758de691..26ad202188 100644 --- a/samples/CppBackendBinding/CppProject.cs +++ b/samples/CppBackendBinding/CppProject.cs @@ -5,6 +5,7 @@ // $Revision$ // +using Microsoft.Win32; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -14,7 +15,6 @@ using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Xml; - using ICSharpCode.Core; using ICSharpCode.SharpDevelop.Project; @@ -166,22 +166,41 @@ namespace CppBackendBinding } #endregion - public override void StartBuild(ProjectBuildOptions options, IBuildFeedbackSink feedbackSink) + static string GetFile(string filename) { - string commonTools = Environment.GetEnvironmentVariable("VS90COMNTOOLS"); - if (string.IsNullOrEmpty(commonTools)) { - commonTools = Environment.GetEnvironmentVariable("VS80COMNTOOLS"); - } - if (!string.IsNullOrEmpty(commonTools)) { - commonTools = Path.Combine(commonTools, "vsvars32.bat"); - if (!File.Exists(commonTools)) - commonTools = null; + filename = Environment.ExpandEnvironmentVariables(filename); + if (File.Exists(filename)) + return filename; + else + return null; + } + + static string GetPathFromRegistry(string key, string valueName) + { + using (RegistryKey installRootKey = Registry.LocalMachine.OpenSubKey(key)) { + if (installRootKey != null) { + object o = installRootKey.GetValue(valueName); + if (o != null) { + string r = o.ToString(); + if (!string.IsNullOrEmpty(r)) + return r; + } + } } + return null; + } + + public override void StartBuild(ProjectBuildOptions options, IBuildFeedbackSink feedbackSink) + { + string commonTools = + GetFile(Path.Combine(GetPathFromRegistry(@"SOFTWARE\Microsoft\VisualStudio\9.0\Setup\VC", "ProductDir"), "bin\\vcvars32.bat")) + ?? GetFile("%VS90COMNTOOLS%\\vsvars32.bat") + ?? GetFile("%VS80COMNTOOLS%\\vsvars32.bat"); Process p = new Process(); p.StartInfo.FileName = "cmd.exe"; p.StartInfo.Arguments = "/C"; - if (commonTools != null) { + if (!string.IsNullOrEmpty(commonTools)) { p.StartInfo.Arguments += " call \"" + commonTools + "\" &&"; } p.StartInfo.Arguments += " vcbuild"; @@ -210,8 +229,8 @@ namespace CppBackendBinding BuildError error = ParseError(e.Data); if (error != null) feedbackSink.ReportError(error); - else - feedbackSink.ReportMessage(e.Data); +// else + feedbackSink.ReportMessage(e.Data); } }; p.ErrorDataReceived += delegate(object sender, DataReceivedEventArgs e) { @@ -219,8 +238,8 @@ namespace CppBackendBinding BuildError error = ParseError(e.Data); if (error != null) feedbackSink.ReportError(error); - else - feedbackSink.ReportError(new BuildError(null, e.Data)); +// else + feedbackSink.ReportError(new BuildError(null, e.Data)); } }; p.Exited += delegate(object sender, EventArgs e) { @@ -238,7 +257,7 @@ namespace CppBackendBinding } static readonly Regex errorRegex = new Regex(@"^Error: " + - @"([^(:]+?)" + // group 1: file name + @"((?:[^(:]|:\\)+)" + // group 1: file name @"(?:\((\d+)\))?" + // group 2: line number @"\s*:\s*" + // first separator @"(?:error ([^:]+):)?" + // group 3: error code @@ -247,7 +266,7 @@ namespace CppBackendBinding static readonly Regex warningRegex = new Regex(@"^(?:\d+\>)?Warning: " + - @"([^(:]+?)" + // group 1: file name + @"((?:[^(:]|:\\)+)" + // group 1: file name @"(?:\((\d+)\))?" + // group 2: line number @"\s*:\s*" + // first separator @"(?:warning ([^:]+):)?" + // group 3: error code diff --git a/src/Main/Base/Project/Src/Project/Solution/Solution.cs b/src/Main/Base/Project/Src/Project/Solution/Solution.cs index 08c4b45f50..751f6ac922 100644 --- a/src/Main/Base/Project/Src/Project/Solution/Solution.cs +++ b/src/Main/Base/Project/Src/Project/Solution/Solution.cs @@ -654,15 +654,7 @@ namespace ICSharpCode.SharpDevelop.Project foreach (IProject project in projects) { string guid = project.IdGuid.ToUpperInvariant(); foreach (SolutionItem configuration in solSec.Items) { - string searchKey = guid + "." + configuration.Name + ".Build.0"; - if (!prjSec.Items.Exists(delegate (SolutionItem item) { - return item.Name == searchKey; - })) - { - prjSec.Items.Add(new SolutionItem(searchKey, configuration.Location)); - changed = true; - } - searchKey = guid + "." + configuration.Name + ".ActiveCfg"; + string searchKey = guid + "." + configuration.Name + ".ActiveCfg"; if (!prjSec.Items.Exists(delegate (SolutionItem item) { return item.Name == searchKey; })) @@ -757,11 +749,11 @@ namespace ICSharpCode.SharpDevelop.Project if (this.SolutionItem == null) return; string oldName = this.SolutionItem.Name; - this.SolutionItem.Name = this.Project.IdGuid + "." + newConfiguration + "|" + newPlatform + ".Build.0"; + this.SolutionItem.Name = this.Project.IdGuid + "." + newConfiguration + "|" + newPlatform + ".ActiveCfg"; string newName = this.SolutionItem.Name; - if (StripBuild0(ref oldName) && StripBuild0(ref newName)) { - oldName += ".ActiveCfg"; - newName += ".ActiveCfg"; + if (StripActiveCfg(ref oldName) && StripActiveCfg(ref newName)) { + oldName += ".Build.0"; + newName += ".Build.0"; foreach (SolutionItem item in section.Items) { if (item.Name == oldName) item.Name = newName; @@ -777,8 +769,8 @@ namespace ICSharpCode.SharpDevelop.Project return; this.SolutionItem.Location = newConfiguration + "|" + newPlatform; string thisName = this.SolutionItem.Name; - if (StripBuild0(ref thisName)) { - thisName += ".ActiveCfg"; + if (StripActiveCfg(ref thisName)) { + thisName += ".Build.0"; foreach (SolutionItem item in section.Items) { if (item.Name == thisName) item.Location = this.SolutionItem.Location; @@ -786,10 +778,10 @@ namespace ICSharpCode.SharpDevelop.Project } } - internal static bool StripBuild0(ref string s) + internal static bool StripActiveCfg(ref string s) { - if (s.EndsWith(".Build.0")) { - s = s.Substring(0, s.Length - ".Build.0".Length); + if (s.EndsWith(".ActiveCfg")) { + s = s.Substring(0, s.Length - ".ActiveCfg".Length); return true; } else { return false; @@ -806,7 +798,7 @@ namespace ICSharpCode.SharpDevelop.Project foreach (SolutionItem item in prjSec.Items) { dict[item.Name] = item; } - string searchKeyPostFix = "." + solutionConfiguration + "|" + solutionPlatform + ".Build.0"; + string searchKeyPostFix = "." + solutionConfiguration + "|" + solutionPlatform + ".ActiveCfg"; foreach (IProject p in Projects) { string searchKey = p.IdGuid + searchKeyPostFix; SolutionItem solutionItem; @@ -828,11 +820,11 @@ namespace ICSharpCode.SharpDevelop.Project internal SolutionItem CreateMatchingItem(string solutionConfiguration, string solutionPlatform, IProject project, string initialLocation) { + GetProjectConfigurationsSection().Items.Add(new SolutionItem(project.IdGuid + "." + solutionConfiguration + "|" + + solutionPlatform + ".Build.0", initialLocation)); SolutionItem item = new SolutionItem(project.IdGuid + "." + solutionConfiguration + "|" - + solutionPlatform + ".Build.0", initialLocation); + + solutionPlatform + ".ActiveCfg", initialLocation); GetProjectConfigurationsSection().Items.Add(item); - GetProjectConfigurationsSection().Items.Add(new SolutionItem(project.IdGuid + "." + solutionConfiguration + "|" - + solutionPlatform + ".ActiveCfg", initialLocation)); return item; } #endregion @@ -997,14 +989,14 @@ namespace ICSharpCode.SharpDevelop.Project /// /// Gets the configuration|platform name from a conf item, e.g. /// "Release|Any CPU" from - /// "{7115F3A9-781C-4A95-90AE-B5AB53C4C588}.Release|Any CPU.Build.0" + /// "{7115F3A9-781C-4A95-90AE-B5AB53C4C588}.Release|Any CPU.ActiveCfg" /// static string GetKeyFromProjectConfItem(string name) { int pos = name.IndexOf('.'); if (pos < 0) return null; name = name.Substring(pos + 1); - if (!ProjectConfigurationPlatformMatching.StripBuild0(ref name)) { + if (!ProjectConfigurationPlatformMatching.StripActiveCfg(ref name)) { pos = name.LastIndexOf('.'); if (pos < 0) return null; name = name.Substring(0, pos);