opensim – Blame information for rev 1

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