NAntTarget.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  1. #region BSD License
  2. /*
  3. Copyright (c) 2004 - 2008
  4. Matthew Holmes ([email protected]),
  5. Dan Moorehead ([email protected]),
  6. C.J. Adams-Collier ([email protected]),
  7. Redistribution and use in source and binary forms, with or without
  8. modification, are permitted provided that the following conditions are
  9. met:
  10. * Redistributions of source code must retain the above copyright
  11. notice, this list of conditions and the following disclaimer.
  12. * Redistributions in binary form must reproduce the above copyright
  13. notice, this list of conditions and the following disclaimer in the
  14. documentation and/or other materials provided with the distribution.
  15. * The name of the author may not be used to endorse or promote
  16. products derived from this software without specific prior written
  17. permission.
  18. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  19. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
  22. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  24. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  25. HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  26. STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  27. IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #endregion
  31. using System;
  32. using System.Collections.Generic;
  33. using System.IO;
  34. using System.Text.RegularExpressions;
  35. using Prebuild.Core.Attributes;
  36. using Prebuild.Core.Interfaces;
  37. using Prebuild.Core.Nodes;
  38. using Prebuild.Core.Utilities;
  39. namespace Prebuild.Core.Targets
  40. {
  41. /// <summary>
  42. ///
  43. /// </summary>
  44. [Target("nant")]
  45. public class NAntTarget : ITarget
  46. {
  47. #region Fields
  48. private Kernel m_Kernel;
  49. #endregion
  50. #region Private Methods
  51. private static string PrependPath(string path)
  52. {
  53. string tmpPath = Helper.NormalizePath(path, '/');
  54. Regex regex = new Regex(@"(\w):/(\w+)");
  55. Match match = regex.Match(tmpPath);
  56. //if(match.Success || tmpPath[0] == '.' || tmpPath[0] == '/')
  57. //{
  58. tmpPath = Helper.NormalizePath(tmpPath);
  59. //}
  60. // else
  61. // {
  62. // tmpPath = Helper.NormalizePath("./" + tmpPath);
  63. // }
  64. return tmpPath;
  65. }
  66. private static string BuildReference(SolutionNode solution, ProjectNode currentProject, ReferenceNode refr)
  67. {
  68. if (!String.IsNullOrEmpty(refr.Path))
  69. {
  70. return refr.Path;
  71. }
  72. if (solution.ProjectsTable.ContainsKey(refr.Name))
  73. {
  74. ProjectNode projectRef = (ProjectNode) solution.ProjectsTable[refr.Name];
  75. string finalPath =
  76. Helper.NormalizePath(refr.Name + GetProjectExtension(projectRef), '/');
  77. return finalPath;
  78. }
  79. ProjectNode project = (ProjectNode) refr.Parent;
  80. // Do we have an explicit file reference?
  81. string fileRef = FindFileReference(refr.Name, project);
  82. if (fileRef != null)
  83. {
  84. return fileRef;
  85. }
  86. // Is there an explicit path in the project ref?
  87. if (refr.Path != null)
  88. {
  89. return Helper.NormalizePath(refr.Path + "/" + refr.Name + GetProjectExtension(project), '/');
  90. }
  91. // No, it's an extensionless GAC ref, but nant needs the .dll extension anyway
  92. return refr.Name + ".dll";
  93. }
  94. public static string GetRefFileName(string refName)
  95. {
  96. if (ExtensionSpecified(refName))
  97. {
  98. return refName;
  99. }
  100. else
  101. {
  102. return refName + ".dll";
  103. }
  104. }
  105. private static bool ExtensionSpecified(string refName)
  106. {
  107. return refName.EndsWith(".dll") || refName.EndsWith(".exe");
  108. }
  109. private static string GetProjectExtension(ProjectNode project)
  110. {
  111. string extension = ".dll";
  112. if (project.Type == ProjectType.Exe || project.Type == ProjectType.WinExe)
  113. {
  114. extension = ".exe";
  115. }
  116. return extension;
  117. }
  118. private static string FindFileReference(string refName, ProjectNode project)
  119. {
  120. foreach (ReferencePathNode refPath in project.ReferencePaths)
  121. {
  122. string fullPath = Helper.MakeFilePath(refPath.Path, refName);
  123. if (File.Exists(fullPath))
  124. {
  125. return fullPath;
  126. }
  127. fullPath = Helper.MakeFilePath(refPath.Path, refName, "dll");
  128. if (File.Exists(fullPath))
  129. {
  130. return fullPath;
  131. }
  132. fullPath = Helper.MakeFilePath(refPath.Path, refName, "exe");
  133. if (File.Exists(fullPath))
  134. {
  135. return fullPath;
  136. }
  137. }
  138. return null;
  139. }
  140. /// <summary>
  141. /// Gets the XML doc file.
  142. /// </summary>
  143. /// <param name="project">The project.</param>
  144. /// <param name="conf">The conf.</param>
  145. /// <returns></returns>
  146. public static string GetXmlDocFile(ProjectNode project, ConfigurationNode conf)
  147. {
  148. if (conf == null)
  149. {
  150. throw new ArgumentNullException("conf");
  151. }
  152. if (project == null)
  153. {
  154. throw new ArgumentNullException("project");
  155. }
  156. string docFile = (string)conf.Options["XmlDocFile"];
  157. // if(docFile != null && docFile.Length == 0)//default to assembly name if not specified
  158. // {
  159. // return Path.GetFileNameWithoutExtension(project.AssemblyName) + ".xml";
  160. // }
  161. return docFile;
  162. }
  163. private void WriteProject(SolutionNode solution, ProjectNode project)
  164. {
  165. string projFile = Helper.MakeFilePath(project.FullPath, project.Name + GetProjectExtension(project), "build");
  166. StreamWriter ss = new StreamWriter(projFile);
  167. m_Kernel.CurrentWorkingDirectory.Push();
  168. Helper.SetCurrentDir(Path.GetDirectoryName(projFile));
  169. bool hasDoc = false;
  170. using (ss)
  171. {
  172. ss.WriteLine("<?xml version=\"1.0\" ?>");
  173. ss.WriteLine("<project name=\"{0}\" default=\"build\">", project.Name);
  174. ss.WriteLine(" <target name=\"{0}\">", "build");
  175. ss.WriteLine(" <echo message=\"Build Directory is ${project::get-base-directory()}/${build.dir}\" />");
  176. ss.WriteLine(" <mkdir dir=\"${project::get-base-directory()}/${build.dir}\" />");
  177. ss.WriteLine(" <copy todir=\"${project::get-base-directory()}/${build.dir}\" flatten=\"true\">");
  178. ss.WriteLine(" <fileset basedir=\"${project::get-base-directory()}\">");
  179. foreach (ReferenceNode refr in project.References)
  180. {
  181. if (refr.LocalCopy)
  182. {
  183. ss.WriteLine(" <include name=\"{0}", Helper.NormalizePath(Helper.MakePathRelativeTo(project.FullPath, BuildReference(solution, project, refr)) + "\" />", '/'));
  184. }
  185. }
  186. ss.WriteLine(" </fileset>");
  187. ss.WriteLine(" </copy>");
  188. if (project.ConfigFile != null && project.ConfigFile.Length!=0)
  189. {
  190. ss.Write(" <copy file=\"" + project.ConfigFile + "\" tofile=\"${project::get-base-directory()}/${build.dir}/${project::get-name()}");
  191. if (project.Type == ProjectType.Library)
  192. {
  193. ss.Write(".dll.config\"");
  194. }
  195. else
  196. {
  197. ss.Write(".exe.config\"");
  198. }
  199. ss.WriteLine(" />");
  200. }
  201. // Add the content files to just be copied
  202. ss.WriteLine(" {0}", "<copy todir=\"${project::get-base-directory()}/${build.dir}\">");
  203. ss.WriteLine(" {0}", "<fileset basedir=\".\">");
  204. foreach (string file in project.Files)
  205. {
  206. // Ignore if we aren't content
  207. if (project.Files.GetBuildAction(file) != BuildAction.Content)
  208. continue;
  209. // Create a include tag
  210. ss.WriteLine(" {0}", "<include name=\"" + Helper.NormalizePath(PrependPath(file), '/') + "\" />");
  211. }
  212. ss.WriteLine(" {0}", "</fileset>");
  213. ss.WriteLine(" {0}", "</copy>");
  214. ss.Write(" <csc ");
  215. ss.Write(" target=\"{0}\"", project.Type.ToString().ToLower());
  216. ss.Write(" debug=\"{0}\"", "${build.debug}");
  217. ss.Write(" platform=\"${build.platform}\"");
  218. foreach (ConfigurationNode conf in project.Configurations)
  219. {
  220. if (conf.Options.KeyFile != "")
  221. {
  222. ss.Write(" keyfile=\"{0}\"", conf.Options.KeyFile);
  223. break;
  224. }
  225. }
  226. foreach (ConfigurationNode conf in project.Configurations)
  227. {
  228. ss.Write(" unsafe=\"{0}\"", conf.Options.AllowUnsafe);
  229. break;
  230. }
  231. foreach (ConfigurationNode conf in project.Configurations)
  232. {
  233. ss.Write(" warnaserror=\"{0}\"", conf.Options.WarningsAsErrors);
  234. break;
  235. }
  236. foreach (ConfigurationNode conf in project.Configurations)
  237. {
  238. ss.Write(" define=\"{0}\"", conf.Options.CompilerDefines);
  239. break;
  240. }
  241. foreach (ConfigurationNode conf in project.Configurations)
  242. {
  243. ss.Write(" nostdlib=\"{0}\"", conf.Options["NoStdLib"]);
  244. break;
  245. }
  246. ss.Write(" main=\"{0}\"", project.StartupObject);
  247. foreach (ConfigurationNode conf in project.Configurations)
  248. {
  249. if (GetXmlDocFile(project, conf) != "")
  250. {
  251. ss.Write(" doc=\"{0}\"", "${project::get-base-directory()}/${build.dir}/" + GetXmlDocFile(project, conf));
  252. hasDoc = true;
  253. }
  254. break;
  255. }
  256. ss.Write(" output=\"{0}", "${project::get-base-directory()}/${build.dir}/${project::get-name()}");
  257. if (project.Type == ProjectType.Library)
  258. {
  259. ss.Write(".dll\"");
  260. }
  261. else
  262. {
  263. ss.Write(".exe\"");
  264. }
  265. if (project.AppIcon != null && project.AppIcon.Length != 0)
  266. {
  267. ss.Write(" win32icon=\"{0}\"", Helper.NormalizePath(project.AppIcon, '/'));
  268. }
  269. // This disables a very different behavior between VS and NAnt. With Nant,
  270. // If you have using System.Xml; it will ensure System.Xml.dll is referenced,
  271. // but not in VS. This will force the behaviors to match, so when it works
  272. // in nant, it will work in VS.
  273. ss.Write(" noconfig=\"true\"");
  274. ss.WriteLine(">");
  275. ss.WriteLine(" <resources prefix=\"{0}\" dynamicprefix=\"true\" >", project.RootNamespace);
  276. foreach (string file in project.Files)
  277. {
  278. switch (project.Files.GetBuildAction(file))
  279. {
  280. case BuildAction.EmbeddedResource:
  281. ss.WriteLine(" {0}", "<include name=\"" + Helper.NormalizePath(PrependPath(file), '/') + "\" />");
  282. break;
  283. default:
  284. if (project.Files.GetSubType(file) != SubType.Code && project.Files.GetSubType(file) != SubType.Settings)
  285. {
  286. ss.WriteLine(" <include name=\"{0}\" />", file.Substring(0, file.LastIndexOf('.')) + ".resx");
  287. }
  288. break;
  289. }
  290. }
  291. //if (project.Files.GetSubType(file).ToString() != "Code")
  292. //{
  293. // ps.WriteLine(" <EmbeddedResource Include=\"{0}\">", file.Substring(0, file.LastIndexOf('.')) + ".resx");
  294. ss.WriteLine(" </resources>");
  295. ss.WriteLine(" <sources failonempty=\"true\">");
  296. foreach (string file in project.Files)
  297. {
  298. switch (project.Files.GetBuildAction(file))
  299. {
  300. case BuildAction.Compile:
  301. ss.WriteLine(" <include name=\"" + Helper.NormalizePath(PrependPath(file), '/') + "\" />");
  302. break;
  303. default:
  304. break;
  305. }
  306. }
  307. ss.WriteLine(" </sources>");
  308. ss.WriteLine(" <references basedir=\"${project::get-base-directory()}\">");
  309. ss.WriteLine(" <lib>");
  310. ss.WriteLine(" <include name=\"${project::get-base-directory()}\" />");
  311. foreach(ReferencePathNode refPath in project.ReferencePaths)
  312. {
  313. ss.WriteLine(" <include name=\"${project::get-base-directory()}/" + refPath.Path.TrimEnd('/', '\\') + "\" />");
  314. }
  315. ss.WriteLine(" </lib>");
  316. foreach (ReferenceNode refr in project.References)
  317. {
  318. string path = Helper.NormalizePath(Helper.MakePathRelativeTo(project.FullPath, BuildReference(solution, project, refr)), '/');
  319. if (refr.Path != null) {
  320. if (ExtensionSpecified(refr.Name))
  321. {
  322. ss.WriteLine (" <include name=\"" + path + refr.Name + "\"/>");
  323. }
  324. else
  325. {
  326. ss.WriteLine (" <include name=\"" + path + refr.Name + ".dll\"/>");
  327. }
  328. }
  329. else
  330. {
  331. ss.WriteLine (" <include name=\"" + path + "\" />");
  332. }
  333. }
  334. ss.WriteLine(" </references>");
  335. ss.WriteLine(" </csc>");
  336. foreach (ConfigurationNode conf in project.Configurations)
  337. {
  338. if (!String.IsNullOrEmpty(conf.Options.OutputPath))
  339. {
  340. string targetDir = Helper.NormalizePath(conf.Options.OutputPath, '/');
  341. ss.WriteLine(" <echo message=\"Copying from [${project::get-base-directory()}/${build.dir}/] to [${project::get-base-directory()}/" + targetDir + "\" />");
  342. ss.WriteLine(" <mkdir dir=\"${project::get-base-directory()}/" + targetDir + "\"/>");
  343. ss.WriteLine(" <copy todir=\"${project::get-base-directory()}/" + targetDir + "\">");
  344. ss.WriteLine(" <fileset basedir=\"${project::get-base-directory()}/${build.dir}/\" >");
  345. ss.WriteLine(" <include name=\"*.dll\"/>");
  346. ss.WriteLine(" <include name=\"*.exe\"/>");
  347. ss.WriteLine(" <include name=\"*.mdb\" if='${build.debug}'/>");
  348. ss.WriteLine(" <include name=\"*.pdb\" if='${build.debug}'/>");
  349. ss.WriteLine(" </fileset>");
  350. ss.WriteLine(" </copy>");
  351. break;
  352. }
  353. }
  354. ss.WriteLine(" </target>");
  355. ss.WriteLine(" <target name=\"clean\">");
  356. ss.WriteLine(" <delete dir=\"${bin.dir}\" failonerror=\"false\" />");
  357. ss.WriteLine(" <delete dir=\"${obj.dir}\" failonerror=\"false\" />");
  358. ss.WriteLine(" </target>");
  359. ss.WriteLine(" <target name=\"doc\" description=\"Creates documentation.\">");
  360. if (hasDoc)
  361. {
  362. ss.WriteLine(" <property name=\"doc.target\" value=\"\" />");
  363. ss.WriteLine(" <if test=\"${platform::is-unix()}\">");
  364. ss.WriteLine(" <property name=\"doc.target\" value=\"Web\" />");
  365. ss.WriteLine(" </if>");
  366. ss.WriteLine(" <ndoc failonerror=\"false\" verbose=\"true\">");
  367. ss.WriteLine(" <assemblies basedir=\"${project::get-base-directory()}\">");
  368. ss.Write(" <include name=\"${build.dir}/${project::get-name()}");
  369. if (project.Type == ProjectType.Library)
  370. {
  371. ss.WriteLine(".dll\" />");
  372. }
  373. else
  374. {
  375. ss.WriteLine(".exe\" />");
  376. }
  377. ss.WriteLine(" </assemblies>");
  378. ss.WriteLine(" <summaries basedir=\"${project::get-base-directory()}\">");
  379. ss.WriteLine(" <include name=\"${build.dir}/${project::get-name()}.xml\"/>");
  380. ss.WriteLine(" </summaries>");
  381. ss.WriteLine(" <referencepaths basedir=\"${project::get-base-directory()}\">");
  382. ss.WriteLine(" <include name=\"${build.dir}\" />");
  383. // foreach(ReferenceNode refr in project.References)
  384. // {
  385. // string path = Helper.NormalizePath(Helper.MakePathRelativeTo(project.FullPath, BuildReferencePath(solution, refr)), '/');
  386. // if (path != "")
  387. // {
  388. // ss.WriteLine(" <include name=\"{0}\" />", path);
  389. // }
  390. // }
  391. ss.WriteLine(" </referencepaths>");
  392. ss.WriteLine(" <documenters>");
  393. ss.WriteLine(" <documenter name=\"MSDN\">");
  394. ss.WriteLine(" <property name=\"OutputDirectory\" value=\"${project::get-base-directory()}/${build.dir}/doc/${project::get-name()}\" />");
  395. ss.WriteLine(" <property name=\"OutputTarget\" value=\"${doc.target}\" />");
  396. ss.WriteLine(" <property name=\"HtmlHelpName\" value=\"${project::get-name()}\" />");
  397. ss.WriteLine(" <property name=\"IncludeFavorites\" value=\"False\" />");
  398. ss.WriteLine(" <property name=\"Title\" value=\"${project::get-name()} SDK Documentation\" />");
  399. ss.WriteLine(" <property name=\"SplitTOCs\" value=\"False\" />");
  400. ss.WriteLine(" <property name=\"DefaulTOC\" value=\"\" />");
  401. ss.WriteLine(" <property name=\"ShowVisualBasic\" value=\"True\" />");
  402. ss.WriteLine(" <property name=\"AutoDocumentConstructors\" value=\"True\" />");
  403. ss.WriteLine(" <property name=\"ShowMissingSummaries\" value=\"${build.debug}\" />");
  404. ss.WriteLine(" <property name=\"ShowMissingRemarks\" value=\"${build.debug}\" />");
  405. ss.WriteLine(" <property name=\"ShowMissingParams\" value=\"${build.debug}\" />");
  406. ss.WriteLine(" <property name=\"ShowMissingReturns\" value=\"${build.debug}\" />");
  407. ss.WriteLine(" <property name=\"ShowMissingValues\" value=\"${build.debug}\" />");
  408. ss.WriteLine(" <property name=\"DocumentInternals\" value=\"False\" />");
  409. ss.WriteLine(" <property name=\"DocumentPrivates\" value=\"False\" />");
  410. ss.WriteLine(" <property name=\"DocumentProtected\" value=\"True\" />");
  411. ss.WriteLine(" <property name=\"DocumentEmptyNamespaces\" value=\"${build.debug}\" />");
  412. ss.WriteLine(" <property name=\"IncludeAssemblyVersion\" value=\"True\" />");
  413. ss.WriteLine(" </documenter>");
  414. ss.WriteLine(" </documenters>");
  415. ss.WriteLine(" </ndoc>");
  416. }
  417. ss.WriteLine(" </target>");
  418. ss.WriteLine("</project>");
  419. }
  420. m_Kernel.CurrentWorkingDirectory.Pop();
  421. }
  422. private void WriteCombine(SolutionNode solution)
  423. {
  424. m_Kernel.Log.Write("Creating NAnt build files");
  425. foreach (ProjectNode project in solution.Projects)
  426. {
  427. if (m_Kernel.AllowProject(project.FilterGroups))
  428. {
  429. m_Kernel.Log.Write("...Creating project: {0}", project.Name);
  430. WriteProject(solution, project);
  431. }
  432. }
  433. m_Kernel.Log.Write("");
  434. string combFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "build");
  435. StreamWriter ss = new StreamWriter(combFile);
  436. m_Kernel.CurrentWorkingDirectory.Push();
  437. Helper.SetCurrentDir(Path.GetDirectoryName(combFile));
  438. using (ss)
  439. {
  440. ss.WriteLine("<?xml version=\"1.0\" ?>");
  441. ss.WriteLine("<project name=\"{0}\" default=\"build\">", solution.Name);
  442. ss.WriteLine(" <echo message=\"Using '${nant.settings.currentframework}' Framework\"/>");
  443. ss.WriteLine();
  444. //ss.WriteLine(" <property name=\"dist.dir\" value=\"dist\" />");
  445. //ss.WriteLine(" <property name=\"source.dir\" value=\"source\" />");
  446. ss.WriteLine(" <property name=\"bin.dir\" value=\"bin\" />");
  447. ss.WriteLine(" <property name=\"obj.dir\" value=\"obj\" />");
  448. ss.WriteLine(" <property name=\"doc.dir\" value=\"doc\" />");
  449. ss.WriteLine(" <property name=\"project.main.dir\" value=\"${project::get-base-directory()}\" />");
  450. // Use the active configuration, which is the first configuration name in the prebuild file.
  451. Dictionary<string,string> emittedConfigurations = new Dictionary<string, string>();
  452. ss.WriteLine(" <property name=\"project.config\" value=\"{0}\" />", solution.ActiveConfig);
  453. ss.WriteLine();
  454. foreach (ConfigurationNode conf in solution.Configurations)
  455. {
  456. // If the name isn't in the emitted configurations, we give a high level target to the
  457. // platform specific on. This lets "Debug" point to "Debug-AnyCPU".
  458. if (!emittedConfigurations.ContainsKey(conf.Name))
  459. {
  460. // Add it to the dictionary so we only emit one.
  461. emittedConfigurations.Add(conf.Name, conf.Platform);
  462. // Write out the target block.
  463. ss.WriteLine(" <target name=\"{0}\" description=\"{0}|{1}\" depends=\"{0}-{1}\">", conf.Name, conf.Platform);
  464. ss.WriteLine(" </target>");
  465. ss.WriteLine();
  466. }
  467. // Write out the target for the configuration.
  468. ss.WriteLine(" <target name=\"{0}-{1}\" description=\"{0}|{1}\">", conf.Name, conf.Platform);
  469. ss.WriteLine(" <property name=\"project.config\" value=\"{0}\" />", conf.Name);
  470. ss.WriteLine(" <property name=\"build.debug\" value=\"{0}\" />", conf.Options["DebugInformation"].ToString().ToLower());
  471. ss.WriteLine("\t\t <property name=\"build.platform\" value=\"{0}\" />", conf.Platform);
  472. ss.WriteLine(" </target>");
  473. ss.WriteLine();
  474. }
  475. ss.WriteLine(" <target name=\"net-1.1\" description=\"Sets framework to .NET 1.1\">");
  476. ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"net-1.1\" />");
  477. ss.WriteLine(" </target>");
  478. ss.WriteLine();
  479. ss.WriteLine(" <target name=\"net-2.0\" description=\"Sets framework to .NET 2.0\">");
  480. ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"net-2.0\" />");
  481. ss.WriteLine(" </target>");
  482. ss.WriteLine();
  483. ss.WriteLine(" <target name=\"net-3.5\" description=\"Sets framework to .NET 3.5\">");
  484. ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"net-3.5\" />");
  485. ss.WriteLine(" </target>");
  486. ss.WriteLine();
  487. ss.WriteLine(" <target name=\"mono-1.0\" description=\"Sets framework to mono 1.0\">");
  488. ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"mono-1.0\" />");
  489. ss.WriteLine(" </target>");
  490. ss.WriteLine();
  491. ss.WriteLine(" <target name=\"mono-2.0\" description=\"Sets framework to mono 2.0\">");
  492. ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"mono-2.0\" />");
  493. ss.WriteLine(" </target>");
  494. ss.WriteLine();
  495. ss.WriteLine(" <target name=\"mono-3.5\" description=\"Sets framework to mono 3.5\">");
  496. ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"mono-3.5\" />");
  497. ss.WriteLine(" </target>");
  498. ss.WriteLine();
  499. ss.WriteLine(" <target name=\"init\" description=\"\">");
  500. ss.WriteLine(" <call target=\"${project.config}\" />");
  501. ss.WriteLine(" <property name=\"sys.os.platform\"");
  502. ss.WriteLine(" value=\"${platform::get-name()}\"");
  503. ss.WriteLine(" />");
  504. ss.WriteLine(" <echo message=\"Platform ${sys.os.platform}\" />");
  505. ss.WriteLine(" <property name=\"build.dir\" value=\"${bin.dir}/${project.config}\" />");
  506. ss.WriteLine(" </target>");
  507. ss.WriteLine();
  508. // sdague - ok, this is an ugly hack, but what it lets
  509. // us do is native include of files into the nant
  510. // created files from all .nant/*include files. This
  511. // lets us keep using prebuild, but allows for
  512. // extended nant targets to do build and the like.
  513. try
  514. {
  515. Regex re = new Regex(".include$");
  516. DirectoryInfo nantdir = new DirectoryInfo(".nant");
  517. foreach (FileSystemInfo item in nantdir.GetFileSystemInfos())
  518. {
  519. if (item is DirectoryInfo) { }
  520. else if (item is FileInfo)
  521. {
  522. if (re.Match(item.FullName) !=
  523. System.Text.RegularExpressions.Match.Empty)
  524. {
  525. Console.WriteLine("Including file: " + item.FullName);
  526. using (FileStream fs = new FileStream(item.FullName,
  527. FileMode.Open,
  528. FileAccess.Read,
  529. FileShare.None))
  530. {
  531. using (StreamReader sr = new StreamReader(fs))
  532. {
  533. ss.WriteLine("<!-- included from {0} -->", (item).FullName);
  534. while (sr.Peek() != -1)
  535. {
  536. ss.WriteLine(sr.ReadLine());
  537. }
  538. ss.WriteLine();
  539. }
  540. }
  541. }
  542. }
  543. }
  544. }
  545. catch { }
  546. // ss.WriteLine(" <include buildfile=\".nant/local.include\" />");
  547. // ss.WriteLine(" <target name=\"zip\" description=\"\">");
  548. // ss.WriteLine(" <zip zipfile=\"{0}-{1}.zip\">", solution.Name, solution.Version);
  549. // ss.WriteLine(" <fileset basedir=\"${project::get-base-directory()}\">");
  550. // ss.WriteLine(" <include name=\"${project::get-base-directory()}/**/*.cs\" />");
  551. // // ss.WriteLine(" <include name=\"${project.main.dir}/**/*\" />");
  552. // ss.WriteLine(" </fileset>");
  553. // ss.WriteLine(" </zip>");
  554. // ss.WriteLine(" <echo message=\"Building zip target\" />");
  555. // ss.WriteLine(" </target>");
  556. ss.WriteLine();
  557. ss.WriteLine(" <target name=\"clean\" description=\"\">");
  558. ss.WriteLine(" <echo message=\"Deleting all builds from all configurations\" />");
  559. //ss.WriteLine(" <delete dir=\"${dist.dir}\" failonerror=\"false\" />");
  560. // justincc: FIXME FIXME FIXME - A temporary OpenSim hack to clean up files when "nant clean" is executed.
  561. // Should be replaced with extreme prejudice once anybody finds out if the CleanFiles stuff works or there is
  562. // another working mechanism for specifying this stuff
  563. ss.WriteLine(" <delete failonerror=\"false\">");
  564. ss.WriteLine(" <fileset basedir=\"${bin.dir}\">");
  565. ss.WriteLine(" <include name=\"OpenSim*.dll\"/>");
  566. ss.WriteLine(" <include name=\"OpenSim*.dll.mdb\"/>");
  567. ss.WriteLine(" <include name=\"OpenSim*.exe\"/>");
  568. ss.WriteLine(" <include name=\"OpenSim*.exe.mdb\"/>");
  569. ss.WriteLine(" <include name=\"ScriptEngines/*\"/>");
  570. ss.WriteLine(" <include name=\"Physics/*.dll\"/>");
  571. ss.WriteLine(" <include name=\"Physics/*.dll.mdb\"/>");
  572. ss.WriteLine(" <exclude name=\"OpenSim.32BitLaunch.exe\"/>");
  573. ss.WriteLine(" <exclude name=\"ScriptEngines/Default.lsl\"/>");
  574. ss.WriteLine(" </fileset>");
  575. ss.WriteLine(" </delete>");
  576. if (solution.Cleanup != null && solution.Cleanup.CleanFiles.Count > 0)
  577. {
  578. foreach (CleanFilesNode cleanFile in solution.Cleanup.CleanFiles)
  579. {
  580. ss.WriteLine(" <delete failonerror=\"false\">");
  581. ss.WriteLine(" <fileset basedir=\"${project::get-base-directory()}\">");
  582. ss.WriteLine(" <include name=\"{0}/*\"/>", cleanFile.Pattern);
  583. ss.WriteLine(" <include name=\"{0}\"/>", cleanFile.Pattern);
  584. ss.WriteLine(" </fileset>");
  585. ss.WriteLine(" </delete>");
  586. }
  587. }
  588. ss.WriteLine(" <delete dir=\"${obj.dir}\" failonerror=\"false\" />");
  589. foreach (ProjectNode project in solution.Projects)
  590. {
  591. string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath);
  592. ss.Write(" <nant buildfile=\"{0}\"",
  593. Helper.NormalizePath(Helper.MakeFilePath(path, project.Name + GetProjectExtension(project), "build"), '/'));
  594. ss.WriteLine(" target=\"clean\" />");
  595. }
  596. ss.WriteLine(" </target>");
  597. ss.WriteLine();
  598. ss.WriteLine(" <target name=\"build\" depends=\"init\" description=\"\">");
  599. foreach (ProjectNode project in solution.ProjectsTableOrder)
  600. {
  601. string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath);
  602. ss.Write(" <nant buildfile=\"{0}\"",
  603. Helper.NormalizePath(Helper.MakeFilePath(path, project.Name + GetProjectExtension(project), "build"), '/'));
  604. ss.WriteLine(" target=\"build\" />");
  605. }
  606. ss.WriteLine(" </target>");
  607. ss.WriteLine();
  608. ss.WriteLine(" <target name=\"build-release\" depends=\"Release, init, build\" description=\"Builds in Release mode\" />");
  609. ss.WriteLine();
  610. ss.WriteLine(" <target name=\"build-debug\" depends=\"Debug, init, build\" description=\"Builds in Debug mode\" />");
  611. ss.WriteLine();
  612. //ss.WriteLine(" <target name=\"package\" depends=\"clean, doc, copyfiles, zip\" description=\"Builds in Release mode\" />");
  613. ss.WriteLine(" <target name=\"package\" depends=\"clean, doc\" description=\"Builds all\" />");
  614. ss.WriteLine();
  615. ss.WriteLine(" <target name=\"doc\" depends=\"build-release\">");
  616. ss.WriteLine(" <echo message=\"Generating all documentation from all builds\" />");
  617. foreach (ProjectNode project in solution.Projects)
  618. {
  619. string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath);
  620. ss.Write(" <nant buildfile=\"{0}\"",
  621. Helper.NormalizePath(Helper.MakeFilePath(path, project.Name + GetProjectExtension(project), "build"), '/'));
  622. ss.WriteLine(" target=\"doc\" />");
  623. }
  624. ss.WriteLine(" </target>");
  625. ss.WriteLine();
  626. ss.WriteLine("</project>");
  627. }
  628. m_Kernel.CurrentWorkingDirectory.Pop();
  629. }
  630. private void CleanProject(ProjectNode project)
  631. {
  632. m_Kernel.Log.Write("...Cleaning project: {0}", project.Name);
  633. string projectFile = Helper.MakeFilePath(project.FullPath, project.Name + GetProjectExtension(project), "build");
  634. Helper.DeleteIfExists(projectFile);
  635. }
  636. private void CleanSolution(SolutionNode solution)
  637. {
  638. m_Kernel.Log.Write("Cleaning NAnt build files for", solution.Name);
  639. string slnFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "build");
  640. Helper.DeleteIfExists(slnFile);
  641. foreach (ProjectNode project in solution.Projects)
  642. {
  643. CleanProject(project);
  644. }
  645. m_Kernel.Log.Write("");
  646. }
  647. #endregion
  648. #region ITarget Members
  649. /// <summary>
  650. /// Writes the specified kern.
  651. /// </summary>
  652. /// <param name="kern">The kern.</param>
  653. public void Write(Kernel kern)
  654. {
  655. if (kern == null)
  656. {
  657. throw new ArgumentNullException("kern");
  658. }
  659. m_Kernel = kern;
  660. foreach (SolutionNode solution in kern.Solutions)
  661. {
  662. WriteCombine(solution);
  663. }
  664. m_Kernel = null;
  665. }
  666. /// <summary>
  667. /// Cleans the specified kern.
  668. /// </summary>
  669. /// <param name="kern">The kern.</param>
  670. public virtual void Clean(Kernel kern)
  671. {
  672. if (kern == null)
  673. {
  674. throw new ArgumentNullException("kern");
  675. }
  676. m_Kernel = kern;
  677. foreach (SolutionNode sol in kern.Solutions)
  678. {
  679. CleanSolution(sol);
  680. }
  681. m_Kernel = null;
  682. }
  683. /// <summary>
  684. /// Gets the name.
  685. /// </summary>
  686. /// <value>The name.</value>
  687. public string Name
  688. {
  689. get
  690. {
  691. return "nant";
  692. }
  693. }
  694. #endregion
  695. }
  696. }