diff options
Diffstat (limited to 'Prebuild/src/Core/Targets/MonoDevelopTarget.cs')
-rw-r--r-- | Prebuild/src/Core/Targets/MonoDevelopTarget.cs | 464 |
1 files changed, 0 insertions, 464 deletions
diff --git a/Prebuild/src/Core/Targets/MonoDevelopTarget.cs b/Prebuild/src/Core/Targets/MonoDevelopTarget.cs deleted file mode 100644 index c8401fd..0000000 --- a/Prebuild/src/Core/Targets/MonoDevelopTarget.cs +++ /dev/null | |||
@@ -1,464 +0,0 @@ | |||
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.Collections; | ||
28 | using System.Collections.Specialized; | ||
29 | using System.IO; | ||
30 | using System.Reflection; | ||
31 | using System.Text.RegularExpressions; | ||
32 | |||
33 | using Prebuild.Core.Attributes; | ||
34 | using Prebuild.Core.Interfaces; | ||
35 | using Prebuild.Core.Nodes; | ||
36 | using Prebuild.Core.Utilities; | ||
37 | |||
38 | namespace Prebuild.Core.Targets | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// | ||
42 | /// </summary> | ||
43 | [Target("monodev")] | ||
44 | public class MonoDevelopTarget : ITarget | ||
45 | { | ||
46 | #region Fields | ||
47 | |||
48 | private Kernel m_Kernel; | ||
49 | |||
50 | #endregion | ||
51 | |||
52 | #region Private Methods | ||
53 | |||
54 | private static string PrependPath(string path) | ||
55 | { | ||
56 | string tmpPath = Helper.NormalizePath(path, '/'); | ||
57 | Regex regex = new Regex(@"(\w):/(\w+)"); | ||
58 | Match match = regex.Match(tmpPath); | ||
59 | if(match.Success || tmpPath[0] == '.' || tmpPath[0] == '/') | ||
60 | { | ||
61 | tmpPath = Helper.NormalizePath(tmpPath); | ||
62 | } | ||
63 | else | ||
64 | { | ||
65 | tmpPath = Helper.NormalizePath("./" + tmpPath); | ||
66 | } | ||
67 | |||
68 | return tmpPath; | ||
69 | } | ||
70 | |||
71 | private static string BuildReference(SolutionNode solution, ReferenceNode refr) | ||
72 | { | ||
73 | string ret = "<ProjectReference type=\""; | ||
74 | if(solution.ProjectsTable.ContainsKey(refr.Name)) | ||
75 | { | ||
76 | ret += "Project\""; | ||
77 | ret += " localcopy=\"" + refr.LocalCopy.ToString() + "\" refto=\"" + refr.Name + "\" />"; | ||
78 | } | ||
79 | else | ||
80 | { | ||
81 | ProjectNode project = (ProjectNode)refr.Parent; | ||
82 | string fileRef = FindFileReference(refr.Name, project); | ||
83 | |||
84 | if(refr.Path != null || fileRef != null) | ||
85 | { | ||
86 | ret += "Assembly\" refto=\""; | ||
87 | |||
88 | string finalPath = (refr.Path != null) ? Helper.MakeFilePath(refr.Path, refr.Name, "dll") : fileRef; | ||
89 | |||
90 | ret += finalPath; | ||
91 | ret += "\" localcopy=\"" + refr.LocalCopy.ToString() + "\" />"; | ||
92 | return ret; | ||
93 | } | ||
94 | |||
95 | ret += "Gac\""; | ||
96 | ret += " localcopy=\"" + refr.LocalCopy.ToString() + "\""; | ||
97 | ret += " refto=\""; | ||
98 | try | ||
99 | { | ||
100 | /* | ||
101 | Day changed to 28 Mar 2007 | ||
102 | ... | ||
103 | 08:09 < cj> is there anything that replaces Assembly.LoadFromPartialName() ? | ||
104 | 08:09 < jonp> no | ||
105 | 08:10 < jonp> in their infinite wisdom [sic], microsoft decided that the | ||
106 | ability to load any assembly version by-name was an inherently | ||
107 | bad idea | ||
108 | 08:11 < cj> I'm thinking of a bunch of four-letter words right now... | ||
109 | 08:11 < cj> security through making it difficult for the developer!!! | ||
110 | 08:12 < jonp> just use the Obsolete API | ||
111 | 08:12 < jonp> it should still work | ||
112 | 08:12 < cj> alrighty. | ||
113 | 08:12 < jonp> you just get warnings when using it | ||
114 | */ | ||
115 | Assembly assem = Assembly.LoadWithPartialName(refr.Name); | ||
116 | ret += assem.FullName; | ||
117 | //ret += refr.Name; | ||
118 | } | ||
119 | catch (System.NullReferenceException e) | ||
120 | { | ||
121 | e.ToString(); | ||
122 | ret += refr.Name; | ||
123 | } | ||
124 | ret += "\" />"; | ||
125 | } | ||
126 | |||
127 | return ret; | ||
128 | } | ||
129 | |||
130 | private static string FindFileReference(string refName, ProjectNode project) | ||
131 | { | ||
132 | foreach(ReferencePathNode refPath in project.ReferencePaths) | ||
133 | { | ||
134 | string fullPath = Helper.MakeFilePath(refPath.Path, refName, "dll"); | ||
135 | |||
136 | if(File.Exists(fullPath)) | ||
137 | { | ||
138 | return fullPath; | ||
139 | } | ||
140 | } | ||
141 | |||
142 | return null; | ||
143 | } | ||
144 | |||
145 | /// <summary> | ||
146 | /// Gets the XML doc file. | ||
147 | /// </summary> | ||
148 | /// <param name="project">The project.</param> | ||
149 | /// <param name="conf">The conf.</param> | ||
150 | /// <returns></returns> | ||
151 | public static string GenerateXmlDocFile(ProjectNode project, ConfigurationNode conf) | ||
152 | { | ||
153 | if( conf == null ) | ||
154 | { | ||
155 | throw new ArgumentNullException("conf"); | ||
156 | } | ||
157 | if( project == null ) | ||
158 | { | ||
159 | throw new ArgumentNullException("project"); | ||
160 | } | ||
161 | string docFile = (string)conf.Options["XmlDocFile"]; | ||
162 | if(docFile != null && docFile.Length == 0)//default to assembly name if not specified | ||
163 | { | ||
164 | return "False"; | ||
165 | } | ||
166 | return "True"; | ||
167 | } | ||
168 | |||
169 | private void WriteProject(SolutionNode solution, ProjectNode project) | ||
170 | { | ||
171 | string csComp = "Mcs"; | ||
172 | string netRuntime = "Mono"; | ||
173 | if(project.Runtime == ClrRuntime.Microsoft) | ||
174 | { | ||
175 | csComp = "Csc"; | ||
176 | netRuntime = "MsNet"; | ||
177 | } | ||
178 | |||
179 | string projFile = Helper.MakeFilePath(project.FullPath, project.Name, "mdp"); | ||
180 | StreamWriter ss = new StreamWriter(projFile); | ||
181 | |||
182 | m_Kernel.CurrentWorkingDirectory.Push(); | ||
183 | Helper.SetCurrentDir(Path.GetDirectoryName(projFile)); | ||
184 | |||
185 | using(ss) | ||
186 | { | ||
187 | ss.WriteLine( | ||
188 | "<Project name=\"{0}\" description=\"\" standardNamespace=\"{1}\" newfilesearch=\"None\" enableviewstate=\"True\" fileversion=\"2.0\" language=\"C#\" clr-version=\"Net_2_0\" ctype=\"DotNetProject\">", | ||
189 | project.Name, | ||
190 | project.RootNamespace | ||
191 | ); | ||
192 | |||
193 | int count = 0; | ||
194 | |||
195 | ss.WriteLine(" <Configurations active=\"{0}\">", solution.ActiveConfig); | ||
196 | |||
197 | foreach(ConfigurationNode conf in project.Configurations) | ||
198 | { | ||
199 | ss.WriteLine(" <Configuration name=\"{0}\" ctype=\"DotNetProjectConfiguration\">", conf.Name); | ||
200 | ss.Write(" <Output"); | ||
201 | ss.Write(" directory=\"{0}\"", Helper.EndPath(Helper.NormalizePath(".\\" + conf.Options["OutputPath"].ToString()))); | ||
202 | ss.Write(" assembly=\"{0}\"", project.AssemblyName); | ||
203 | ss.Write(" executeScript=\"{0}\"", conf.Options["RunScript"]); | ||
204 | //ss.Write(" executeBeforeBuild=\"{0}\"", conf.Options["PreBuildEvent"]); | ||
205 | //ss.Write(" executeAfterBuild=\"{0}\"", conf.Options["PostBuildEvent"]); | ||
206 | if (conf.Options["PreBuildEvent"] != null && conf.Options["PreBuildEvent"].ToString().Length != 0) | ||
207 | { | ||
208 | ss.Write(" executeBeforeBuild=\"{0}\"", Helper.NormalizePath(conf.Options["PreBuildEvent"].ToString())); | ||
209 | } | ||
210 | else | ||
211 | { | ||
212 | ss.Write(" executeBeforeBuild=\"{0}\"", conf.Options["PreBuildEvent"]); | ||
213 | } | ||
214 | if (conf.Options["PostBuildEvent"] != null && conf.Options["PostBuildEvent"].ToString().Length != 0) | ||
215 | { | ||
216 | ss.Write(" executeAfterBuild=\"{0}\"", Helper.NormalizePath(conf.Options["PostBuildEvent"].ToString())); | ||
217 | } | ||
218 | else | ||
219 | { | ||
220 | ss.Write(" executeAfterBuild=\"{0}\"", conf.Options["PostBuildEvent"]); | ||
221 | } | ||
222 | ss.Write(" executeBeforeBuildArguments=\"{0}\"", conf.Options["PreBuildEventArgs"]); | ||
223 | ss.Write(" executeAfterBuildArguments=\"{0}\"", conf.Options["PreBuildEventArgs"]); | ||
224 | ss.WriteLine(" />"); | ||
225 | |||
226 | ss.Write(" <Build"); | ||
227 | ss.Write(" debugmode=\"True\""); | ||
228 | if (project.Type == ProjectType.WinExe) | ||
229 | { | ||
230 | ss.Write(" target=\"{0}\"", ProjectType.Exe.ToString()); | ||
231 | } | ||
232 | else | ||
233 | { | ||
234 | ss.Write(" target=\"{0}\"", project.Type); | ||
235 | } | ||
236 | ss.WriteLine(" />"); | ||
237 | |||
238 | ss.Write(" <Execution"); | ||
239 | ss.Write(" runwithwarnings=\"{0}\"", !conf.Options.WarningsAsErrors); | ||
240 | ss.Write(" consolepause=\"True\""); | ||
241 | ss.Write(" runtime=\"{0}\"", netRuntime); | ||
242 | ss.Write(" clr-version=\"Net_2_0\""); | ||
243 | ss.WriteLine(" />"); | ||
244 | |||
245 | ss.Write(" <CodeGeneration"); | ||
246 | ss.Write(" compiler=\"{0}\"", csComp); | ||
247 | ss.Write(" warninglevel=\"{0}\"", conf.Options["WarningLevel"]); | ||
248 | ss.Write(" nowarn=\"{0}\"", conf.Options["SuppressWarnings"]); | ||
249 | ss.Write(" includedebuginformation=\"{0}\"", conf.Options["DebugInformation"]); | ||
250 | ss.Write(" optimize=\"{0}\"", conf.Options["OptimizeCode"]); | ||
251 | ss.Write(" unsafecodeallowed=\"{0}\"", conf.Options["AllowUnsafe"]); | ||
252 | ss.Write(" generateoverflowchecks=\"{0}\"", conf.Options["CheckUnderflowOverflow"]); | ||
253 | ss.Write(" mainclass=\"{0}\"", project.StartupObject); | ||
254 | ss.Write(" target=\"{0}\"", project.Type); | ||
255 | ss.Write(" definesymbols=\"{0}\"", conf.Options["CompilerDefines"]); | ||
256 | ss.Write(" generatexmldocumentation=\"{0}\"", GenerateXmlDocFile(project, conf)); | ||
257 | ss.Write(" win32Icon=\"{0}\"", project.AppIcon); | ||
258 | ss.Write(" ctype=\"CSharpCompilerParameters\""); | ||
259 | ss.WriteLine(" />"); | ||
260 | ss.WriteLine(" </Configuration>"); | ||
261 | |||
262 | count++; | ||
263 | } | ||
264 | ss.WriteLine(" </Configurations>"); | ||
265 | |||
266 | ss.Write(" <DeploymentInformation"); | ||
267 | ss.Write(" target=\"\""); | ||
268 | ss.Write(" script=\"\""); | ||
269 | ss.Write(" strategy=\"File\""); | ||
270 | ss.WriteLine(">"); | ||
271 | ss.WriteLine(" <excludeFiles />"); | ||
272 | ss.WriteLine(" </DeploymentInformation>"); | ||
273 | |||
274 | ss.WriteLine(" <Contents>"); | ||
275 | foreach(string file in project.Files) | ||
276 | { | ||
277 | string buildAction = "Compile"; | ||
278 | switch(project.Files.GetBuildAction(file)) | ||
279 | { | ||
280 | case BuildAction.None: | ||
281 | buildAction = "Nothing"; | ||
282 | break; | ||
283 | |||
284 | case BuildAction.Content: | ||
285 | buildAction = "Exclude"; | ||
286 | break; | ||
287 | |||
288 | case BuildAction.EmbeddedResource: | ||
289 | buildAction = "EmbedAsResource"; | ||
290 | break; | ||
291 | |||
292 | default: | ||
293 | buildAction = "Compile"; | ||
294 | break; | ||
295 | } | ||
296 | |||
297 | // Sort of a hack, we try and resolve the path and make it relative, if we can. | ||
298 | string filePath = PrependPath(file); | ||
299 | ss.WriteLine(" <File name=\"{0}\" subtype=\"Code\" buildaction=\"{1}\" dependson=\"\" data=\"\" />", filePath, buildAction); | ||
300 | } | ||
301 | ss.WriteLine(" </Contents>"); | ||
302 | |||
303 | ss.WriteLine(" <References>"); | ||
304 | foreach(ReferenceNode refr in project.References) | ||
305 | { | ||
306 | ss.WriteLine(" {0}", BuildReference(solution, refr)); | ||
307 | } | ||
308 | ss.WriteLine(" </References>"); | ||
309 | |||
310 | |||
311 | ss.WriteLine("</Project>"); | ||
312 | } | ||
313 | |||
314 | m_Kernel.CurrentWorkingDirectory.Pop(); | ||
315 | } | ||
316 | |||
317 | private void WriteCombine(SolutionNode solution) | ||
318 | { | ||
319 | m_Kernel.Log.Write("Creating MonoDevelop combine and project files"); | ||
320 | foreach(ProjectNode project in solution.Projects) | ||
321 | { | ||
322 | if(m_Kernel.AllowProject(project.FilterGroups)) | ||
323 | { | ||
324 | m_Kernel.Log.Write("...Creating project: {0}", project.Name); | ||
325 | WriteProject(solution, project); | ||
326 | } | ||
327 | } | ||
328 | |||
329 | m_Kernel.Log.Write(""); | ||
330 | string combFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "mds"); | ||
331 | StreamWriter ss = new StreamWriter(combFile); | ||
332 | |||
333 | m_Kernel.CurrentWorkingDirectory.Push(); | ||
334 | Helper.SetCurrentDir(Path.GetDirectoryName(combFile)); | ||
335 | |||
336 | int count = 0; | ||
337 | |||
338 | using(ss) | ||
339 | { | ||
340 | ss.WriteLine("<Combine name=\"{0}\" fileversion=\"2.0\" description=\"\">", solution.Name); | ||
341 | |||
342 | count = 0; | ||
343 | foreach(ConfigurationNode conf in solution.Configurations) | ||
344 | { | ||
345 | if(count == 0) | ||
346 | { | ||
347 | ss.WriteLine(" <Configurations active=\"{0}\">", conf.Name); | ||
348 | } | ||
349 | |||
350 | ss.WriteLine(" <Configuration name=\"{0}\" ctype=\"CombineConfiguration\">", conf.Name); | ||
351 | foreach(ProjectNode project in solution.Projects) | ||
352 | { | ||
353 | ss.WriteLine(" <Entry configuration=\"{1}\" build=\"True\" name=\"{0}\" />", project.Name, conf.Name); | ||
354 | } | ||
355 | ss.WriteLine(" </Configuration>"); | ||
356 | |||
357 | count++; | ||
358 | } | ||
359 | ss.WriteLine(" </Configurations>"); | ||
360 | |||
361 | count = 0; | ||
362 | |||
363 | foreach(ProjectNode project in solution.Projects) | ||
364 | { | ||
365 | if(count == 0) | ||
366 | ss.WriteLine(" <StartMode startupentry=\"{0}\" single=\"True\">", project.Name); | ||
367 | |||
368 | ss.WriteLine(" <Execute type=\"None\" entry=\"{0}\" />", project.Name); | ||
369 | count++; | ||
370 | } | ||
371 | ss.WriteLine(" </StartMode>"); | ||
372 | |||
373 | ss.WriteLine(" <Entries>"); | ||
374 | foreach(ProjectNode project in solution.Projects) | ||
375 | { | ||
376 | string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath); | ||
377 | ss.WriteLine(" <Entry filename=\"{0}\" />", | ||
378 | Helper.MakeFilePath(path, project.Name, "mdp")); | ||
379 | } | ||
380 | ss.WriteLine(" </Entries>"); | ||
381 | |||
382 | ss.WriteLine("</Combine>"); | ||
383 | } | ||
384 | |||
385 | m_Kernel.CurrentWorkingDirectory.Pop(); | ||
386 | } | ||
387 | |||
388 | private void CleanProject(ProjectNode project) | ||
389 | { | ||
390 | m_Kernel.Log.Write("...Cleaning project: {0}", project.Name); | ||
391 | string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, "mdp"); | ||
392 | Helper.DeleteIfExists(projectFile); | ||
393 | } | ||
394 | |||
395 | private void CleanSolution(SolutionNode solution) | ||
396 | { | ||
397 | m_Kernel.Log.Write("Cleaning MonoDevelop combine and project files for", solution.Name); | ||
398 | |||
399 | string slnFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "mds"); | ||
400 | Helper.DeleteIfExists(slnFile); | ||
401 | |||
402 | foreach(ProjectNode project in solution.Projects) | ||
403 | { | ||
404 | CleanProject(project); | ||
405 | } | ||
406 | |||
407 | m_Kernel.Log.Write(""); | ||
408 | } | ||
409 | |||
410 | #endregion | ||
411 | |||
412 | #region ITarget Members | ||
413 | |||
414 | /// <summary> | ||
415 | /// Writes the specified kern. | ||
416 | /// </summary> | ||
417 | /// <param name="kern">The kern.</param> | ||
418 | public void Write(Kernel kern) | ||
419 | { | ||
420 | if( kern == null ) | ||
421 | { | ||
422 | throw new ArgumentNullException("kern"); | ||
423 | } | ||
424 | m_Kernel = kern; | ||
425 | foreach(SolutionNode solution in kern.Solutions) | ||
426 | { | ||
427 | WriteCombine(solution); | ||
428 | } | ||
429 | m_Kernel = null; | ||
430 | } | ||
431 | |||
432 | /// <summary> | ||
433 | /// Cleans the specified kern. | ||
434 | /// </summary> | ||
435 | /// <param name="kern">The kern.</param> | ||
436 | public virtual void Clean(Kernel kern) | ||
437 | { | ||
438 | if( kern == null ) | ||
439 | { | ||
440 | throw new ArgumentNullException("kern"); | ||
441 | } | ||
442 | m_Kernel = kern; | ||
443 | foreach(SolutionNode sol in kern.Solutions) | ||
444 | { | ||
445 | CleanSolution(sol); | ||
446 | } | ||
447 | m_Kernel = null; | ||
448 | } | ||
449 | |||
450 | /// <summary> | ||
451 | /// Gets the name. | ||
452 | /// </summary> | ||
453 | /// <value>The name.</value> | ||
454 | public string Name | ||
455 | { | ||
456 | get | ||
457 | { | ||
458 | return "sharpdev"; | ||
459 | } | ||
460 | } | ||
461 | |||
462 | #endregion | ||
463 | } | ||
464 | } | ||