diff options
Diffstat (limited to 'Prebuild/src/Core/Targets/NAntTarget.cs')
-rw-r--r-- | Prebuild/src/Core/Targets/NAntTarget.cs | 792 |
1 files changed, 792 insertions, 0 deletions
diff --git a/Prebuild/src/Core/Targets/NAntTarget.cs b/Prebuild/src/Core/Targets/NAntTarget.cs new file mode 100644 index 0000000..d4a33f8 --- /dev/null +++ b/Prebuild/src/Core/Targets/NAntTarget.cs | |||
@@ -0,0 +1,792 @@ | |||
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 | ss.WriteLine(" <copy todir=\"${project::get-base-directory()}/${build.dir}\" flatten=\"true\">"); | ||
213 | ss.WriteLine(" <fileset basedir=\"${project::get-base-directory()}\">"); | ||
214 | foreach (ReferenceNode refr in project.References) | ||
215 | { | ||
216 | if (refr.LocalCopy) | ||
217 | { | ||
218 | ss.WriteLine(" <include name=\"{0}", Helper.NormalizePath(Helper.MakePathRelativeTo(project.FullPath, BuildReference(solution, project, refr)) + "\" />", '/')); | ||
219 | } | ||
220 | } | ||
221 | |||
222 | ss.WriteLine(" </fileset>"); | ||
223 | ss.WriteLine(" </copy>"); | ||
224 | if (project.ConfigFile != null && project.ConfigFile.Length!=0) | ||
225 | { | ||
226 | ss.Write(" <copy file=\"" + project.ConfigFile + "\" tofile=\"${project::get-base-directory()}/${build.dir}/${project::get-name()}"); | ||
227 | |||
228 | if (project.Type == ProjectType.Library) | ||
229 | { | ||
230 | ss.Write(".dll.config\""); | ||
231 | } | ||
232 | else | ||
233 | { | ||
234 | ss.Write(".exe.config\""); | ||
235 | } | ||
236 | ss.WriteLine(" />"); | ||
237 | } | ||
238 | |||
239 | // Add the content files to just be copied | ||
240 | ss.WriteLine(" {0}", "<copy todir=\"${project::get-base-directory()}/${build.dir}\">"); | ||
241 | ss.WriteLine(" {0}", "<fileset basedir=\".\">"); | ||
242 | |||
243 | foreach (string file in project.Files) | ||
244 | { | ||
245 | // Ignore if we aren't content | ||
246 | if (project.Files.GetBuildAction(file) != BuildAction.Content) | ||
247 | continue; | ||
248 | |||
249 | // Create a include tag | ||
250 | ss.WriteLine(" {0}", "<include name=\"" + Helper.NormalizePath(PrependPath(file), '/') + "\" />"); | ||
251 | } | ||
252 | |||
253 | ss.WriteLine(" {0}", "</fileset>"); | ||
254 | ss.WriteLine(" {0}", "</copy>"); | ||
255 | |||
256 | ss.Write(" <csc "); | ||
257 | ss.Write(" target=\"{0}\"", project.Type.ToString().ToLower()); | ||
258 | ss.Write(" debug=\"{0}\"", "${build.debug}"); | ||
259 | ss.Write(" platform=\"${build.platform}\""); | ||
260 | |||
261 | |||
262 | foreach (ConfigurationNode conf in project.Configurations) | ||
263 | { | ||
264 | if (conf.Options.KeyFile != "") | ||
265 | { | ||
266 | ss.Write(" keyfile=\"{0}\"", conf.Options.KeyFile); | ||
267 | break; | ||
268 | } | ||
269 | } | ||
270 | foreach (ConfigurationNode conf in project.Configurations) | ||
271 | { | ||
272 | ss.Write(" unsafe=\"{0}\"", conf.Options.AllowUnsafe); | ||
273 | break; | ||
274 | } | ||
275 | foreach (ConfigurationNode conf in project.Configurations) | ||
276 | { | ||
277 | ss.Write(" warnaserror=\"{0}\"", conf.Options.WarningsAsErrors); | ||
278 | break; | ||
279 | } | ||
280 | foreach (ConfigurationNode conf in project.Configurations) | ||
281 | { | ||
282 | ss.Write(" define=\"{0}\"", conf.Options.CompilerDefines); | ||
283 | break; | ||
284 | } | ||
285 | foreach (ConfigurationNode conf in project.Configurations) | ||
286 | { | ||
287 | ss.Write(" nostdlib=\"{0}\"", conf.Options["NoStdLib"]); | ||
288 | break; | ||
289 | } | ||
290 | |||
291 | ss.Write(" main=\"{0}\"", project.StartupObject); | ||
292 | |||
293 | foreach (ConfigurationNode conf in project.Configurations) | ||
294 | { | ||
295 | if (GetXmlDocFile(project, conf) != "") | ||
296 | { | ||
297 | ss.Write(" doc=\"{0}\"", "${project::get-base-directory()}/${build.dir}/" + GetXmlDocFile(project, conf)); | ||
298 | hasDoc = true; | ||
299 | } | ||
300 | break; | ||
301 | } | ||
302 | ss.Write(" output=\"{0}", "${project::get-base-directory()}/${build.dir}/${project::get-name()}"); | ||
303 | if (project.Type == ProjectType.Library) | ||
304 | { | ||
305 | ss.Write(".dll\""); | ||
306 | } | ||
307 | else | ||
308 | { | ||
309 | ss.Write(".exe\""); | ||
310 | } | ||
311 | if (project.AppIcon != null && project.AppIcon.Length != 0) | ||
312 | { | ||
313 | ss.Write(" win32icon=\"{0}\"", Helper.NormalizePath(project.AppIcon, '/')); | ||
314 | } | ||
315 | // This disables a very different behavior between VS and NAnt. With Nant, | ||
316 | // If you have using System.Xml; it will ensure System.Xml.dll is referenced, | ||
317 | // but not in VS. This will force the behaviors to match, so when it works | ||
318 | // in nant, it will work in VS. | ||
319 | ss.Write(" noconfig=\"true\""); | ||
320 | ss.WriteLine(">"); | ||
321 | ss.WriteLine(" <resources prefix=\"{0}\" dynamicprefix=\"true\" >", project.RootNamespace); | ||
322 | foreach (string file in project.Files) | ||
323 | { | ||
324 | switch (project.Files.GetBuildAction(file)) | ||
325 | { | ||
326 | case BuildAction.EmbeddedResource: | ||
327 | ss.WriteLine(" {0}", "<include name=\"" + Helper.NormalizePath(PrependPath(file), '/') + "\" />"); | ||
328 | break; | ||
329 | default: | ||
330 | if (project.Files.GetSubType(file) != SubType.Code && project.Files.GetSubType(file) != SubType.Settings) | ||
331 | { | ||
332 | ss.WriteLine(" <include name=\"{0}\" />", file.Substring(0, file.LastIndexOf('.')) + ".resx"); | ||
333 | } | ||
334 | break; | ||
335 | } | ||
336 | } | ||
337 | //if (project.Files.GetSubType(file).ToString() != "Code") | ||
338 | //{ | ||
339 | // ps.WriteLine(" <EmbeddedResource Include=\"{0}\">", file.Substring(0, file.LastIndexOf('.')) + ".resx"); | ||
340 | |||
341 | ss.WriteLine(" </resources>"); | ||
342 | ss.WriteLine(" <sources failonempty=\"true\">"); | ||
343 | foreach (string file in project.Files) | ||
344 | { | ||
345 | switch (project.Files.GetBuildAction(file)) | ||
346 | { | ||
347 | case BuildAction.Compile: | ||
348 | ss.WriteLine(" <include name=\"" + Helper.NormalizePath(PrependPath(file), '/') + "\" />"); | ||
349 | break; | ||
350 | default: | ||
351 | break; | ||
352 | } | ||
353 | } | ||
354 | ss.WriteLine(" </sources>"); | ||
355 | ss.WriteLine(" <references basedir=\"${project::get-base-directory()}\">"); | ||
356 | ss.WriteLine(" <lib>"); | ||
357 | ss.WriteLine(" <include name=\"${project::get-base-directory()}\" />"); | ||
358 | foreach(ReferencePathNode refPath in project.ReferencePaths) | ||
359 | { | ||
360 | ss.WriteLine(" <include name=\"${project::get-base-directory()}/" + refPath.Path.TrimEnd('/', '\\') + "\" />"); | ||
361 | } | ||
362 | ss.WriteLine(" </lib>"); | ||
363 | foreach (ReferenceNode refr in project.References) | ||
364 | { | ||
365 | string path = Helper.NormalizePath(Helper.MakePathRelativeTo(project.FullPath, BuildReference(solution, project, refr)), '/'); | ||
366 | if (refr.Path != null) { | ||
367 | if (ExtensionSpecified(refr.Name)) | ||
368 | { | ||
369 | ss.WriteLine (" <include name=\"" + path + refr.Name + "\"/>"); | ||
370 | } | ||
371 | else | ||
372 | { | ||
373 | ss.WriteLine (" <include name=\"" + path + refr.Name + ".dll\"/>"); | ||
374 | } | ||
375 | } | ||
376 | else | ||
377 | { | ||
378 | ss.WriteLine (" <include name=\"" + path + "\" />"); | ||
379 | } | ||
380 | } | ||
381 | ss.WriteLine(" </references>"); | ||
382 | |||
383 | ss.WriteLine(" </csc>"); | ||
384 | |||
385 | foreach (ConfigurationNode conf in project.Configurations) | ||
386 | { | ||
387 | if (!String.IsNullOrEmpty(conf.Options.OutputPath)) | ||
388 | { | ||
389 | string targetDir = Helper.NormalizePath(conf.Options.OutputPath, '/'); | ||
390 | |||
391 | ss.WriteLine(" <echo message=\"Copying from [${project::get-base-directory()}/${build.dir}/] to [${project::get-base-directory()}/" + targetDir + "\" />"); | ||
392 | |||
393 | ss.WriteLine(" <mkdir dir=\"${project::get-base-directory()}/" + targetDir + "\"/>"); | ||
394 | |||
395 | ss.WriteLine(" <copy todir=\"${project::get-base-directory()}/" + targetDir + "\">"); | ||
396 | ss.WriteLine(" <fileset basedir=\"${project::get-base-directory()}/${build.dir}/\" >"); | ||
397 | ss.WriteLine(" <include name=\"*.dll\"/>"); | ||
398 | ss.WriteLine(" <include name=\"*.exe\"/>"); | ||
399 | ss.WriteLine(" <include name=\"*.mdb\" if='${build.debug}'/>"); | ||
400 | ss.WriteLine(" <include name=\"*.pdb\" if='${build.debug}'/>"); | ||
401 | ss.WriteLine(" </fileset>"); | ||
402 | ss.WriteLine(" </copy>"); | ||
403 | break; | ||
404 | } | ||
405 | } | ||
406 | |||
407 | ss.WriteLine(" </target>"); | ||
408 | |||
409 | ss.WriteLine(" <target name=\"clean\">"); | ||
410 | ss.WriteLine(" <delete dir=\"${bin.dir}\" failonerror=\"false\" />"); | ||
411 | ss.WriteLine(" <delete dir=\"${obj.dir}\" failonerror=\"false\" />"); | ||
412 | ss.WriteLine(" </target>"); | ||
413 | |||
414 | ss.WriteLine(" <target name=\"doc\" description=\"Creates documentation.\">"); | ||
415 | if (hasDoc) | ||
416 | { | ||
417 | ss.WriteLine(" <property name=\"doc.target\" value=\"\" />"); | ||
418 | ss.WriteLine(" <if test=\"${platform::is-unix()}\">"); | ||
419 | ss.WriteLine(" <property name=\"doc.target\" value=\"Web\" />"); | ||
420 | ss.WriteLine(" </if>"); | ||
421 | ss.WriteLine(" <ndoc failonerror=\"false\" verbose=\"true\">"); | ||
422 | ss.WriteLine(" <assemblies basedir=\"${project::get-base-directory()}\">"); | ||
423 | ss.Write(" <include name=\"${build.dir}/${project::get-name()}"); | ||
424 | if (project.Type == ProjectType.Library) | ||
425 | { | ||
426 | ss.WriteLine(".dll\" />"); | ||
427 | } | ||
428 | else | ||
429 | { | ||
430 | ss.WriteLine(".exe\" />"); | ||
431 | } | ||
432 | |||
433 | ss.WriteLine(" </assemblies>"); | ||
434 | ss.WriteLine(" <summaries basedir=\"${project::get-base-directory()}\">"); | ||
435 | ss.WriteLine(" <include name=\"${build.dir}/${project::get-name()}.xml\"/>"); | ||
436 | ss.WriteLine(" </summaries>"); | ||
437 | ss.WriteLine(" <referencepaths basedir=\"${project::get-base-directory()}\">"); | ||
438 | ss.WriteLine(" <include name=\"${build.dir}\" />"); | ||
439 | // foreach(ReferenceNode refr in project.References) | ||
440 | // { | ||
441 | // string path = Helper.NormalizePath(Helper.MakePathRelativeTo(project.FullPath, BuildReferencePath(solution, refr)), '/'); | ||
442 | // if (path != "") | ||
443 | // { | ||
444 | // ss.WriteLine(" <include name=\"{0}\" />", path); | ||
445 | // } | ||
446 | // } | ||
447 | ss.WriteLine(" </referencepaths>"); | ||
448 | ss.WriteLine(" <documenters>"); | ||
449 | ss.WriteLine(" <documenter name=\"MSDN\">"); | ||
450 | ss.WriteLine(" <property name=\"OutputDirectory\" value=\"${project::get-base-directory()}/${build.dir}/doc/${project::get-name()}\" />"); | ||
451 | ss.WriteLine(" <property name=\"OutputTarget\" value=\"${doc.target}\" />"); | ||
452 | ss.WriteLine(" <property name=\"HtmlHelpName\" value=\"${project::get-name()}\" />"); | ||
453 | ss.WriteLine(" <property name=\"IncludeFavorites\" value=\"False\" />"); | ||
454 | ss.WriteLine(" <property name=\"Title\" value=\"${project::get-name()} SDK Documentation\" />"); | ||
455 | ss.WriteLine(" <property name=\"SplitTOCs\" value=\"False\" />"); | ||
456 | ss.WriteLine(" <property name=\"DefaulTOC\" value=\"\" />"); | ||
457 | ss.WriteLine(" <property name=\"ShowVisualBasic\" value=\"True\" />"); | ||
458 | ss.WriteLine(" <property name=\"AutoDocumentConstructors\" value=\"True\" />"); | ||
459 | ss.WriteLine(" <property name=\"ShowMissingSummaries\" value=\"${build.debug}\" />"); | ||
460 | ss.WriteLine(" <property name=\"ShowMissingRemarks\" value=\"${build.debug}\" />"); | ||
461 | ss.WriteLine(" <property name=\"ShowMissingParams\" value=\"${build.debug}\" />"); | ||
462 | ss.WriteLine(" <property name=\"ShowMissingReturns\" value=\"${build.debug}\" />"); | ||
463 | ss.WriteLine(" <property name=\"ShowMissingValues\" value=\"${build.debug}\" />"); | ||
464 | ss.WriteLine(" <property name=\"DocumentInternals\" value=\"False\" />"); | ||
465 | ss.WriteLine(" <property name=\"DocumentPrivates\" value=\"False\" />"); | ||
466 | ss.WriteLine(" <property name=\"DocumentProtected\" value=\"True\" />"); | ||
467 | ss.WriteLine(" <property name=\"DocumentEmptyNamespaces\" value=\"${build.debug}\" />"); | ||
468 | ss.WriteLine(" <property name=\"IncludeAssemblyVersion\" value=\"True\" />"); | ||
469 | ss.WriteLine(" </documenter>"); | ||
470 | ss.WriteLine(" </documenters>"); | ||
471 | ss.WriteLine(" </ndoc>"); | ||
472 | } | ||
473 | ss.WriteLine(" </target>"); | ||
474 | ss.WriteLine("</project>"); | ||
475 | } | ||
476 | m_Kernel.CurrentWorkingDirectory.Pop(); | ||
477 | } | ||
478 | |||
479 | private void WriteCombine(SolutionNode solution) | ||
480 | { | ||
481 | m_Kernel.Log.Write("Creating NAnt build files"); | ||
482 | foreach (ProjectNode project in solution.Projects) | ||
483 | { | ||
484 | if (m_Kernel.AllowProject(project.FilterGroups)) | ||
485 | { | ||
486 | m_Kernel.Log.Write("...Creating project: {0}", project.Name); | ||
487 | WriteProject(solution, project); | ||
488 | } | ||
489 | } | ||
490 | |||
491 | m_Kernel.Log.Write(""); | ||
492 | string combFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "build"); | ||
493 | StreamWriter ss = new StreamWriter(combFile); | ||
494 | |||
495 | m_Kernel.CurrentWorkingDirectory.Push(); | ||
496 | Helper.SetCurrentDir(Path.GetDirectoryName(combFile)); | ||
497 | |||
498 | using (ss) | ||
499 | { | ||
500 | ss.WriteLine("<?xml version=\"1.0\" ?>"); | ||
501 | ss.WriteLine("<project name=\"{0}\" default=\"build\">", solution.Name); | ||
502 | ss.WriteLine(" <echo message=\"Using '${nant.settings.currentframework}' Framework\"/>"); | ||
503 | ss.WriteLine(); | ||
504 | |||
505 | //ss.WriteLine(" <property name=\"dist.dir\" value=\"dist\" />"); | ||
506 | //ss.WriteLine(" <property name=\"source.dir\" value=\"source\" />"); | ||
507 | ss.WriteLine(" <property name=\"bin.dir\" value=\"bin\" />"); | ||
508 | ss.WriteLine(" <property name=\"obj.dir\" value=\"obj\" />"); | ||
509 | ss.WriteLine(" <property name=\"doc.dir\" value=\"doc\" />"); | ||
510 | ss.WriteLine(" <property name=\"project.main.dir\" value=\"${project::get-base-directory()}\" />"); | ||
511 | |||
512 | // Use the active configuration, which is the first configuration name in the prebuild file. | ||
513 | Dictionary<string,string> emittedConfigurations = new Dictionary<string, string>(); | ||
514 | |||
515 | ss.WriteLine(" <property name=\"project.config\" value=\"{0}\" />", solution.ActiveConfig); | ||
516 | ss.WriteLine(); | ||
517 | |||
518 | foreach (ConfigurationNode conf in solution.Configurations) | ||
519 | { | ||
520 | // If the name isn't in the emitted configurations, we give a high level target to the | ||
521 | // platform specific on. This lets "Debug" point to "Debug-AnyCPU". | ||
522 | if (!emittedConfigurations.ContainsKey(conf.Name)) | ||
523 | { | ||
524 | // Add it to the dictionary so we only emit one. | ||
525 | emittedConfigurations.Add(conf.Name, conf.Platform); | ||
526 | |||
527 | // Write out the target block. | ||
528 | ss.WriteLine(" <target name=\"{0}\" description=\"{0}|{1}\" depends=\"{0}-{1}\">", conf.Name, conf.Platform); | ||
529 | ss.WriteLine(" </target>"); | ||
530 | ss.WriteLine(); | ||
531 | } | ||
532 | |||
533 | // Write out the target for the configuration. | ||
534 | ss.WriteLine(" <target name=\"{0}-{1}\" description=\"{0}|{1}\">", conf.Name, conf.Platform); | ||
535 | ss.WriteLine(" <property name=\"project.config\" value=\"{0}\" />", conf.Name); | ||
536 | ss.WriteLine(" <property name=\"build.debug\" value=\"{0}\" />", conf.Options["DebugInformation"].ToString().ToLower()); | ||
537 | ss.WriteLine("\t\t <property name=\"build.platform\" value=\"{0}\" />", conf.Platform); | ||
538 | ss.WriteLine(" </target>"); | ||
539 | ss.WriteLine(); | ||
540 | } | ||
541 | |||
542 | ss.WriteLine(" <target name=\"net-1.1\" description=\"Sets framework to .NET 1.1\">"); | ||
543 | ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"net-1.1\" />"); | ||
544 | ss.WriteLine(" </target>"); | ||
545 | ss.WriteLine(); | ||
546 | |||
547 | ss.WriteLine(" <target name=\"net-2.0\" description=\"Sets framework to .NET 2.0\">"); | ||
548 | ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"net-2.0\" />"); | ||
549 | ss.WriteLine(" </target>"); | ||
550 | ss.WriteLine(); | ||
551 | |||
552 | ss.WriteLine(" <target name=\"net-3.5\" description=\"Sets framework to .NET 3.5\">"); | ||
553 | ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"net-3.5\" />"); | ||
554 | ss.WriteLine(" </target>"); | ||
555 | ss.WriteLine(); | ||
556 | |||
557 | ss.WriteLine(" <target name=\"mono-1.0\" description=\"Sets framework to mono 1.0\">"); | ||
558 | ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"mono-1.0\" />"); | ||
559 | ss.WriteLine(" </target>"); | ||
560 | ss.WriteLine(); | ||
561 | |||
562 | ss.WriteLine(" <target name=\"mono-2.0\" description=\"Sets framework to mono 2.0\">"); | ||
563 | ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"mono-2.0\" />"); | ||
564 | ss.WriteLine(" </target>"); | ||
565 | ss.WriteLine(); | ||
566 | |||
567 | ss.WriteLine(" <target name=\"mono-3.5\" description=\"Sets framework to mono 3.5\">"); | ||
568 | ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"mono-3.5\" />"); | ||
569 | ss.WriteLine(" </target>"); | ||
570 | ss.WriteLine(); | ||
571 | |||
572 | ss.WriteLine(" <target name=\"init\" description=\"\">"); | ||
573 | ss.WriteLine(" <call target=\"${project.config}\" />"); | ||
574 | ss.WriteLine(" <property name=\"sys.os.platform\""); | ||
575 | ss.WriteLine(" value=\"${platform::get-name()}\""); | ||
576 | ss.WriteLine(" />"); | ||
577 | ss.WriteLine(" <echo message=\"Platform ${sys.os.platform}\" />"); | ||
578 | ss.WriteLine(" <property name=\"build.dir\" value=\"${bin.dir}/${project.config}\" />"); | ||
579 | ss.WriteLine(" </target>"); | ||
580 | ss.WriteLine(); | ||
581 | |||
582 | |||
583 | // sdague - ok, this is an ugly hack, but what it lets | ||
584 | // us do is native include of files into the nant | ||
585 | // created files from all .nant/*include files. This | ||
586 | // lets us keep using prebuild, but allows for | ||
587 | // extended nant targets to do build and the like. | ||
588 | |||
589 | try | ||
590 | { | ||
591 | Regex re = new Regex(".include$"); | ||
592 | DirectoryInfo nantdir = new DirectoryInfo(".nant"); | ||
593 | foreach (FileSystemInfo item in nantdir.GetFileSystemInfos()) | ||
594 | { | ||
595 | if (item is DirectoryInfo) { } | ||
596 | else if (item is FileInfo) | ||
597 | { | ||
598 | if (re.Match(item.FullName) != | ||
599 | System.Text.RegularExpressions.Match.Empty) | ||
600 | { | ||
601 | Console.WriteLine("Including file: " + item.FullName); | ||
602 | |||
603 | using (FileStream fs = new FileStream(item.FullName, | ||
604 | FileMode.Open, | ||
605 | FileAccess.Read, | ||
606 | FileShare.None)) | ||
607 | { | ||
608 | using (StreamReader sr = new StreamReader(fs)) | ||
609 | { | ||
610 | ss.WriteLine("<!-- included from {0} -->", (item).FullName); | ||
611 | while (sr.Peek() != -1) | ||
612 | { | ||
613 | ss.WriteLine(sr.ReadLine()); | ||
614 | } | ||
615 | ss.WriteLine(); | ||
616 | } | ||
617 | } | ||
618 | } | ||
619 | } | ||
620 | } | ||
621 | } | ||
622 | catch { } | ||
623 | // ss.WriteLine(" <include buildfile=\".nant/local.include\" />"); | ||
624 | // ss.WriteLine(" <target name=\"zip\" description=\"\">"); | ||
625 | // ss.WriteLine(" <zip zipfile=\"{0}-{1}.zip\">", solution.Name, solution.Version); | ||
626 | // ss.WriteLine(" <fileset basedir=\"${project::get-base-directory()}\">"); | ||
627 | |||
628 | // ss.WriteLine(" <include name=\"${project::get-base-directory()}/**/*.cs\" />"); | ||
629 | // // ss.WriteLine(" <include name=\"${project.main.dir}/**/*\" />"); | ||
630 | // ss.WriteLine(" </fileset>"); | ||
631 | // ss.WriteLine(" </zip>"); | ||
632 | // ss.WriteLine(" <echo message=\"Building zip target\" />"); | ||
633 | // ss.WriteLine(" </target>"); | ||
634 | ss.WriteLine(); | ||
635 | |||
636 | |||
637 | ss.WriteLine(" <target name=\"clean\" description=\"\">"); | ||
638 | ss.WriteLine(" <echo message=\"Deleting all builds from all configurations\" />"); | ||
639 | //ss.WriteLine(" <delete dir=\"${dist.dir}\" failonerror=\"false\" />"); | ||
640 | |||
641 | // justincc: FIXME FIXME FIXME - A temporary OpenSim hack to clean up files when "nant clean" is executed. | ||
642 | // Should be replaced with extreme prejudice once anybody finds out if the CleanFiles stuff works or there is | ||
643 | // another working mechanism for specifying this stuff | ||
644 | ss.WriteLine(" <delete failonerror=\"false\">"); | ||
645 | ss.WriteLine(" <fileset basedir=\"${bin.dir}\">"); | ||
646 | ss.WriteLine(" <include name=\"OpenSim*.dll\"/>"); | ||
647 | ss.WriteLine(" <include name=\"OpenSim*.exe\"/>"); | ||
648 | ss.WriteLine(" <include name=\"ScriptEngines/*\"/>"); | ||
649 | ss.WriteLine(" <include name=\"Physics/*\"/>"); | ||
650 | ss.WriteLine(" <exclude name=\"OpenSim.32BitLaunch.exe\"/>"); | ||
651 | ss.WriteLine(" <exclude name=\"ScriptEngines/Default.lsl\"/>"); | ||
652 | ss.WriteLine(" </fileset>"); | ||
653 | ss.WriteLine(" </delete>"); | ||
654 | |||
655 | if (solution.Cleanup != null && solution.Cleanup.CleanFiles.Count > 0) | ||
656 | { | ||
657 | foreach (CleanFilesNode cleanFile in solution.Cleanup.CleanFiles) | ||
658 | { | ||
659 | ss.WriteLine(" <delete failonerror=\"false\">"); | ||
660 | ss.WriteLine(" <fileset basedir=\"${project::get-base-directory()}\">"); | ||
661 | ss.WriteLine(" <include name=\"{0}/*\"/>", cleanFile.Pattern); | ||
662 | ss.WriteLine(" <include name=\"{0}\"/>", cleanFile.Pattern); | ||
663 | ss.WriteLine(" </fileset>"); | ||
664 | ss.WriteLine(" </delete>"); | ||
665 | } | ||
666 | } | ||
667 | |||
668 | ss.WriteLine(" <delete dir=\"${obj.dir}\" failonerror=\"false\" />"); | ||
669 | foreach (ProjectNode project in solution.Projects) | ||
670 | { | ||
671 | string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath); | ||
672 | ss.Write(" <nant buildfile=\"{0}\"", | ||
673 | Helper.NormalizePath(Helper.MakeFilePath(path, project.Name + GetProjectExtension(project), "build"), '/')); | ||
674 | ss.WriteLine(" target=\"clean\" />"); | ||
675 | } | ||
676 | ss.WriteLine(" </target>"); | ||
677 | ss.WriteLine(); | ||
678 | |||
679 | ss.WriteLine(" <target name=\"build\" depends=\"init\" description=\"\">"); | ||
680 | |||
681 | foreach (ProjectNode project in solution.ProjectsTableOrder) | ||
682 | { | ||
683 | string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath); | ||
684 | ss.Write(" <nant buildfile=\"{0}\"", | ||
685 | Helper.NormalizePath(Helper.MakeFilePath(path, project.Name + GetProjectExtension(project), "build"), '/')); | ||
686 | ss.WriteLine(" target=\"build\" />"); | ||
687 | } | ||
688 | ss.WriteLine(" </target>"); | ||
689 | ss.WriteLine(); | ||
690 | |||
691 | ss.WriteLine(" <target name=\"build-release\" depends=\"Release, init, build\" description=\"Builds in Release mode\" />"); | ||
692 | ss.WriteLine(); | ||
693 | ss.WriteLine(" <target name=\"build-debug\" depends=\"Debug, init, build\" description=\"Builds in Debug mode\" />"); | ||
694 | ss.WriteLine(); | ||
695 | //ss.WriteLine(" <target name=\"package\" depends=\"clean, doc, copyfiles, zip\" description=\"Builds in Release mode\" />"); | ||
696 | ss.WriteLine(" <target name=\"package\" depends=\"clean, doc\" description=\"Builds all\" />"); | ||
697 | ss.WriteLine(); | ||
698 | |||
699 | ss.WriteLine(" <target name=\"doc\" depends=\"build-release\">"); | ||
700 | ss.WriteLine(" <echo message=\"Generating all documentation from all builds\" />"); | ||
701 | foreach (ProjectNode project in solution.Projects) | ||
702 | { | ||
703 | string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath); | ||
704 | ss.Write(" <nant buildfile=\"{0}\"", | ||
705 | Helper.NormalizePath(Helper.MakeFilePath(path, project.Name + GetProjectExtension(project), "build"), '/')); | ||
706 | ss.WriteLine(" target=\"doc\" />"); | ||
707 | } | ||
708 | ss.WriteLine(" </target>"); | ||
709 | ss.WriteLine(); | ||
710 | ss.WriteLine("</project>"); | ||
711 | } | ||
712 | |||
713 | m_Kernel.CurrentWorkingDirectory.Pop(); | ||
714 | } | ||
715 | |||
716 | private void CleanProject(ProjectNode project) | ||
717 | { | ||
718 | m_Kernel.Log.Write("...Cleaning project: {0}", project.Name); | ||
719 | string projectFile = Helper.MakeFilePath(project.FullPath, project.Name + GetProjectExtension(project), "build"); | ||
720 | Helper.DeleteIfExists(projectFile); | ||
721 | } | ||
722 | |||
723 | private void CleanSolution(SolutionNode solution) | ||
724 | { | ||
725 | m_Kernel.Log.Write("Cleaning NAnt build files for", solution.Name); | ||
726 | |||
727 | string slnFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "build"); | ||
728 | Helper.DeleteIfExists(slnFile); | ||
729 | |||
730 | foreach (ProjectNode project in solution.Projects) | ||
731 | { | ||
732 | CleanProject(project); | ||
733 | } | ||
734 | |||
735 | m_Kernel.Log.Write(""); | ||
736 | } | ||
737 | |||
738 | #endregion | ||
739 | |||
740 | #region ITarget Members | ||
741 | |||
742 | /// <summary> | ||
743 | /// Writes the specified kern. | ||
744 | /// </summary> | ||
745 | /// <param name="kern">The kern.</param> | ||
746 | public void Write(Kernel kern) | ||
747 | { | ||
748 | if (kern == null) | ||
749 | { | ||
750 | throw new ArgumentNullException("kern"); | ||
751 | } | ||
752 | m_Kernel = kern; | ||
753 | foreach (SolutionNode solution in kern.Solutions) | ||
754 | { | ||
755 | WriteCombine(solution); | ||
756 | } | ||
757 | m_Kernel = null; | ||
758 | } | ||
759 | |||
760 | /// <summary> | ||
761 | /// Cleans the specified kern. | ||
762 | /// </summary> | ||
763 | /// <param name="kern">The kern.</param> | ||
764 | public virtual void Clean(Kernel kern) | ||
765 | { | ||
766 | if (kern == null) | ||
767 | { | ||
768 | throw new ArgumentNullException("kern"); | ||
769 | } | ||
770 | m_Kernel = kern; | ||
771 | foreach (SolutionNode sol in kern.Solutions) | ||
772 | { | ||
773 | CleanSolution(sol); | ||
774 | } | ||
775 | m_Kernel = null; | ||
776 | } | ||
777 | |||
778 | /// <summary> | ||
779 | /// Gets the name. | ||
780 | /// </summary> | ||
781 | /// <value>The name.</value> | ||
782 | public string Name | ||
783 | { | ||
784 | get | ||
785 | { | ||
786 | return "nant"; | ||
787 | } | ||
788 | } | ||
789 | |||
790 | #endregion | ||
791 | } | ||
792 | } | ||