2007-07-16 15:40:11 +00:00
#region BSD License
/ *
2008-03-17 20:55:21 +00:00
Copyright ( c ) 2004 - 2008
Matthew Holmes ( matthew @wildfiregames . com ) ,
Dan Moorehead ( dan05a @gmail . com ) ,
C . J . Adams - Collier ( cjac @colliertech . org ) ,
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 .
2007-07-16 15:40:11 +00:00
* /
2008-03-17 20:55:21 +00:00
2007-07-16 15:40:11 +00:00
# endregion
#region CVS Information
/ *
* $ Source $
2008-03-17 20:55:21 +00:00
* $ Author : cjcollier $
* $ Date : 2008 - 02 - 07 10 : 22 : 36 + 0900 ( Thu , 07 Feb 2008 ) $
* $ Revision : 255 $
2007-07-16 15:40:11 +00:00
* /
# endregion
using System ;
using System.Collections ;
using System.Collections.Specialized ;
using System.IO ;
using System.Reflection ;
using System.Text.RegularExpressions ;
using Prebuild.Core.Attributes ;
using Prebuild.Core.Interfaces ;
using Prebuild.Core.Nodes ;
using Prebuild.Core.Utilities ;
namespace Prebuild.Core.Targets
{
2007-09-15 10:17:24 +00:00
/// <summary>
2007-11-05 15:10:20 +00:00
///
/// </summary>
[Target("nant")]
public class NAntTarget : ITarget
2007-09-15 10:17:24 +00:00
{
2007-11-05 15:10:20 +00:00
#region Fields
private Kernel m_Kernel ;
# endregion
#region Private Methods
private static string PrependPath ( string path )
{
string tmpPath = Helper . NormalizePath ( path , '/' ) ;
Regex regex = new Regex ( @"(\w):/(\w+)" ) ;
Match match = regex . Match ( tmpPath ) ;
//if(match.Success || tmpPath[0] == '.' || tmpPath[0] == '/')
//{
tmpPath = Helper . NormalizePath ( tmpPath ) ;
//}
// else
// {
// tmpPath = Helper.NormalizePath("./" + tmpPath);
// }
return tmpPath ;
}
private static string BuildReference ( SolutionNode solution , ProjectNode currentProject , ReferenceNode refr )
{
string ret = "" ;
2009-01-13 10:06:53 +00:00
string referencePath = ( ( ReferencePathNode ) currentProject . ReferencePaths [ 0 ] ) . Path ;
2009-02-17 16:15:29 +00:00
if ( String . IsNullOrEmpty ( refr . Path ) )
2007-09-15 10:17:24 +00:00
{
2009-02-17 16:15:29 +00:00
if ( solution . ProjectsTable . ContainsKey ( refr . Name ) )
2009-01-13 10:06:53 +00:00
{
2009-02-17 16:15:29 +00:00
ProjectNode project = ( ProjectNode ) solution . ProjectsTable [ refr . Name ] ;
string finalPath =
Helper . NormalizePath ( referencePath + refr . Name + GetProjectExtension ( project ) , '/' ) ;
return finalPath ;
2009-01-13 10:06:53 +00:00
}
2009-02-17 16:15:29 +00:00
else
{
ProjectNode project = ( ProjectNode ) refr . Parent ;
2009-01-13 10:06:53 +00:00
2009-02-17 16:15:29 +00:00
// Do we have an explicit file reference?
string fileRef = FindFileReference ( refr . Name , project ) ;
if ( fileRef ! = null )
{
return fileRef ;
}
2009-01-13 10:06:53 +00:00
2009-02-17 16:15:29 +00:00
// Is there an explicit path in the project ref?
if ( refr . Path ! = null )
{
return Helper . NormalizePath ( refr . Path + "/" + refr . Name + GetProjectExtension ( project ) , '/' ) ;
}
2007-09-15 10:17:24 +00:00
2009-02-17 16:15:29 +00:00
// Is it a specified extension (dll or exe?)
if ( ExtensionSpecified ( refr . Name ) )
{
return Helper . NormalizePath ( referencePath + GetRefFileName ( refr . Name ) , '/' ) ;
}
2009-01-13 10:06:53 +00:00
2009-02-17 16:15:29 +00:00
// No, it's an extensionless GAC ref, but nant needs the .dll extension anyway
return refr . Name + ".dll" ;
2007-11-05 15:10:20 +00:00
}
2009-02-17 16:15:29 +00:00
}
else
{
return refr . Path ;
2007-09-15 10:17:24 +00:00
}
2009-01-13 10:06:53 +00:00
}
public static string GetRefFileName ( string refName )
{
if ( ExtensionSpecified ( refName ) )
{
return refName ;
}
else
{
return refName + ".dll" ;
}
}
private static bool ExtensionSpecified ( string refName )
{
return refName . EndsWith ( ".dll" ) | | refName . EndsWith ( ".exe" ) ;
2007-11-05 15:10:20 +00:00
}
2007-09-15 10:17:24 +00:00
2007-11-05 15:10:20 +00:00
private static string GetProjectExtension ( ProjectNode project )
{
string extension = ".dll" ;
if ( project . Type = = ProjectType . Exe )
{
extension = ".exe" ;
}
return extension ;
}
2009-02-17 16:15:29 +00:00
//private static string BuildReferencePath(SolutionNode solution, ReferenceNode refr)
//{
// string ret = "";
// if (solution.ProjectsTable.ContainsKey(refr.Name))
// {
// ProjectNode project = (ProjectNode)solution.ProjectsTable[refr.Name];
// string finalPath = Helper.NormalizePath(((ReferencePathNode)project.ReferencePaths[0]).Path, '/');
// return finalPath;
// }
// else
// {
// if (refr.Path == null)
// {
// ProjectNode project = (ProjectNode) refr.Parent;
// string fileRef = FindFileReference(refr.Name, project);
// if (refr.Path != null || fileRef != null)
// {
// string finalPath = (refr.Path != null) ? Helper.NormalizePath(refr.Path, '/') : fileRef;
// ret += finalPath;
// return ret;
// }
// try
// {
// Assembly assem = Assembly.Load(refr.Name);
// if (assem != null)
// {
// ret += "";
// }
// else
// {
// ret += "";
// }
// }
// catch (System.NullReferenceException e)
// {
// e.ToString();
// ret += "";
// }
// }
// else
// {
// ret = refr.Path;
// }
// }
// return ret;
//}
2007-09-15 10:17:24 +00:00
2007-11-05 15:10:20 +00:00
private static string FindFileReference ( string refName , ProjectNode project )
{
foreach ( ReferencePathNode refPath in project . ReferencePaths )
2007-09-15 10:17:24 +00:00
{
string fullPath = Helper . MakeFilePath ( refPath . Path , refName , "dll" ) ;
2007-11-05 15:10:20 +00:00
if ( File . Exists ( fullPath ) )
{
return fullPath ;
}
2009-01-13 10:06:53 +00:00
fullPath = Helper . MakeFilePath ( refPath . Path , refName , "exe" ) ;
if ( File . Exists ( fullPath ) )
{
return fullPath ;
}
2007-09-15 10:17:24 +00:00
}
2007-11-05 15:10:20 +00:00
return null ;
}
/// <summary>
/// Gets the XML doc file.
/// </summary>
/// <param name="project">The project.</param>
/// <param name="conf">The conf.</param>
/// <returns></returns>
public static string GetXmlDocFile ( ProjectNode project , ConfigurationNode conf )
{
if ( conf = = null )
2007-09-15 10:17:24 +00:00
{
throw new ArgumentNullException ( "conf" ) ;
}
2007-11-05 15:10:20 +00:00
if ( project = = null )
2007-09-15 10:17:24 +00:00
{
throw new ArgumentNullException ( "project" ) ;
}
2007-11-05 15:10:20 +00:00
string docFile = ( string ) conf . Options [ "XmlDocFile" ] ;
// if(docFile != null && docFile.Length == 0)//default to assembly name if not specified
// {
// return Path.GetFileNameWithoutExtension(project.AssemblyName) + ".xml";
// }
return docFile ;
}
private void WriteProject ( SolutionNode solution , ProjectNode project )
{
string projFile = Helper . MakeFilePath ( project . FullPath , project . Name + GetProjectExtension ( project ) , "build" ) ;
StreamWriter ss = new StreamWriter ( projFile ) ;
m_Kernel . CurrentWorkingDirectory . Push ( ) ;
Helper . SetCurrentDir ( Path . GetDirectoryName ( projFile ) ) ;
bool hasDoc = false ;
using ( ss )
2007-09-15 10:17:24 +00:00
{
ss . WriteLine ( "<?xml version=\"1.0\" ?>" ) ;
ss . WriteLine ( "<project name=\"{0}\" default=\"build\">" , project . Name ) ;
ss . WriteLine ( " <target name=\"{0}\">" , "build" ) ;
ss . WriteLine ( " <echo message=\"Build Directory is ${project::get-base-directory()}/${build.dir}\" />" ) ;
2007-11-05 15:10:20 +00:00
ss . WriteLine ( " <mkdir dir=\"${project::get-base-directory()}/${build.dir}\" />" ) ;
2008-03-17 20:55:21 +00:00
ss . WriteLine ( " <copy todir=\"${project::get-base-directory()}/${build.dir}\" flatten=\"true\">" ) ;
2007-09-15 10:17:24 +00:00
ss . WriteLine ( " <fileset basedir=\"${project::get-base-directory()}\">" ) ;
2007-11-05 15:10:20 +00:00
foreach ( ReferenceNode refr in project . References )
{
if ( refr . LocalCopy )
2007-09-15 10:17:24 +00:00
{
2007-11-05 15:10:20 +00:00
ss . WriteLine ( " <include name=\"{0}" , Helper . NormalizePath ( Helper . MakePathRelativeTo ( project . FullPath , BuildReference ( solution , project , refr ) ) + "\" />" , '/' ) ) ;
2007-09-15 10:17:24 +00:00
}
2007-11-05 15:10:20 +00:00
}
2008-03-17 20:55:21 +00:00
2007-09-15 10:17:24 +00:00
ss . WriteLine ( " </fileset>" ) ;
ss . WriteLine ( " </copy>" ) ;
2008-03-17 20:55:21 +00:00
if ( project . ConfigFile ! = null & & project . ConfigFile . Length ! = 0 )
{
ss . Write ( " <copy file=\"" + project . ConfigFile + "\" tofile=\"${project::get-base-directory()}/${build.dir}/${project::get-name()}" ) ;
if ( project . Type = = ProjectType . Library )
{
ss . Write ( ".dll.config\"" ) ;
}
else
{
ss . Write ( ".exe.config\"" ) ;
}
ss . WriteLine ( " />" ) ;
}
// Add the content files to just be copied
ss . WriteLine ( " {0}" , "<copy todir=\"${project::get-base-directory()}/${build.dir}\">" ) ;
ss . WriteLine ( " {0}" , "<fileset basedir=\".\">" ) ;
foreach ( string file in project . Files )
{
// Ignore if we aren't content
if ( project . Files . GetBuildAction ( file ) ! = BuildAction . Content )
continue ;
// Create a include tag
ss . WriteLine ( " {0}" , "<include name=\"" + Helper . NormalizePath ( PrependPath ( file ) , '/' ) + "\" />" ) ;
}
ss . WriteLine ( " {0}" , "</fileset>" ) ;
ss . WriteLine ( " {0}" , "</copy>" ) ;
2007-09-15 10:17:24 +00:00
ss . Write ( " <csc" ) ;
ss . Write ( " target=\"{0}\"" , project . Type . ToString ( ) . ToLower ( ) ) ;
ss . Write ( " debug=\"{0}\"" , "${build.debug}" ) ;
2007-11-05 15:10:20 +00:00
foreach ( ConfigurationNode conf in project . Configurations )
{
if ( conf . Options . KeyFile ! = "" )
2007-09-15 10:17:24 +00:00
{
2007-11-05 15:10:20 +00:00
ss . Write ( " keyfile=\"{0}\"" , conf . Options . KeyFile ) ;
2007-09-15 10:17:24 +00:00
break ;
}
2007-11-05 15:10:20 +00:00
}
foreach ( ConfigurationNode conf in project . Configurations )
{
ss . Write ( " unsafe=\"{0}\"" , conf . Options . AllowUnsafe ) ;
break ;
}
foreach ( ConfigurationNode conf in project . Configurations )
2008-03-25 07:49:31 +00:00
{
ss . Write ( " warnaserror=\"{0}\"" , conf . Options . WarningsAsErrors ) ;
break ;
}
foreach ( ConfigurationNode conf in project . Configurations )
2007-11-05 15:10:20 +00:00
{
ss . Write ( " define=\"{0}\"" , conf . Options . CompilerDefines ) ;
break ;
}
2008-03-17 20:55:21 +00:00
ss . Write ( " main=\"{0}\"" , project . StartupObject ) ;
2007-11-05 15:10:20 +00:00
foreach ( ConfigurationNode conf in project . Configurations )
{
if ( GetXmlDocFile ( project , conf ) ! = "" )
2007-09-15 10:17:24 +00:00
{
2007-11-05 15:10:20 +00:00
ss . Write ( " doc=\"{0}\"" , "${project::get-base-directory()}/${build.dir}/" + GetXmlDocFile ( project , conf ) ) ;
hasDoc = true ;
2007-09-15 10:17:24 +00:00
}
2007-11-05 15:10:20 +00:00
break ;
}
2007-09-15 10:17:24 +00:00
ss . Write ( " output=\"{0}" , "${project::get-base-directory()}/${build.dir}/${project::get-name()}" ) ;
if ( project . Type = = ProjectType . Library )
2007-11-05 15:10:20 +00:00
{
ss . Write ( ".dll\"" ) ;
}
2007-09-15 10:17:24 +00:00
else
2007-11-05 15:10:20 +00:00
{
ss . Write ( ".exe\"" ) ;
}
if ( project . AppIcon ! = null & & project . AppIcon . Length ! = 0 )
{
ss . Write ( " win32icon=\"{0}\"" , Helper . NormalizePath ( project . AppIcon , '/' ) ) ;
}
2007-09-15 10:17:24 +00:00
ss . WriteLine ( ">" ) ;
2007-07-16 15:40:11 +00:00
ss . WriteLine ( " <resources prefix=\"{0}\" dynamicprefix=\"true\" >" , project . RootNamespace ) ;
foreach ( string file in project . Files )
2007-11-05 15:10:20 +00:00
{
switch ( project . Files . GetBuildAction ( file ) )
2007-07-16 15:40:11 +00:00
{
2007-11-05 15:10:20 +00:00
case BuildAction . EmbeddedResource :
ss . WriteLine ( " {0}" , "<include name=\"" + Helper . NormalizePath ( PrependPath ( file ) , '/' ) + "\" />" ) ;
break ;
default :
if ( project . Files . GetSubType ( file ) ! = SubType . Code & & project . Files . GetSubType ( file ) ! = SubType . Settings )
2007-07-16 15:40:11 +00:00
{
2007-11-05 15:10:20 +00:00
ss . WriteLine ( " <include name=\"{0}\" />" , file . Substring ( 0 , file . LastIndexOf ( '.' ) ) + ".resx" ) ;
2007-07-16 15:40:11 +00:00
}
2007-11-05 15:10:20 +00:00
break ;
2007-07-16 15:40:11 +00:00
}
2007-11-05 15:10:20 +00:00
}
2007-07-16 15:40:11 +00:00
//if (project.Files.GetSubType(file).ToString() != "Code")
//{
// ps.WriteLine(" <EmbeddedResource Include=\"{0}\">", file.Substring(0, file.LastIndexOf('.')) + ".resx");
ss . WriteLine ( " </resources>" ) ;
2007-09-15 10:17:24 +00:00
ss . WriteLine ( " <sources failonempty=\"true\">" ) ;
2007-11-05 15:10:20 +00:00
foreach ( string file in project . Files )
{
switch ( project . Files . GetBuildAction ( file ) )
2007-09-15 10:17:24 +00:00
{
2007-11-05 15:10:20 +00:00
case BuildAction . Compile :
ss . WriteLine ( " <include name=\"" + Helper . NormalizePath ( PrependPath ( file ) , '/' ) + "\" />" ) ;
break ;
default :
break ;
2007-09-15 10:17:24 +00:00
}
2007-11-05 15:10:20 +00:00
}
2007-09-15 10:17:24 +00:00
ss . WriteLine ( " </sources>" ) ;
ss . WriteLine ( " <references basedir=\"${project::get-base-directory()}\">" ) ;
ss . WriteLine ( " <lib>" ) ;
ss . WriteLine ( " <include name=\"${project::get-base-directory()}\" />" ) ;
ss . WriteLine ( " <include name=\"${project::get-base-directory()}/${build.dir}\" />" ) ;
ss . WriteLine ( " </lib>" ) ;
2007-11-05 15:10:20 +00:00
foreach ( ReferenceNode refr in project . References )
{
string path = Helper . NormalizePath ( Helper . MakePathRelativeTo ( project . FullPath , BuildReference ( solution , project , refr ) ) , '/' ) ;
ss . WriteLine ( " <include name=\"" + path + "\" />" ) ;
}
2007-09-15 10:17:24 +00:00
ss . WriteLine ( " </references>" ) ;
2007-11-05 15:10:20 +00:00
2007-09-15 10:17:24 +00:00
ss . WriteLine ( " </csc>" ) ;
2007-07-16 15:40:11 +00:00
foreach ( ConfigurationNode conf in project . Configurations )
2007-11-05 15:10:20 +00:00
{
if ( ! String . IsNullOrEmpty ( conf . Options . OutputPath ) )
2007-07-16 15:40:11 +00:00
{
2007-11-05 15:10:20 +00:00
string targetDir = Helper . NormalizePath ( conf . Options . OutputPath , '/' ) ;
ss . WriteLine ( " <echo message=\"Copying from [${project::get-base-directory()}/${build.dir}/] to [${project::get-base-directory()}/" + targetDir + "\" />" ) ;
ss . WriteLine ( " <mkdir dir=\"${project::get-base-directory()}/" + targetDir + "\"/>" ) ;
ss . WriteLine ( " <copy todir=\"${project::get-base-directory()}/" + targetDir + "\">" ) ;
ss . WriteLine ( " <fileset basedir=\"${project::get-base-directory()}/${build.dir}/\" >" ) ;
ss . WriteLine ( " <include name=\"*.dll\"/>" ) ;
ss . WriteLine ( " <include name=\"*.exe\"/>" ) ;
2008-11-08 13:55:11 +00:00
ss . WriteLine ( " <include name=\"*.mdb\" if='${build.debug}'/>" ) ;
2007-11-05 15:10:20 +00:00
ss . WriteLine ( " </fileset>" ) ;
ss . WriteLine ( " </copy>" ) ;
break ;
2007-07-16 15:40:11 +00:00
}
2007-11-05 15:10:20 +00:00
}
2007-09-15 10:17:24 +00:00
ss . WriteLine ( " </target>" ) ;
ss . WriteLine ( " <target name=\"clean\">" ) ;
ss . WriteLine ( " <delete dir=\"${obj.dir}\" failonerror=\"false\" />" ) ;
2007-11-28 16:24:28 +00:00
ss . WriteLine ( " <delete dir=\"${bin.dir}\" failonerror=\"false\" />" ) ;
2007-09-15 10:17:24 +00:00
ss . WriteLine ( " </target>" ) ;
ss . WriteLine ( " <target name=\"doc\" description=\"Creates documentation.\">" ) ;
if ( hasDoc )
2007-11-05 15:10:20 +00:00
{
ss . WriteLine ( " <property name=\"doc.target\" value=\"\" />" ) ;
ss . WriteLine ( " <if test=\"${platform::is-unix()}\">" ) ;
ss . WriteLine ( " <property name=\"doc.target\" value=\"Web\" />" ) ;
ss . WriteLine ( " </if>" ) ;
ss . WriteLine ( " <ndoc failonerror=\"false\" verbose=\"true\">" ) ;
ss . WriteLine ( " <assemblies basedir=\"${project::get-base-directory()}\">" ) ;
ss . Write ( " <include name=\"${build.dir}/${project::get-name()}" ) ;
if ( project . Type = = ProjectType . Library )
2007-09-15 10:17:24 +00:00
{
2007-11-05 15:10:20 +00:00
ss . WriteLine ( ".dll\" />" ) ;
}
else
{
ss . WriteLine ( ".exe\" />" ) ;
2007-09-15 10:17:24 +00:00
}
2007-11-05 15:10:20 +00:00
ss . WriteLine ( " </assemblies>" ) ;
ss . WriteLine ( " <summaries basedir=\"${project::get-base-directory()}\">" ) ;
ss . WriteLine ( " <include name=\"${build.dir}/${project::get-name()}.xml\"/>" ) ;
ss . WriteLine ( " </summaries>" ) ;
ss . WriteLine ( " <referencepaths basedir=\"${project::get-base-directory()}\">" ) ;
ss . WriteLine ( " <include name=\"${build.dir}\" />" ) ;
// foreach(ReferenceNode refr in project.References)
// {
// string path = Helper.NormalizePath(Helper.MakePathRelativeTo(project.FullPath, BuildReferencePath(solution, refr)), '/');
// if (path != "")
// {
// ss.WriteLine(" <include name=\"{0}\" />", path);
// }
// }
ss . WriteLine ( " </referencepaths>" ) ;
ss . WriteLine ( " <documenters>" ) ;
ss . WriteLine ( " <documenter name=\"MSDN\">" ) ;
ss . WriteLine ( " <property name=\"OutputDirectory\" value=\"${project::get-base-directory()}/${build.dir}/doc/${project::get-name()}\" />" ) ;
ss . WriteLine ( " <property name=\"OutputTarget\" value=\"${doc.target}\" />" ) ;
ss . WriteLine ( " <property name=\"HtmlHelpName\" value=\"${project::get-name()}\" />" ) ;
ss . WriteLine ( " <property name=\"IncludeFavorites\" value=\"False\" />" ) ;
ss . WriteLine ( " <property name=\"Title\" value=\"${project::get-name()} SDK Documentation\" />" ) ;
ss . WriteLine ( " <property name=\"SplitTOCs\" value=\"False\" />" ) ;
ss . WriteLine ( " <property name=\"DefaulTOC\" value=\"\" />" ) ;
ss . WriteLine ( " <property name=\"ShowVisualBasic\" value=\"True\" />" ) ;
ss . WriteLine ( " <property name=\"AutoDocumentConstructors\" value=\"True\" />" ) ;
ss . WriteLine ( " <property name=\"ShowMissingSummaries\" value=\"${build.debug}\" />" ) ;
ss . WriteLine ( " <property name=\"ShowMissingRemarks\" value=\"${build.debug}\" />" ) ;
ss . WriteLine ( " <property name=\"ShowMissingParams\" value=\"${build.debug}\" />" ) ;
ss . WriteLine ( " <property name=\"ShowMissingReturns\" value=\"${build.debug}\" />" ) ;
ss . WriteLine ( " <property name=\"ShowMissingValues\" value=\"${build.debug}\" />" ) ;
ss . WriteLine ( " <property name=\"DocumentInternals\" value=\"False\" />" ) ;
ss . WriteLine ( " <property name=\"DocumentPrivates\" value=\"False\" />" ) ;
ss . WriteLine ( " <property name=\"DocumentProtected\" value=\"True\" />" ) ;
ss . WriteLine ( " <property name=\"DocumentEmptyNamespaces\" value=\"${build.debug}\" />" ) ;
ss . WriteLine ( " <property name=\"IncludeAssemblyVersion\" value=\"True\" />" ) ;
ss . WriteLine ( " </documenter>" ) ;
ss . WriteLine ( " </documenters>" ) ;
ss . WriteLine ( " </ndoc>" ) ;
}
2007-09-15 10:17:24 +00:00
ss . WriteLine ( " </target>" ) ;
ss . WriteLine ( "</project>" ) ;
2007-11-05 15:10:20 +00:00
}
m_Kernel . CurrentWorkingDirectory . Pop ( ) ;
}
2007-09-15 10:17:24 +00:00
2007-11-05 15:10:20 +00:00
private void WriteCombine ( SolutionNode solution )
{
m_Kernel . Log . Write ( "Creating NAnt build files" ) ;
foreach ( ProjectNode project in solution . Projects )
2007-09-15 10:17:24 +00:00
{
2007-11-05 15:10:20 +00:00
if ( m_Kernel . AllowProject ( project . FilterGroups ) )
{
m_Kernel . Log . Write ( "...Creating project: {0}" , project . Name ) ;
WriteProject ( solution , project ) ;
}
2007-09-15 10:17:24 +00:00
}
2007-11-05 15:10:20 +00:00
m_Kernel . Log . Write ( "" ) ;
string combFile = Helper . MakeFilePath ( solution . FullPath , solution . Name , "build" ) ;
StreamWriter ss = new StreamWriter ( combFile ) ;
2007-09-15 10:17:24 +00:00
2007-11-05 15:10:20 +00:00
m_Kernel . CurrentWorkingDirectory . Push ( ) ;
Helper . SetCurrentDir ( Path . GetDirectoryName ( combFile ) ) ;
using ( ss )
2007-09-15 10:17:24 +00:00
{
ss . WriteLine ( "<?xml version=\"1.0\" ?>" ) ;
ss . WriteLine ( "<project name=\"{0}\" default=\"build\">" , solution . Name ) ;
ss . WriteLine ( " <echo message=\"Using '${nant.settings.currentframework}' Framework\"/>" ) ;
ss . WriteLine ( ) ;
//ss.WriteLine(" <property name=\"dist.dir\" value=\"dist\" />");
//ss.WriteLine(" <property name=\"source.dir\" value=\"source\" />");
ss . WriteLine ( " <property name=\"bin.dir\" value=\"bin\" />" ) ;
ss . WriteLine ( " <property name=\"obj.dir\" value=\"obj\" />" ) ;
ss . WriteLine ( " <property name=\"doc.dir\" value=\"doc\" />" ) ;
ss . WriteLine ( " <property name=\"project.main.dir\" value=\"${project::get-base-directory()}\" />" ) ;
2007-11-28 16:24:28 +00:00
// actually use active config out of prebuild.xml
ss . WriteLine ( " <property name=\"project.config\" value=\"{0}\" />" , solution . ActiveConfig ) ;
2007-11-05 15:10:20 +00:00
foreach ( ConfigurationNode conf in solution . Configurations )
{
ss . WriteLine ( ) ;
ss . WriteLine ( " <target name=\"{0}\" description=\"\">" , conf . Name ) ;
ss . WriteLine ( " <property name=\"project.config\" value=\"{0}\" />" , conf . Name ) ;
ss . WriteLine ( " <property name=\"build.debug\" value=\"{0}\" />" , conf . Options [ "DebugInformation" ] . ToString ( ) . ToLower ( ) ) ;
ss . WriteLine ( " </target>" ) ;
ss . WriteLine ( ) ;
}
2007-09-15 10:17:24 +00:00
ss . WriteLine ( " <target name=\"net-1.1\" description=\"Sets framework to .NET 1.1\">" ) ;
ss . WriteLine ( " <property name=\"nant.settings.currentframework\" value=\"net-1.1\" />" ) ;
ss . WriteLine ( " </target>" ) ;
ss . WriteLine ( ) ;
2007-11-05 15:10:20 +00:00
2007-09-15 10:17:24 +00:00
ss . WriteLine ( " <target name=\"net-2.0\" description=\"Sets framework to .NET 2.0\">" ) ;
ss . WriteLine ( " <property name=\"nant.settings.currentframework\" value=\"net-2.0\" />" ) ;
ss . WriteLine ( " </target>" ) ;
ss . WriteLine ( ) ;
ss . WriteLine ( " <target name=\"mono-2.0\" description=\"Sets framework to mono 2.0\">" ) ;
ss . WriteLine ( " <property name=\"nant.settings.currentframework\" value=\"mono-2.0\" />" ) ;
ss . WriteLine ( " </target>" ) ;
ss . WriteLine ( ) ;
ss . WriteLine ( " <target name=\"mono-1.0\" description=\"Sets framework to mono 1.0\">" ) ;
ss . WriteLine ( " <property name=\"nant.settings.currentframework\" value=\"mono-1.0\" />" ) ;
ss . WriteLine ( " </target>" ) ;
ss . WriteLine ( ) ;
ss . WriteLine ( " <target name=\"init\" description=\"\">" ) ;
ss . WriteLine ( " <call target=\"${project.config}\" />" ) ;
2008-03-17 20:55:21 +00:00
ss . WriteLine ( " <property name=\"sys.os.platform\"" ) ;
ss . WriteLine ( " value=\"${platform::get-name()}\"" ) ;
ss . WriteLine ( " />" ) ;
2007-09-15 10:17:24 +00:00
ss . WriteLine ( " <echo message=\"Platform ${sys.os.platform}\" />" ) ;
ss . WriteLine ( " <property name=\"build.dir\" value=\"${bin.dir}/${project.config}\" />" ) ;
ss . WriteLine ( " </target>" ) ;
ss . WriteLine ( ) ;
2007-09-17 10:58:06 +00:00
// sdague - ok, this is an ugly hack, but what it lets
// us do is native include of files into the nant
// created files from all .nant/*include files. This
// lets us keep using prebuild, but allows for
// extended nant targets to do build and the like.
2007-11-05 15:10:20 +00:00
try
{
2007-09-17 10:58:06 +00:00
Regex re = new Regex ( ".include$" ) ;
DirectoryInfo nantdir = new DirectoryInfo ( ".nant" ) ;
foreach ( FileSystemInfo item in nantdir . GetFileSystemInfos ( ) )
{
2007-11-05 15:10:20 +00:00
if ( item is DirectoryInfo ) { }
2007-09-17 10:58:06 +00:00
else if ( item is FileInfo )
{
2007-11-05 15:10:20 +00:00
if ( re . Match ( ( ( FileInfo ) item ) . FullName ) ! =
System . Text . RegularExpressions . Match . Empty )
{
2007-09-17 10:58:06 +00:00
Console . WriteLine ( "Including file: " + ( ( FileInfo ) item ) . FullName ) ;
2007-11-05 15:10:20 +00:00
using ( FileStream fs = new FileStream ( ( ( FileInfo ) item ) . FullName ,
2007-09-17 10:58:06 +00:00
FileMode . Open ,
FileAccess . Read ,
2007-11-05 15:10:20 +00:00
FileShare . None ) )
2007-09-17 10:58:06 +00:00
{
2007-11-05 15:10:20 +00:00
using ( StreamReader sr = new StreamReader ( fs ) )
2007-09-17 10:58:06 +00:00
{
ss . WriteLine ( "<!-- included from {0} -->" , ( ( FileInfo ) item ) . FullName ) ;
2007-11-05 15:10:20 +00:00
while ( sr . Peek ( ) ! = - 1 )
{
2007-09-17 10:58:06 +00:00
ss . WriteLine ( sr . ReadLine ( ) ) ;
}
ss . WriteLine ( ) ;
}
}
}
}
}
2007-11-05 15:10:20 +00:00
}
catch { }
2007-09-17 10:58:06 +00:00
// ss.WriteLine(" <include buildfile=\".nant/local.include\" />");
2007-11-05 15:10:20 +00:00
// ss.WriteLine(" <target name=\"zip\" description=\"\">");
// ss.WriteLine(" <zip zipfile=\"{0}-{1}.zip\">", solution.Name, solution.Version);
// ss.WriteLine(" <fileset basedir=\"${project::get-base-directory()}\">");
// ss.WriteLine(" <include name=\"${project::get-base-directory()}/**/*.cs\" />");
// // ss.WriteLine(" <include name=\"${project.main.dir}/**/*\" />");
// ss.WriteLine(" </fileset>");
// ss.WriteLine(" </zip>");
// ss.WriteLine(" <echo message=\"Building zip target\" />");
// ss.WriteLine(" </target>");
2007-09-15 10:17:24 +00:00
ss . WriteLine ( ) ;
2007-11-05 15:10:20 +00:00
2007-09-15 10:17:24 +00:00
ss . WriteLine ( " <target name=\"clean\" description=\"\">" ) ;
ss . WriteLine ( " <echo message=\"Deleting all builds from all configurations\" />" ) ;
//ss.WriteLine(" <delete dir=\"${dist.dir}\" failonerror=\"false\" />");
2007-11-28 16:24:28 +00:00
ss . WriteLine ( " <delete failonerror=\"false\">" ) ;
ss . WriteLine ( " <fileset basedir=\"${bin.dir}\">" ) ;
ss . WriteLine ( " <include name=\"OpenSim*.dll\"/>" ) ;
ss . WriteLine ( " <include name=\"OpenSim*.exe\"/>" ) ;
ss . WriteLine ( " <include name=\"ScriptEngines/*\"/>" ) ;
ss . WriteLine ( " <include name=\"Physics/*\"/>" ) ;
2008-02-15 11:11:03 +00:00
ss . WriteLine ( " <exclude name=\"OpenSim.32BitLaunch.exe\"/>" ) ;
ss . WriteLine ( " <exclude name=\"ScriptEngines/Default.lsl\"/>" ) ;
2007-11-28 16:24:28 +00:00
ss . WriteLine ( " </fileset>" ) ;
ss . WriteLine ( " </delete>" ) ;
2007-09-15 10:17:24 +00:00
ss . WriteLine ( " <delete dir=\"${obj.dir}\" failonerror=\"false\" />" ) ;
2007-11-05 15:10:20 +00:00
foreach ( ProjectNode project in solution . Projects )
{
string path = Helper . MakePathRelativeTo ( solution . FullPath , project . FullPath ) ;
ss . Write ( " <nant buildfile=\"{0}\"" ,
Helper . NormalizePath ( Helper . MakeFilePath ( path , project . Name + GetProjectExtension ( project ) , "build" ) , '/' ) ) ;
ss . WriteLine ( " target=\"clean\" />" ) ;
}
2007-09-15 10:17:24 +00:00
ss . WriteLine ( " </target>" ) ;
ss . WriteLine ( ) ;
ss . WriteLine ( " <target name=\"build\" depends=\"init\" description=\"\">" ) ;
2007-11-05 15:10:20 +00:00
foreach ( ProjectNode project in solution . ProjectsTableOrder )
{
string path = Helper . MakePathRelativeTo ( solution . FullPath , project . FullPath ) ;
ss . Write ( " <nant buildfile=\"{0}\"" ,
Helper . NormalizePath ( Helper . MakeFilePath ( path , project . Name + GetProjectExtension ( project ) , "build" ) , '/' ) ) ;
ss . WriteLine ( " target=\"build\" />" ) ;
}
2007-09-15 10:17:24 +00:00
ss . WriteLine ( " </target>" ) ;
ss . WriteLine ( ) ;
ss . WriteLine ( " <target name=\"build-release\" depends=\"Release, init, build\" description=\"Builds in Release mode\" />" ) ;
ss . WriteLine ( ) ;
ss . WriteLine ( " <target name=\"build-debug\" depends=\"Debug, init, build\" description=\"Builds in Debug mode\" />" ) ;
ss . WriteLine ( ) ;
//ss.WriteLine(" <target name=\"package\" depends=\"clean, doc, copyfiles, zip\" description=\"Builds in Release mode\" />");
ss . WriteLine ( " <target name=\"package\" depends=\"clean, doc\" description=\"Builds all\" />" ) ;
ss . WriteLine ( ) ;
2007-07-16 15:40:11 +00:00
ss . WriteLine ( " <target name=\"doc\" depends=\"build-release\">" ) ;
ss . WriteLine ( " <echo message=\"Generating all documentation from all builds\" />" ) ;
foreach ( ProjectNode project in solution . Projects )
2007-11-05 15:10:20 +00:00
{
string path = Helper . MakePathRelativeTo ( solution . FullPath , project . FullPath ) ;
ss . Write ( " <nant buildfile=\"{0}\"" ,
Helper . NormalizePath ( Helper . MakeFilePath ( path , project . Name + GetProjectExtension ( project ) , "build" ) , '/' ) ) ;
ss . WriteLine ( " target=\"doc\" />" ) ;
}
2007-09-15 10:17:24 +00:00
ss . WriteLine ( " </target>" ) ;
2007-11-05 15:10:20 +00:00
ss . WriteLine ( ) ;
2007-09-15 10:17:24 +00:00
ss . WriteLine ( "</project>" ) ;
}
2007-11-05 15:10:20 +00:00
m_Kernel . CurrentWorkingDirectory . Pop ( ) ;
}
2007-09-15 10:17:24 +00:00
2007-11-05 15:10:20 +00:00
private void CleanProject ( ProjectNode project )
{
m_Kernel . Log . Write ( "...Cleaning project: {0}" , project . Name ) ;
string projectFile = Helper . MakeFilePath ( project . FullPath , project . Name + GetProjectExtension ( project ) , "build" ) ;
Helper . DeleteIfExists ( projectFile ) ;
}
2007-09-15 10:17:24 +00:00
2007-11-05 15:10:20 +00:00
private void CleanSolution ( SolutionNode solution )
{
m_Kernel . Log . Write ( "Cleaning NAnt build files for" , solution . Name ) ;
2007-09-15 10:17:24 +00:00
2007-11-05 15:10:20 +00:00
string slnFile = Helper . MakeFilePath ( solution . FullPath , solution . Name , "build" ) ;
Helper . DeleteIfExists ( slnFile ) ;
2007-09-15 10:17:24 +00:00
2007-11-05 15:10:20 +00:00
foreach ( ProjectNode project in solution . Projects )
2007-09-15 10:17:24 +00:00
{
CleanProject ( project ) ;
}
2007-11-05 15:10:20 +00:00
m_Kernel . Log . Write ( "" ) ;
}
2007-09-15 10:17:24 +00:00
2007-11-05 15:10:20 +00:00
# endregion
2007-09-15 10:17:24 +00:00
2007-11-05 15:10:20 +00:00
#region ITarget Members
/// <summary>
/// Writes the specified kern.
/// </summary>
/// <param name="kern">The kern.</param>
public void Write ( Kernel kern )
{
if ( kern = = null )
2007-09-15 10:17:24 +00:00
{
throw new ArgumentNullException ( "kern" ) ;
}
2007-11-05 15:10:20 +00:00
m_Kernel = kern ;
foreach ( SolutionNode solution in kern . Solutions )
2007-09-15 10:17:24 +00:00
{
WriteCombine ( solution ) ;
}
2007-11-05 15:10:20 +00:00
m_Kernel = null ;
}
/// <summary>
/// Cleans the specified kern.
/// </summary>
/// <param name="kern">The kern.</param>
public virtual void Clean ( Kernel kern )
{
if ( kern = = null )
2007-09-15 10:17:24 +00:00
{
throw new ArgumentNullException ( "kern" ) ;
}
2007-11-05 15:10:20 +00:00
m_Kernel = kern ;
foreach ( SolutionNode sol in kern . Solutions )
2007-09-15 10:17:24 +00:00
{
CleanSolution ( sol ) ;
}
2007-11-05 15:10:20 +00:00
m_Kernel = null ;
}
/// <summary>
/// Gets the name.
/// </summary>
/// <value>The name.</value>
public string Name
{
get
2007-09-15 10:17:24 +00:00
{
return "nant" ;
}
2007-11-05 15:10:20 +00:00
}
2007-09-15 10:17:24 +00:00
2007-11-05 15:10:20 +00:00
# endregion
}
2007-07-16 15:40:11 +00:00
}