From 3436961bb5c01d659d09be134368f4f69460cef9 Mon Sep 17 00:00:00 2001
From: MW
Date: Sat, 26 May 2007 13:40:19 +0000
Subject: Start of rewrite 5279!
---
Prebuild/src/Core/Targets/VS2003Target.cs | 633 ++++++++++++++++++++++++++++++
1 file changed, 633 insertions(+)
create mode 100644 Prebuild/src/Core/Targets/VS2003Target.cs
(limited to 'Prebuild/src/Core/Targets/VS2003Target.cs')
diff --git a/Prebuild/src/Core/Targets/VS2003Target.cs b/Prebuild/src/Core/Targets/VS2003Target.cs
new file mode 100644
index 0000000..b3236a8
--- /dev/null
+++ b/Prebuild/src/Core/Targets/VS2003Target.cs
@@ -0,0 +1,633 @@
+#region BSD License
+/*
+Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com)
+
+Redistribution and use in source and binary forms, with or without modification, are permitted
+provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this list of conditions
+ and the following disclaimer.
+* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ and the following disclaimer in the documentation and/or other materials provided with the
+ distribution.
+* The name of the author may not be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+#endregion
+
+#region CVS Information
+/*
+ * $Source$
+ * $Author: jendave $
+ * $Date: 2006-09-29 21:11:40 +0200 (fr, 29 sep 2006) $
+ * $Revision: 177 $
+ */
+#endregion
+
+using System;
+using System.Collections;
+using System.Collections.Specialized;
+using System.IO;
+
+using Prebuild.Core.Attributes;
+using Prebuild.Core.Interfaces;
+using Prebuild.Core.Nodes;
+using Prebuild.Core.Utilities;
+
+namespace Prebuild.Core.Targets
+{
+ ///
+ ///
+ ///
+ public enum VSVersion
+ {
+ ///
+ ///
+ ///
+ VS70,
+ ///
+ ///
+ ///
+ VS71,
+ ///
+ ///
+ ///
+ VS80
+ }
+
+ ///
+ ///
+ ///
+ [Target("vs2003")]
+ public class VS2003Target : ITarget
+ {
+
+ #region Fields
+
+ string solutionVersion = "8.00";
+ string productVersion = "7.10.3077";
+ string schemaVersion = "2.0";
+ string versionName = "2003";
+ VSVersion version = VSVersion.VS71;
+
+ Hashtable m_Tools;
+ Kernel m_Kernel;
+
+ ///
+ /// Gets or sets the solution version.
+ ///
+ /// The solution version.
+ protected string SolutionVersion
+ {
+ get
+ {
+ return this.solutionVersion;
+ }
+ set
+ {
+ this.solutionVersion = value;
+ }
+ }
+ ///
+ /// Gets or sets the product version.
+ ///
+ /// The product version.
+ protected string ProductVersion
+ {
+ get
+ {
+ return this.productVersion;
+ }
+ set
+ {
+ this.productVersion = value;
+ }
+ }
+ ///
+ /// Gets or sets the schema version.
+ ///
+ /// The schema version.
+ protected string SchemaVersion
+ {
+ get
+ {
+ return this.schemaVersion;
+ }
+ set
+ {
+ this.schemaVersion = value;
+ }
+ }
+ ///
+ /// Gets or sets the name of the version.
+ ///
+ /// The name of the version.
+ protected string VersionName
+ {
+ get
+ {
+ return this.versionName;
+ }
+ set
+ {
+ this.versionName = value;
+ }
+ }
+ ///
+ /// Gets or sets the version.
+ ///
+ /// The version.
+ protected VSVersion Version
+ {
+ get
+ {
+ return this.version;
+ }
+ set
+ {
+ this.version = value;
+ }
+ }
+
+ #endregion
+
+ #region Constructors
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public VS2003Target()
+ {
+ m_Tools = new Hashtable();
+
+ m_Tools["C#"] = new ToolInfo("C#", "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", "csproj", "CSHARP");
+ m_Tools["VB.NET"] = new ToolInfo("VB.NET", "{F184B08F-C81C-45F6-A57F-5ABD9991F28F}", "vbproj", "VisualBasic");
+ }
+
+ #endregion
+
+ #region Private Methods
+
+ private string MakeRefPath(ProjectNode project)
+ {
+ string ret = "";
+ foreach(ReferencePathNode node in project.ReferencePaths)
+ {
+ try
+ {
+ string fullPath = Helper.ResolvePath(node.Path);
+ if(ret.Length < 1)
+ {
+ ret = fullPath;
+ }
+ else
+ {
+ ret += ";" + fullPath;
+ }
+ }
+ catch(ArgumentException)
+ {
+ m_Kernel.Log.Write(LogType.Warning, "Could not resolve reference path: {0}", node.Path);
+ }
+ }
+
+ return ret;
+ }
+
+ private void WriteProject(SolutionNode solution, ProjectNode project)
+ {
+ if(!m_Tools.ContainsKey(project.Language))
+ {
+ throw new UnknownLanguageException("Unknown .NET language: " + project.Language);
+ }
+
+ ToolInfo toolInfo = (ToolInfo)m_Tools[project.Language];
+ string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, toolInfo.FileExtension);
+ StreamWriter ps = new StreamWriter(projectFile);
+
+ m_Kernel.CurrentWorkingDirectory.Push();
+ Helper.SetCurrentDir(Path.GetDirectoryName(projectFile));
+
+ IEnumerator enumerator;
+ //ConfigurationNode scripts;
+
+ using(ps)
+ {
+ ps.WriteLine("");
+ ps.WriteLine(" <{0}", toolInfo.XmlTag);
+ ps.WriteLine("\t\t\t\tProjectType = \"Local\"");
+ ps.WriteLine("\t\t\t\tProductVersion = \"{0}\"", this.ProductVersion);
+ ps.WriteLine("\t\t\t\tSchemaVersion = \"{0}\"", this.SchemaVersion);
+ ps.WriteLine("\t\t\t\tProjectGuid = \"{{{0}}}\"", project.Guid.ToString().ToUpper());
+ ps.WriteLine("\t\t>");
+
+ ps.WriteLine("\t\t\t\t");
+ ps.WriteLine(" ");
+
+ foreach(ConfigurationNode conf in project.Configurations)
+ {
+ ps.WriteLine("\t\t\t\t ");
+ }
+
+ ps.WriteLine(" ");
+
+ ps.WriteLine(" ");
+ foreach(ReferenceNode refr in project.References)
+ {
+ ps.WriteLine(" ");
+ }
+ ps.WriteLine(" ");
+
+ ps.WriteLine(" ");
+ ps.WriteLine(" ");
+
+ ps.WriteLine(" ");
+
+ foreach(string file in project.Files)
+ {
+ string fileName = file.Replace(".\\", "");
+ ps.WriteLine(" ");
+
+ if (project.Files.GetSubType(file) != SubType.Code && project.Files.GetSubType(file) != SubType.Settings)
+ {
+ ps.WriteLine(" ");
+
+ }
+ }
+ ps.WriteLine(" ");
+
+ ps.WriteLine(" ");
+ ps.WriteLine(" {0}>", toolInfo.XmlTag);
+ ps.WriteLine("");
+ }
+
+ ps = new StreamWriter(projectFile + ".user");
+ using(ps)
+ {
+ ps.WriteLine("");
+ ps.WriteLine(" <{0}>", toolInfo.XmlTag);
+ ps.WriteLine(" ");
+
+ ps.WriteLine(" ", MakeRefPath(project));
+ foreach(ConfigurationNode conf in project.Configurations)
+ {
+ ps.WriteLine(" ");
+ }
+ ps.WriteLine(" ");
+
+ ps.WriteLine(" ");
+ ps.WriteLine(" {0}>", toolInfo.XmlTag);
+ ps.WriteLine("");
+ }
+
+ m_Kernel.CurrentWorkingDirectory.Pop();
+ }
+
+ ///
+ /// Gets the XML doc file.
+ ///
+ /// The project.
+ /// The conf.
+ ///
+ public static string GetXmlDocFile(ProjectNode project, ConfigurationNode conf)
+ {
+ if( conf == null )
+ {
+ throw new ArgumentNullException("conf");
+ }
+ if( project == null )
+ {
+ throw new ArgumentNullException("project");
+ }
+ // if(!(bool)conf.Options["GenerateXmlDocFile"]) //default to none, if the generate option is false
+ // {
+ // return string.Empty;
+ // }
+
+ //default to "AssemblyName.xml"
+ //string defaultValue = Path.GetFileNameWithoutExtension(project.AssemblyName) + ".xml";
+ //return (string)conf.Options["XmlDocFile", defaultValue];
+
+ //default to no XmlDocFile file
+ return (string)conf.Options["XmlDocFile", ""];
+ }
+
+ private void WriteSolution(SolutionNode solution)
+ {
+ m_Kernel.Log.Write("Creating Visual Studio {0} solution and project files", this.VersionName);
+
+ foreach(ProjectNode project in solution.Projects)
+ {
+ if(m_Kernel.AllowProject(project.FilterGroups))
+ {
+ m_Kernel.Log.Write("...Creating project: {0}", project.Name);
+ WriteProject(solution, project);
+ }
+ }
+
+ m_Kernel.Log.Write("");
+ string solutionFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "sln");
+ StreamWriter ss = new StreamWriter(solutionFile);
+
+ m_Kernel.CurrentWorkingDirectory.Push();
+ Helper.SetCurrentDir(Path.GetDirectoryName(solutionFile));
+
+ using(ss)
+ {
+ ss.WriteLine("Microsoft Visual Studio Solution File, Format Version {0}", this.SolutionVersion);
+ foreach(ProjectNode project in solution.Projects)
+ {
+ if(!m_Tools.ContainsKey(project.Language))
+ {
+ throw new UnknownLanguageException("Unknown .NET language: " + project.Language);
+ }
+
+ ToolInfo toolInfo = (ToolInfo)m_Tools[project.Language];
+
+ string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath);
+ ss.WriteLine("Project(\"{0}\") = \"{1}\", \"{2}\", \"{{{3}}}\"",
+ toolInfo.Guid, project.Name, Helper.MakeFilePath(path, project.Name,
+ toolInfo.FileExtension), project.Guid.ToString().ToUpper());
+
+ ss.WriteLine("\tProjectSection(ProjectDependencies) = postProject");
+ ss.WriteLine("\tEndProjectSection");
+
+ ss.WriteLine("EndProject");
+ }
+
+ ss.WriteLine("Global");
+
+ ss.WriteLine("\tGlobalSection(SolutionConfiguration) = preSolution");
+ foreach(ConfigurationNode conf in solution.Configurations)
+ {
+ ss.WriteLine("\t\t{0} = {0}", conf.Name);
+ }
+ ss.WriteLine("\tEndGlobalSection");
+
+ ss.WriteLine("\tGlobalSection(ProjectDependencies) = postSolution");
+ foreach(ProjectNode project in solution.Projects)
+ {
+ for(int i = 0; i < project.References.Count; i++)
+ {
+ ReferenceNode refr = (ReferenceNode)project.References[i];
+ if(solution.ProjectsTable.ContainsKey(refr.Name))
+ {
+ ProjectNode refProject = (ProjectNode)solution.ProjectsTable[refr.Name];
+ ss.WriteLine("\t\t({{{0}}}).{1} = ({{{2}}})",
+ project.Guid.ToString().ToUpper()
+ , i,
+ refProject.Guid.ToString().ToUpper()
+ );
+ }
+ }
+ }
+ ss.WriteLine("\tEndGlobalSection");
+
+ ss.WriteLine("\tGlobalSection(ProjectConfiguration) = postSolution");
+ foreach(ProjectNode project in solution.Projects)
+ {
+ foreach(ConfigurationNode conf in solution.Configurations)
+ {
+ ss.WriteLine("\t\t{{{0}}}.{1}.ActiveCfg = {1}|.NET",
+ project.Guid.ToString().ToUpper(),
+ conf.Name);
+
+ ss.WriteLine("\t\t{{{0}}}.{1}.Build.0 = {1}|.NET",
+ project.Guid.ToString().ToUpper(),
+ conf.Name);
+ }
+ }
+ ss.WriteLine("\tEndGlobalSection");
+
+ if(solution.Files != null)
+ {
+ ss.WriteLine("\tGlobalSection(SolutionItems) = postSolution");
+ foreach(string file in solution.Files)
+ {
+ ss.WriteLine("\t\t{0} = {0}", file);
+ }
+ ss.WriteLine("\tEndGlobalSection");
+ }
+
+ ss.WriteLine("\tGlobalSection(ExtensibilityGlobals) = postSolution");
+ ss.WriteLine("\tEndGlobalSection");
+ ss.WriteLine("\tGlobalSection(ExtensibilityAddIns) = postSolution");
+ ss.WriteLine("\tEndGlobalSection");
+
+ ss.WriteLine("EndGlobal");
+ }
+
+ m_Kernel.CurrentWorkingDirectory.Pop();
+ }
+
+ private void CleanProject(ProjectNode project)
+ {
+ m_Kernel.Log.Write("...Cleaning project: {0}", project.Name);
+
+ ToolInfo toolInfo = (ToolInfo)m_Tools[project.Language];
+ string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, toolInfo.FileExtension);
+ string userFile = projectFile + ".user";
+
+ Helper.DeleteIfExists(projectFile);
+ Helper.DeleteIfExists(userFile);
+ }
+
+ private void CleanSolution(SolutionNode solution)
+ {
+ m_Kernel.Log.Write("Cleaning Visual Studio {0} solution and project files", this.VersionName, solution.Name);
+
+ string slnFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "sln");
+ string suoFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "suo");
+
+ Helper.DeleteIfExists(slnFile);
+ Helper.DeleteIfExists(suoFile);
+
+ foreach(ProjectNode project in solution.Projects)
+ {
+ CleanProject(project);
+ }
+
+ m_Kernel.Log.Write("");
+ }
+
+ #endregion
+
+ #region ITarget Members
+
+ ///
+ /// Writes the specified kern.
+ ///
+ /// The kern.
+ public virtual void Write(Kernel kern)
+ {
+ if( kern == null )
+ {
+ throw new ArgumentNullException("kern");
+ }
+ m_Kernel = kern;
+ foreach(SolutionNode sol in m_Kernel.Solutions)
+ {
+ WriteSolution(sol);
+ }
+ m_Kernel = null;
+ }
+
+ ///
+ /// Cleans the specified kern.
+ ///
+ /// The kern.
+ public virtual void Clean(Kernel kern)
+ {
+ if( kern == null )
+ {
+ throw new ArgumentNullException("kern");
+ }
+ m_Kernel = kern;
+ foreach(SolutionNode sol in m_Kernel.Solutions)
+ {
+ CleanSolution(sol);
+ }
+ m_Kernel = null;
+ }
+
+ ///
+ /// Gets the name.
+ ///
+ /// The name.
+ public virtual string Name
+ {
+ get
+ {
+ return "vs2003";
+ }
+ }
+
+ #endregion
+ }
+}
--
cgit v1.1