diff options
author | BlueWall | 2010-08-31 17:02:36 -0400 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2010-09-04 02:12:21 +0100 |
commit | 1e44ec84bd90ec9078027d1d9d78e83c7d305f2a (patch) | |
tree | e34db5ced4bc7bf59b98ff9fb72271dda0f25a33 /Prebuild/src/Core/Targets/SharpDevelopTarget.cs | |
parent | Merge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff) | |
download | opensim-SC-1e44ec84bd90ec9078027d1d9d78e83c7d305f2a.zip opensim-SC-1e44ec84bd90ec9078027d1d9d78e83c7d305f2a.tar.gz opensim-SC-1e44ec84bd90ec9078027d1d9d78e83c7d305f2a.tar.bz2 opensim-SC-1e44ec84bd90ec9078027d1d9d78e83c7d305f2a.tar.xz |
Build system upgrade:
Upgrading Prebuild.exe to correctly construct build solutions
for crossplatform tools such as xbuild, monodevelop and nant.
NOTE: Module prebuild files will need modification to work,
as the prebuild must correctly define the reference path for
all assemblies shipped in the OpenSimulator ./bin directory.
These include assemblies such as XMLRPC.dll, OpenMetaverse.dll,
Nini.dll, etc. . The entries should follow the form:
<Reference name="Nini" path="../../../bin/"/>
See the distributed prebuild.xml for further examples.
Crossplatform tools: xbuild and monodevelop use the
vs2008 OpenSim.sln and the .csproj files in each namespace.
Changes to the Prebuild.exe are against svn 322 and are included
in a patch attached to the mantis. And the dnpb source are
available@ svn co https://dnpb.svn.sourceforge.net/svnroot/dnpb dnpb
The patches are pending application by the dnpb team. After which,
the un-modified upstream Prebuild.exe will work as expected.
Diffstat (limited to 'Prebuild/src/Core/Targets/SharpDevelopTarget.cs')
-rw-r--r-- | Prebuild/src/Core/Targets/SharpDevelopTarget.cs | 428 |
1 files changed, 0 insertions, 428 deletions
diff --git a/Prebuild/src/Core/Targets/SharpDevelopTarget.cs b/Prebuild/src/Core/Targets/SharpDevelopTarget.cs deleted file mode 100644 index cf7ce02..0000000 --- a/Prebuild/src/Core/Targets/SharpDevelopTarget.cs +++ /dev/null | |||
@@ -1,428 +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.Text.RegularExpressions; | ||
31 | using System.Reflection; | ||
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("sharpdev")] | ||
44 | public class SharpDevelopTarget : 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 = "<Reference type=\""; | ||
74 | if(solution.ProjectsTable.ContainsKey(refr.Name)) | ||
75 | { | ||
76 | ret += "Project\" refto=\"" + refr.Name; | ||
77 | ret += "\" localcopy=\"" + refr.LocalCopy.ToString() + "\" />"; | ||
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\" refto=\""; | ||
96 | try | ||
97 | { | ||
98 | //Assembly assem = Assembly.Load(refr.Name); | ||
99 | ret += refr.Name;// assem.FullName; | ||
100 | } | ||
101 | catch (System.NullReferenceException e) | ||
102 | { | ||
103 | e.ToString(); | ||
104 | ret += refr.Name; | ||
105 | } | ||
106 | ret += "\" localcopy=\"" + refr.LocalCopy.ToString() + "\" />"; | ||
107 | } | ||
108 | |||
109 | return ret; | ||
110 | } | ||
111 | |||
112 | private static string FindFileReference(string refName, ProjectNode project) | ||
113 | { | ||
114 | foreach(ReferencePathNode refPath in project.ReferencePaths) | ||
115 | { | ||
116 | string fullPath = Helper.MakeFilePath(refPath.Path, refName, "dll"); | ||
117 | |||
118 | if(File.Exists(fullPath)) | ||
119 | { | ||
120 | return fullPath; | ||
121 | } | ||
122 | } | ||
123 | |||
124 | return null; | ||
125 | } | ||
126 | |||
127 | /// <summary> | ||
128 | /// Gets the XML doc file. | ||
129 | /// </summary> | ||
130 | /// <param name="project">The project.</param> | ||
131 | /// <param name="conf">The conf.</param> | ||
132 | /// <returns></returns> | ||
133 | public static string GenerateXmlDocFile(ProjectNode project, ConfigurationNode conf) | ||
134 | { | ||
135 | if( conf == null ) | ||
136 | { | ||
137 | throw new ArgumentNullException("conf"); | ||
138 | } | ||
139 | if( project == null ) | ||
140 | { | ||
141 | throw new ArgumentNullException("project"); | ||
142 | } | ||
143 | string docFile = (string)conf.Options["XmlDocFile"]; | ||
144 | if(docFile != null && docFile.Length == 0)//default to assembly name if not specified | ||
145 | { | ||
146 | return "False"; | ||
147 | } | ||
148 | return "True"; | ||
149 | } | ||
150 | |||
151 | private void WriteProject(SolutionNode solution, ProjectNode project) | ||
152 | { | ||
153 | string csComp = "Csc"; | ||
154 | string netRuntime = "MsNet"; | ||
155 | if(project.Runtime == ClrRuntime.Mono) | ||
156 | { | ||
157 | csComp = "Mcs"; | ||
158 | netRuntime = "Mono"; | ||
159 | } | ||
160 | |||
161 | string projFile = Helper.MakeFilePath(project.FullPath, project.Name, "prjx"); | ||
162 | StreamWriter ss = new StreamWriter(projFile); | ||
163 | |||
164 | m_Kernel.CurrentWorkingDirectory.Push(); | ||
165 | Helper.SetCurrentDir(Path.GetDirectoryName(projFile)); | ||
166 | |||
167 | using(ss) | ||
168 | { | ||
169 | ss.WriteLine( | ||
170 | "<Project name=\"{0}\" standardNamespace=\"{1}\" description=\"\" newfilesearch=\"None\" enableviewstate=\"True\" version=\"1.1\" projecttype=\"C#\">", | ||
171 | project.Name, | ||
172 | project.RootNamespace | ||
173 | ); | ||
174 | |||
175 | ss.WriteLine(" <Contents>"); | ||
176 | foreach(string file in project.Files) | ||
177 | { | ||
178 | string buildAction = "Compile"; | ||
179 | switch(project.Files.GetBuildAction(file)) | ||
180 | { | ||
181 | case BuildAction.None: | ||
182 | buildAction = "Nothing"; | ||
183 | break; | ||
184 | |||
185 | case BuildAction.Content: | ||
186 | buildAction = "Exclude"; | ||
187 | break; | ||
188 | |||
189 | case BuildAction.EmbeddedResource: | ||
190 | buildAction = "EmbedAsResource"; | ||
191 | break; | ||
192 | |||
193 | default: | ||
194 | buildAction = "Compile"; | ||
195 | break; | ||
196 | } | ||
197 | |||
198 | // Sort of a hack, we try and resolve the path and make it relative, if we can. | ||
199 | string filePath = PrependPath(file); | ||
200 | ss.WriteLine(" <File name=\"{0}\" subtype=\"Code\" buildaction=\"{1}\" dependson=\"\" data=\"\" />", filePath, buildAction); | ||
201 | } | ||
202 | ss.WriteLine(" </Contents>"); | ||
203 | |||
204 | ss.WriteLine(" <References>"); | ||
205 | foreach(ReferenceNode refr in project.References) | ||
206 | { | ||
207 | ss.WriteLine(" {0}", BuildReference(solution, refr)); | ||
208 | } | ||
209 | ss.WriteLine(" </References>"); | ||
210 | |||
211 | ss.Write(" <DeploymentInformation"); | ||
212 | ss.Write(" target=\"\""); | ||
213 | ss.Write(" script=\"\""); | ||
214 | ss.Write(" strategy=\"File\""); | ||
215 | ss.WriteLine(" />"); | ||
216 | |||
217 | int count = 0; | ||
218 | |||
219 | ss.WriteLine(" <Configurations active=\"{0}\">", solution.ActiveConfig); | ||
220 | |||
221 | foreach(ConfigurationNode conf in project.Configurations) | ||
222 | { | ||
223 | ss.Write(" <Configuration"); | ||
224 | ss.Write(" runwithwarnings=\"True\""); | ||
225 | ss.Write(" name=\"{0}\"", conf.Name); | ||
226 | ss.WriteLine(">"); | ||
227 | ss.Write(" <CodeGeneration"); | ||
228 | ss.Write(" runtime=\"{0}\"", netRuntime); | ||
229 | ss.Write(" compiler=\"{0}\"", csComp); | ||
230 | ss.Write(" compilerversion=\"\""); | ||
231 | ss.Write(" warninglevel=\"{0}\"", conf.Options["WarningLevel"]); | ||
232 | ss.Write(" nowarn=\"{0}\"", conf.Options["SuppressWarnings"]); | ||
233 | ss.Write(" includedebuginformation=\"{0}\"", conf.Options["DebugInformation"]); | ||
234 | ss.Write(" optimize=\"{0}\"", conf.Options["OptimizeCode"]); | ||
235 | ss.Write(" unsafecodeallowed=\"{0}\"", conf.Options["AllowUnsafe"]); | ||
236 | ss.Write(" generateoverflowchecks=\"{0}\"", conf.Options["CheckUnderflowOverflow"]); | ||
237 | ss.Write(" mainclass=\"{0}\"", project.StartupObject); | ||
238 | ss.Write(" target=\"{0}\"", project.Type); | ||
239 | ss.Write(" definesymbols=\"{0}\"", conf.Options["CompilerDefines"]); | ||
240 | ss.Write(" generatexmldocumentation=\"{0}\"", GenerateXmlDocFile(project, conf)); | ||
241 | ss.Write(" win32Icon=\"{0}\"", Helper.NormalizePath(".\\" + project.AppIcon)); | ||
242 | ss.Write(" noconfig=\"{0}\"", "False"); | ||
243 | ss.Write(" nostdlib=\"{0}\"", conf.Options["NoStdLib"]); | ||
244 | ss.WriteLine(" />"); | ||
245 | |||
246 | ss.Write(" <Execution"); | ||
247 | ss.Write(" commandlineparameters=\"\""); | ||
248 | ss.Write(" consolepause=\"True\""); | ||
249 | ss.WriteLine(" />"); | ||
250 | |||
251 | ss.Write(" <Output"); | ||
252 | ss.Write(" directory=\".\\{0}\"", Helper.NormalizePath(conf.Options["OutputPath"].ToString())); | ||
253 | ss.Write(" assembly=\"{0}\"", project.AssemblyName); | ||
254 | ss.Write(" executeScript=\"{0}\"", conf.Options["RunScript"]); | ||
255 | if (conf.Options["PreBuildEvent"] != null && conf.Options["PreBuildEvent"].ToString().Length != 0) | ||
256 | { | ||
257 | ss.Write(" executeBeforeBuild=\"{0}\"", Helper.NormalizePath(conf.Options["PreBuildEvent"].ToString())); | ||
258 | } | ||
259 | else | ||
260 | { | ||
261 | ss.Write(" executeBeforeBuild=\"{0}\"", conf.Options["PreBuildEvent"]); | ||
262 | } | ||
263 | if (conf.Options["PostBuildEvent"] != null && conf.Options["PostBuildEvent"].ToString().Length != 0) | ||
264 | { | ||
265 | ss.Write(" executeAfterBuild=\"{0}\"", Helper.NormalizePath(conf.Options["PostBuildEvent"].ToString())); | ||
266 | } | ||
267 | else | ||
268 | { | ||
269 | ss.Write(" executeAfterBuild=\"{0}\"", conf.Options["PostBuildEvent"]); | ||
270 | } | ||
271 | ss.Write(" executeBeforeBuildArguments=\"{0}\"", conf.Options["PreBuildEventArgs"]); | ||
272 | ss.Write(" executeAfterBuildArguments=\"{0}\"", conf.Options["PreBuildEventArgs"]); | ||
273 | ss.WriteLine(" />"); | ||
274 | ss.WriteLine(" </Configuration>"); | ||
275 | |||
276 | count++; | ||
277 | } | ||
278 | ss.WriteLine(" </Configurations>"); | ||
279 | ss.WriteLine("</Project>"); | ||
280 | } | ||
281 | |||
282 | m_Kernel.CurrentWorkingDirectory.Pop(); | ||
283 | } | ||
284 | |||
285 | private void WriteCombine(SolutionNode solution) | ||
286 | { | ||
287 | m_Kernel.Log.Write("Creating SharpDevelop combine and project files"); | ||
288 | foreach(ProjectNode project in solution.Projects) | ||
289 | { | ||
290 | if(m_Kernel.AllowProject(project.FilterGroups)) | ||
291 | { | ||
292 | m_Kernel.Log.Write("...Creating project: {0}", project.Name); | ||
293 | WriteProject(solution, project); | ||
294 | } | ||
295 | } | ||
296 | |||
297 | m_Kernel.Log.Write(""); | ||
298 | string combFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "cmbx"); | ||
299 | StreamWriter ss = new StreamWriter(combFile); | ||
300 | |||
301 | m_Kernel.CurrentWorkingDirectory.Push(); | ||
302 | Helper.SetCurrentDir(Path.GetDirectoryName(combFile)); | ||
303 | |||
304 | using(ss) | ||
305 | { | ||
306 | ss.WriteLine("<Combine fileversion=\"1.0\" name=\"{0}\" description=\"\">", solution.Name); | ||
307 | |||
308 | int count = 0; | ||
309 | foreach(ProjectNode project in solution.Projects) | ||
310 | { | ||
311 | if(count == 0) | ||
312 | ss.WriteLine(" <StartMode startupentry=\"{0}\" single=\"True\">", project.Name); | ||
313 | |||
314 | ss.WriteLine(" <Execute entry=\"{0}\" type=\"None\" />", project.Name); | ||
315 | count++; | ||
316 | } | ||
317 | ss.WriteLine(" </StartMode>"); | ||
318 | |||
319 | ss.WriteLine(" <Entries>"); | ||
320 | foreach(ProjectNode project in solution.Projects) | ||
321 | { | ||
322 | string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath); | ||
323 | ss.WriteLine(" <Entry filename=\"{0}\" />", | ||
324 | Helper.MakeFilePath(path, project.Name, "prjx")); | ||
325 | } | ||
326 | ss.WriteLine(" </Entries>"); | ||
327 | |||
328 | count = 0; | ||
329 | foreach(ConfigurationNode conf in solution.Configurations) | ||
330 | { | ||
331 | if(count == 0) | ||
332 | { | ||
333 | ss.WriteLine(" <Configurations active=\"{0}\">", conf.Name); | ||
334 | } | ||
335 | |||
336 | ss.WriteLine(" <Configuration name=\"{0}\">", conf.Name); | ||
337 | foreach(ProjectNode project in solution.Projects) | ||
338 | { | ||
339 | ss.WriteLine(" <Entry name=\"{0}\" configurationname=\"{1}\" build=\"True\" />", project.Name, conf.Name); | ||
340 | } | ||
341 | ss.WriteLine(" </Configuration>"); | ||
342 | |||
343 | count++; | ||
344 | } | ||
345 | ss.WriteLine(" </Configurations>"); | ||
346 | ss.WriteLine("</Combine>"); | ||
347 | } | ||
348 | |||
349 | m_Kernel.CurrentWorkingDirectory.Pop(); | ||
350 | } | ||
351 | |||
352 | private void CleanProject(ProjectNode project) | ||
353 | { | ||
354 | m_Kernel.Log.Write("...Cleaning project: {0}", project.Name); | ||
355 | string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, "prjx"); | ||
356 | Helper.DeleteIfExists(projectFile); | ||
357 | } | ||
358 | |||
359 | private void CleanSolution(SolutionNode solution) | ||
360 | { | ||
361 | m_Kernel.Log.Write("Cleaning SharpDevelop combine and project files for", solution.Name); | ||
362 | |||
363 | string slnFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "cmbx"); | ||
364 | Helper.DeleteIfExists(slnFile); | ||
365 | |||
366 | foreach(ProjectNode project in solution.Projects) | ||
367 | { | ||
368 | CleanProject(project); | ||
369 | } | ||
370 | |||
371 | m_Kernel.Log.Write(""); | ||
372 | } | ||
373 | |||
374 | #endregion | ||
375 | |||
376 | #region ITarget Members | ||
377 | |||
378 | /// <summary> | ||
379 | /// Writes the specified kern. | ||
380 | /// </summary> | ||
381 | /// <param name="kern">The kern.</param> | ||
382 | public void Write(Kernel kern) | ||
383 | { | ||
384 | if( kern == null ) | ||
385 | { | ||
386 | throw new ArgumentNullException("kern"); | ||
387 | } | ||
388 | m_Kernel = kern; | ||
389 | foreach(SolutionNode solution in kern.Solutions) | ||
390 | { | ||
391 | WriteCombine(solution); | ||
392 | } | ||
393 | m_Kernel = null; | ||
394 | } | ||
395 | |||
396 | /// <summary> | ||
397 | /// Cleans the specified kern. | ||
398 | /// </summary> | ||
399 | /// <param name="kern">The kern.</param> | ||
400 | public virtual void Clean(Kernel kern) | ||
401 | { | ||
402 | if( kern == null ) | ||
403 | { | ||
404 | throw new ArgumentNullException("kern"); | ||
405 | } | ||
406 | m_Kernel = kern; | ||
407 | foreach(SolutionNode sol in kern.Solutions) | ||
408 | { | ||
409 | CleanSolution(sol); | ||
410 | } | ||
411 | m_Kernel = null; | ||
412 | } | ||
413 | |||
414 | /// <summary> | ||
415 | /// Gets the name. | ||
416 | /// </summary> | ||
417 | /// <value>The name.</value> | ||
418 | public string Name | ||
419 | { | ||
420 | get | ||
421 | { | ||
422 | return "sharpdev"; | ||
423 | } | ||
424 | } | ||
425 | |||
426 | #endregion | ||
427 | } | ||
428 | } | ||