diff options
author | Justin Clark-Casey (justincc) | 2010-09-11 01:13:08 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2010-09-11 01:13:08 +0100 |
commit | 7e65590a55ba575d0086bdfc25addaf1051d799b (patch) | |
tree | 1dc11683170d45d80d7aab6eefdfcc836d3e773b /Prebuild/src/Core/Targets/SharpDevelopTarget.cs | |
parent | Make it clear that the "create region" command will reference ini files in th... (diff) | |
download | opensim-SC_OLD-7e65590a55ba575d0086bdfc25addaf1051d799b.zip opensim-SC_OLD-7e65590a55ba575d0086bdfc25addaf1051d799b.tar.gz opensim-SC_OLD-7e65590a55ba575d0086bdfc25addaf1051d799b.tar.bz2 opensim-SC_OLD-7e65590a55ba575d0086bdfc25addaf1051d799b.tar.xz |
Update Prebuild.exe with Prebuild r323 + an existing OpenSim specific nant hack to correctly clean up chosen OpenSim exes and dlls in bin/ on a "nant clean"
Source code is included for reference. This can go away again once Prebuild is updated with a more general mechanism for cleaning up files.
The Prebuild source code here can be built with nant, or regnerated for other tools using the prebuild at {root}/bin/Prebuild.exe
Diffstat (limited to 'Prebuild/src/Core/Targets/SharpDevelopTarget.cs')
-rw-r--r-- | Prebuild/src/Core/Targets/SharpDevelopTarget.cs | 425 |
1 files changed, 425 insertions, 0 deletions
diff --git a/Prebuild/src/Core/Targets/SharpDevelopTarget.cs b/Prebuild/src/Core/Targets/SharpDevelopTarget.cs new file mode 100644 index 0000000..8e32050 --- /dev/null +++ b/Prebuild/src/Core/Targets/SharpDevelopTarget.cs | |||
@@ -0,0 +1,425 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | using System; | ||
27 | using System.IO; | ||
28 | using System.Text.RegularExpressions; | ||
29 | |||
30 | using Prebuild.Core.Attributes; | ||
31 | using Prebuild.Core.Interfaces; | ||
32 | using Prebuild.Core.Nodes; | ||
33 | using Prebuild.Core.Utilities; | ||
34 | |||
35 | namespace Prebuild.Core.Targets | ||
36 | { | ||
37 | /// <summary> | ||
38 | /// | ||
39 | /// </summary> | ||
40 | [Target("sharpdev")] | ||
41 | public class SharpDevelopTarget : ITarget | ||
42 | { | ||
43 | #region Fields | ||
44 | |||
45 | private Kernel m_Kernel; | ||
46 | |||
47 | #endregion | ||
48 | |||
49 | #region Private Methods | ||
50 | |||
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 | |||
65 | return tmpPath; | ||
66 | } | ||
67 | |||
68 | private static string BuildReference(SolutionNode solution, ReferenceNode refr) | ||
69 | { | ||
70 | string ret = "<Reference type=\""; | ||
71 | if(solution.ProjectsTable.ContainsKey(refr.Name)) | ||
72 | { | ||
73 | ret += "Project\" refto=\"" + refr.Name; | ||
74 | ret += "\" localcopy=\"" + refr.LocalCopy.ToString() + "\" />"; | ||
75 | } | ||
76 | else | ||
77 | { | ||
78 | ProjectNode project = (ProjectNode)refr.Parent; | ||
79 | string fileRef = FindFileReference(refr.Name, project); | ||
80 | |||
81 | if(refr.Path != null || fileRef != null) | ||
82 | { | ||
83 | ret += "Assembly\" refto=\""; | ||
84 | |||
85 | string finalPath = (refr.Path != null) ? Helper.MakeFilePath(refr.Path, refr.Name, "dll") : fileRef; | ||
86 | |||
87 | ret += finalPath; | ||
88 | ret += "\" localcopy=\"" + refr.LocalCopy.ToString() + "\" />"; | ||
89 | return ret; | ||
90 | } | ||
91 | |||
92 | ret += "Gac\" refto=\""; | ||
93 | try | ||
94 | { | ||
95 | //Assembly assem = Assembly.Load(refr.Name); | ||
96 | ret += refr.Name;// assem.FullName; | ||
97 | } | ||
98 | catch (System.NullReferenceException e) | ||
99 | { | ||
100 | e.ToString(); | ||
101 | ret += refr.Name; | ||
102 | } | ||
103 | ret += "\" localcopy=\"" + refr.LocalCopy.ToString() + "\" />"; | ||
104 | } | ||
105 | |||
106 | return ret; | ||
107 | } | ||
108 | |||
109 | private static string FindFileReference(string refName, ProjectNode project) | ||
110 | { | ||
111 | foreach(ReferencePathNode refPath in project.ReferencePaths) | ||
112 | { | ||
113 | string fullPath = Helper.MakeFilePath(refPath.Path, refName, "dll"); | ||
114 | |||
115 | if(File.Exists(fullPath)) | ||
116 | { | ||
117 | return fullPath; | ||
118 | } | ||
119 | } | ||
120 | |||
121 | return null; | ||
122 | } | ||
123 | |||
124 | /// <summary> | ||
125 | /// Gets the XML doc file. | ||
126 | /// </summary> | ||
127 | /// <param name="project">The project.</param> | ||
128 | /// <param name="conf">The conf.</param> | ||
129 | /// <returns></returns> | ||
130 | public static string GenerateXmlDocFile(ProjectNode project, ConfigurationNode conf) | ||
131 | { | ||
132 | if( conf == null ) | ||
133 | { | ||
134 | throw new ArgumentNullException("conf"); | ||
135 | } | ||
136 | if( project == null ) | ||
137 | { | ||
138 | throw new ArgumentNullException("project"); | ||
139 | } | ||
140 | string docFile = (string)conf.Options["XmlDocFile"]; | ||
141 | if(docFile != null && docFile.Length == 0)//default to assembly name if not specified | ||
142 | { | ||
143 | return "False"; | ||
144 | } | ||
145 | return "True"; | ||
146 | } | ||
147 | |||
148 | private void WriteProject(SolutionNode solution, ProjectNode project) | ||
149 | { | ||
150 | string csComp = "Csc"; | ||
151 | string netRuntime = "MsNet"; | ||
152 | if(project.Runtime == ClrRuntime.Mono) | ||
153 | { | ||
154 | csComp = "Mcs"; | ||
155 | netRuntime = "Mono"; | ||
156 | } | ||
157 | |||
158 | string projFile = Helper.MakeFilePath(project.FullPath, project.Name, "prjx"); | ||
159 | StreamWriter ss = new StreamWriter(projFile); | ||
160 | |||
161 | m_Kernel.CurrentWorkingDirectory.Push(); | ||
162 | Helper.SetCurrentDir(Path.GetDirectoryName(projFile)); | ||
163 | |||
164 | using(ss) | ||
165 | { | ||
166 | ss.WriteLine( | ||
167 | "<Project name=\"{0}\" standardNamespace=\"{1}\" description=\"\" newfilesearch=\"None\" enableviewstate=\"True\" version=\"1.1\" projecttype=\"C#\">", | ||
168 | project.Name, | ||
169 | project.RootNamespace | ||
170 | ); | ||
171 | |||
172 | ss.WriteLine(" <Contents>"); | ||
173 | foreach(string file in project.Files) | ||
174 | { | ||
175 | string buildAction = "Compile"; | ||
176 | switch(project.Files.GetBuildAction(file)) | ||
177 | { | ||
178 | case BuildAction.None: | ||
179 | buildAction = "Nothing"; | ||
180 | break; | ||
181 | |||
182 | case BuildAction.Content: | ||
183 | buildAction = "Exclude"; | ||
184 | break; | ||
185 | |||
186 | case BuildAction.EmbeddedResource: | ||
187 | buildAction = "EmbedAsResource"; | ||
188 | break; | ||
189 | |||
190 | default: | ||
191 | buildAction = "Compile"; | ||
192 | break; | ||
193 | } | ||
194 | |||
195 | // Sort of a hack, we try and resolve the path and make it relative, if we can. | ||
196 | string filePath = PrependPath(file); | ||
197 | ss.WriteLine(" <File name=\"{0}\" subtype=\"Code\" buildaction=\"{1}\" dependson=\"\" data=\"\" />", filePath, buildAction); | ||
198 | } | ||
199 | ss.WriteLine(" </Contents>"); | ||
200 | |||
201 | ss.WriteLine(" <References>"); | ||
202 | foreach(ReferenceNode refr in project.References) | ||
203 | { | ||
204 | ss.WriteLine(" {0}", BuildReference(solution, refr)); | ||
205 | } | ||
206 | ss.WriteLine(" </References>"); | ||
207 | |||
208 | ss.Write(" <DeploymentInformation"); | ||
209 | ss.Write(" target=\"\""); | ||
210 | ss.Write(" script=\"\""); | ||
211 | ss.Write(" strategy=\"File\""); | ||
212 | ss.WriteLine(" />"); | ||
213 | |||
214 | int count = 0; | ||
215 | |||
216 | ss.WriteLine(" <Configurations active=\"{0}\">", solution.ActiveConfig); | ||
217 | |||
218 | foreach(ConfigurationNode conf in project.Configurations) | ||
219 | { | ||
220 | ss.Write(" <Configuration"); | ||
221 | ss.Write(" runwithwarnings=\"True\""); | ||
222 | ss.Write(" name=\"{0}\"", conf.Name); | ||
223 | ss.WriteLine(">"); | ||
224 | ss.Write(" <CodeGeneration"); | ||
225 | ss.Write(" runtime=\"{0}\"", netRuntime); | ||
226 | ss.Write(" compiler=\"{0}\"", csComp); | ||
227 | ss.Write(" compilerversion=\"\""); | ||
228 | ss.Write(" warninglevel=\"{0}\"", conf.Options["WarningLevel"]); | ||
229 | ss.Write(" nowarn=\"{0}\"", conf.Options["SuppressWarnings"]); | ||
230 | ss.Write(" includedebuginformation=\"{0}\"", conf.Options["DebugInformation"]); | ||
231 | ss.Write(" optimize=\"{0}\"", conf.Options["OptimizeCode"]); | ||
232 | ss.Write(" unsafecodeallowed=\"{0}\"", conf.Options["AllowUnsafe"]); | ||
233 | ss.Write(" generateoverflowchecks=\"{0}\"", conf.Options["CheckUnderflowOverflow"]); | ||
234 | ss.Write(" mainclass=\"{0}\"", project.StartupObject); | ||
235 | ss.Write(" target=\"{0}\"", project.Type); | ||
236 | ss.Write(" definesymbols=\"{0}\"", conf.Options["CompilerDefines"]); | ||
237 | ss.Write(" generatexmldocumentation=\"{0}\"", GenerateXmlDocFile(project, conf)); | ||
238 | ss.Write(" win32Icon=\"{0}\"", Helper.NormalizePath(".\\" + project.AppIcon)); | ||
239 | ss.Write(" noconfig=\"{0}\"", "False"); | ||
240 | ss.Write(" nostdlib=\"{0}\"", conf.Options["NoStdLib"]); | ||
241 | ss.WriteLine(" />"); | ||
242 | |||
243 | ss.Write(" <Execution"); | ||
244 | ss.Write(" commandlineparameters=\"\""); | ||
245 | ss.Write(" consolepause=\"True\""); | ||
246 | ss.WriteLine(" />"); | ||
247 | |||
248 | ss.Write(" <Output"); | ||
249 | ss.Write(" directory=\".\\{0}\"", Helper.NormalizePath(conf.Options["OutputPath"].ToString())); | ||
250 | ss.Write(" assembly=\"{0}\"", project.AssemblyName); | ||
251 | ss.Write(" executeScript=\"{0}\"", conf.Options["RunScript"]); | ||
252 | if (conf.Options["PreBuildEvent"] != null && conf.Options["PreBuildEvent"].ToString().Length != 0) | ||
253 | { | ||
254 | ss.Write(" executeBeforeBuild=\"{0}\"", Helper.NormalizePath(conf.Options["PreBuildEvent"].ToString())); | ||
255 | } | ||
256 | else | ||
257 | { | ||
258 | ss.Write(" executeBeforeBuild=\"{0}\"", conf.Options["PreBuildEvent"]); | ||
259 | } | ||
260 | if (conf.Options["PostBuildEvent"] != null && conf.Options["PostBuildEvent"].ToString().Length != 0) | ||
261 | { | ||
262 | ss.Write(" executeAfterBuild=\"{0}\"", Helper.NormalizePath(conf.Options["PostBuildEvent"].ToString())); | ||
263 | } | ||
264 | else | ||
265 | { | ||
266 | ss.Write(" executeAfterBuild=\"{0}\"", conf.Options["PostBuildEvent"]); | ||
267 | } | ||
268 | ss.Write(" executeBeforeBuildArguments=\"{0}\"", conf.Options["PreBuildEventArgs"]); | ||
269 | ss.Write(" executeAfterBuildArguments=\"{0}\"", conf.Options["PreBuildEventArgs"]); | ||
270 | ss.WriteLine(" />"); | ||
271 | ss.WriteLine(" </Configuration>"); | ||
272 | |||
273 | count++; | ||
274 | } | ||
275 | ss.WriteLine(" </Configurations>"); | ||
276 | ss.WriteLine("</Project>"); | ||
277 | } | ||
278 | |||
279 | m_Kernel.CurrentWorkingDirectory.Pop(); | ||
280 | } | ||
281 | |||
282 | private void WriteCombine(SolutionNode solution) | ||
283 | { | ||
284 | m_Kernel.Log.Write("Creating SharpDevelop combine and project files"); | ||
285 | foreach(ProjectNode project in solution.Projects) | ||
286 | { | ||
287 | if(m_Kernel.AllowProject(project.FilterGroups)) | ||
288 | { | ||
289 | m_Kernel.Log.Write("...Creating project: {0}", project.Name); | ||
290 | WriteProject(solution, project); | ||
291 | } | ||
292 | } | ||
293 | |||
294 | m_Kernel.Log.Write(""); | ||
295 | string combFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "cmbx"); | ||
296 | StreamWriter ss = new StreamWriter(combFile); | ||
297 | |||
298 | m_Kernel.CurrentWorkingDirectory.Push(); | ||
299 | Helper.SetCurrentDir(Path.GetDirectoryName(combFile)); | ||
300 | |||
301 | using(ss) | ||
302 | { | ||
303 | ss.WriteLine("<Combine fileversion=\"1.0\" name=\"{0}\" description=\"\">", solution.Name); | ||
304 | |||
305 | int count = 0; | ||
306 | foreach(ProjectNode project in solution.Projects) | ||
307 | { | ||
308 | if(count == 0) | ||
309 | ss.WriteLine(" <StartMode startupentry=\"{0}\" single=\"True\">", project.Name); | ||
310 | |||
311 | ss.WriteLine(" <Execute entry=\"{0}\" type=\"None\" />", project.Name); | ||
312 | count++; | ||
313 | } | ||
314 | ss.WriteLine(" </StartMode>"); | ||
315 | |||
316 | ss.WriteLine(" <Entries>"); | ||
317 | foreach(ProjectNode project in solution.Projects) | ||
318 | { | ||
319 | string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath); | ||
320 | ss.WriteLine(" <Entry filename=\"{0}\" />", | ||
321 | Helper.MakeFilePath(path, project.Name, "prjx")); | ||
322 | } | ||
323 | ss.WriteLine(" </Entries>"); | ||
324 | |||
325 | count = 0; | ||
326 | foreach(ConfigurationNode conf in solution.Configurations) | ||
327 | { | ||
328 | if(count == 0) | ||
329 | { | ||
330 | ss.WriteLine(" <Configurations active=\"{0}\">", conf.Name); | ||
331 | } | ||
332 | |||
333 | ss.WriteLine(" <Configuration name=\"{0}\">", conf.Name); | ||
334 | foreach(ProjectNode project in solution.Projects) | ||
335 | { | ||
336 | ss.WriteLine(" <Entry name=\"{0}\" configurationname=\"{1}\" build=\"True\" />", project.Name, conf.Name); | ||
337 | } | ||
338 | ss.WriteLine(" </Configuration>"); | ||
339 | |||
340 | count++; | ||
341 | } | ||
342 | ss.WriteLine(" </Configurations>"); | ||
343 | ss.WriteLine("</Combine>"); | ||
344 | } | ||
345 | |||
346 | m_Kernel.CurrentWorkingDirectory.Pop(); | ||
347 | } | ||
348 | |||
349 | private void CleanProject(ProjectNode project) | ||
350 | { | ||
351 | m_Kernel.Log.Write("...Cleaning project: {0}", project.Name); | ||
352 | string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, "prjx"); | ||
353 | Helper.DeleteIfExists(projectFile); | ||
354 | } | ||
355 | |||
356 | private void CleanSolution(SolutionNode solution) | ||
357 | { | ||
358 | m_Kernel.Log.Write("Cleaning SharpDevelop combine and project files for", solution.Name); | ||
359 | |||
360 | string slnFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "cmbx"); | ||
361 | Helper.DeleteIfExists(slnFile); | ||
362 | |||
363 | foreach(ProjectNode project in solution.Projects) | ||
364 | { | ||
365 | CleanProject(project); | ||
366 | } | ||
367 | |||
368 | m_Kernel.Log.Write(""); | ||
369 | } | ||
370 | |||
371 | #endregion | ||
372 | |||
373 | #region ITarget Members | ||
374 | |||
375 | /// <summary> | ||
376 | /// Writes the specified kern. | ||
377 | /// </summary> | ||
378 | /// <param name="kern">The kern.</param> | ||
379 | public void Write(Kernel kern) | ||
380 | { | ||
381 | if( kern == null ) | ||
382 | { | ||
383 | throw new ArgumentNullException("kern"); | ||
384 | } | ||
385 | m_Kernel = kern; | ||
386 | foreach(SolutionNode solution in kern.Solutions) | ||
387 | { | ||
388 | WriteCombine(solution); | ||
389 | } | ||
390 | m_Kernel = null; | ||
391 | } | ||
392 | |||
393 | /// <summary> | ||
394 | /// Cleans the specified kern. | ||
395 | /// </summary> | ||
396 | /// <param name="kern">The kern.</param> | ||
397 | public virtual void Clean(Kernel kern) | ||
398 | { | ||
399 | if( kern == null ) | ||
400 | { | ||
401 | throw new ArgumentNullException("kern"); | ||
402 | } | ||
403 | m_Kernel = kern; | ||
404 | foreach(SolutionNode sol in kern.Solutions) | ||
405 | { | ||
406 | CleanSolution(sol); | ||
407 | } | ||
408 | m_Kernel = null; | ||
409 | } | ||
410 | |||
411 | /// <summary> | ||
412 | /// Gets the name. | ||
413 | /// </summary> | ||
414 | /// <value>The name.</value> | ||
415 | public string Name | ||
416 | { | ||
417 | get | ||
418 | { | ||
419 | return "sharpdev"; | ||
420 | } | ||
421 | } | ||
422 | |||
423 | #endregion | ||
424 | } | ||
425 | } | ||