Do not use --stacktrace
[mono.git] / mcs / tools / prj2make / PrjxInfo.cs
1 // Copyright (c) 2004 Francisco T. Martinez <paco@mfcon.com>\r
2 // All rights reserved.\r
3 //\r
4 // This program is free software; you can redistribute it and/or modify\r
5 // it under the terms of the GNU General Public License as published by\r
6 // the Free Software Foundation; either version 2 of the License, or\r
7 // (at your option) any later version.\r
8 // \r
9 // This program is distributed in the hope that it will be useful,\r
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
12 // GNU Library General Public License for more details.\r
13 // \r
14 // You should have received a copy of the GNU General Public License\r
15 // along with this program; if not, write to the Free Software\r
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
17 \r
18 using System;\r
19 using System.Collections;\r
20 using System.IO;\r
21 using System.Text;\r
22 using System.Text.RegularExpressions;\r
23 using System.Xml;\r
24 using System.Xml.Serialization;\r
25 \r
26 \r
27 namespace Mfconsulting.General.Prj2Make\r
28 {\r
29     class PrjxInfo\r
30     {\r
31         public readonly string name;\r
32         public readonly string csprojpath;\r
33         public string makename;\r
34         public string makename_ext;\r
35         public string assembly_name;\r
36         public string res;\r
37         public string src;\r
38                 private bool m_bAllowUnsafeCode;\r
39         private Mfconsulting.General.Prj2Make.Schema.Prjx.Project m_projObject;\r
40     \r
41         public string ext_refs = "";\r
42         public string switches = "";\r
43 \r
44                 public bool AllowUnsafeCode\r
45                 {\r
46                         get { return m_bAllowUnsafeCode; }\r
47                 }\r
48         \r
49         public Mfconsulting.General.Prj2Make.Schema.Prjx.Project Proyecto {\r
50                 get { return m_projObject; }\r
51         }\r
52     \r
53         // Project desirialization\r
54                 protected Mfconsulting.General.Prj2Make.Schema.Prjx.Project LoadPrjFromFile (string strIn)\r
55                 {\r
56                         FileStream fs = new FileStream (strIn, FileMode.Open);\r
57             \r
58                         XmlSerializer xmlSer = new XmlSerializer (typeof(Mfconsulting.General.Prj2Make.Schema.Prjx.Project));\r
59                         Mfconsulting.General.Prj2Make.Schema.Prjx.Project prjObj = (Mfconsulting.General.Prj2Make.Schema.Prjx.Project) xmlSer.Deserialize (fs);\r
60             \r
61                         fs.Close();\r
62             \r
63                         return (prjObj);\r
64                 }\r
65 \r
66                 public PrjxInfo(bool isUnixMode, bool isMcsMode, string csprojpath)\r
67                 {\r
68                         Mfconsulting.General.Prj2Make.Schema.Prjx.Configuration activeConf = null;\r
69                 this.csprojpath = csprojpath;\r
70 \r
71                 // convert backslashes to slashes               \r
72                 csprojpath = csprojpath.Replace("\\", "/");\r
73     \r
74                 m_bAllowUnsafeCode = false;\r
75                 \r
76                 // loads the file in order to deserialize and\r
77                 // build the object graph\r
78                 try {\r
79                         m_projObject = LoadPrjFromFile (csprojpath);\r
80                         } catch (Exception exc) {\r
81                         \r
82                                 Console.WriteLine ("Could not load the file {0}\n{1}: {2}",\r
83                                                 csprojpath,\r
84                                                 exc.GetType().Name,\r
85                                                 exc.Message\r
86                                         );\r
87                                 return;                 \r
88                         }\r
89 \r
90                 this.name = m_projObject.name;\r
91 \r
92                 makename = name.Replace('.','_').ToUpper();\r
93                 makename_ext = makename + "_EXT";\r
94 \r
95                         // Get the configuration to be used and\r
96                         // copy it to a local configuration object\r
97                         foreach(Mfconsulting.General.Prj2Make.Schema.Prjx.Configuration cnfObj in m_projObject.Configurations.Configuration)\r
98                         {\r
99                                 if(cnfObj.name.CompareTo(m_projObject.Configurations.active) == 0)\r
100                                 {\r
101                                         // Assign the active configuration\r
102                                         activeConf = cnfObj;\r
103                                         break;\r
104                                 }\r
105                         }\r
106 \r
107                         // Establish if the allow unsafe code flag is true\r
108                         if(activeConf.CodeGeneration.unsafecodeallowed == Mfconsulting.General.Prj2Make.Schema.Prjx.CodeGenerationUnsafecodeallowed.True)\r
109                         {\r
110                                 m_bAllowUnsafeCode = true;\r
111                         }\r
112                         \r
113                 switch (activeConf.CodeGeneration.target)\r
114                 {\r
115                         case "Library":\r
116                                 makename_ext = makename + "_DLL";\r
117                                 assembly_name = activeConf.Output.assembly + ".dll";\r
118                                 switches += " -target:library";\r
119                                 break;\r
120     \r
121                         case "Exe":\r
122                                 makename_ext = makename + "_EXE";\r
123                                 assembly_name = activeConf.Output.assembly + ".exe";\r
124                                 switches += " -target:exe";\r
125                                 break;\r
126     \r
127                         case "WinExe":\r
128                                 makename_ext = makename + "_EXE";\r
129                                 assembly_name = activeConf.Output.assembly + ".exe";\r
130                                 switches += " -target:winexe";\r
131                                 break;\r
132     \r
133                         default:\r
134                                 throw new NotSupportedException("Unsupported OutputType: " + activeConf.CodeGeneration.target);\r
135                         \r
136                 }\r
137     \r
138                 src = "";    \r
139                 string basePath = Path.GetDirectoryName(csprojpath);\r
140                 string s;\r
141                 \r
142                         // Process Source code files for compiling\r
143                 foreach (Mfconsulting.General.Prj2Make.Schema.Prjx.File f in m_projObject.Contents)\r
144                 {\r
145                         if(f.buildaction == Mfconsulting.General.Prj2Make.Schema.Prjx.FileBuildaction.Compile)\r
146                         {\r
147                                 if (src != "") {\r
148                                         src += " \\\n\t";\r
149                                 }\r
150                         \r
151                                 s = System.IO.Path.Combine(basePath, f.name);\r
152                                 s = s.Replace("\\", "/");\r
153                                 if (CmbxMaker.slash != "/")\r
154                                         s = s.Replace("/", CmbxMaker.slash);\r
155 \r
156                                         // Test for spaces\r
157                                         if (isUnixMode == false)\r
158                                         {\r
159                                                 // We are in win32 using a cmd.exe or other\r
160                                                 // DOS shell\r
161                                                 if(s.IndexOf(' ') > -1) {\r
162                                                         src += String.Format("\"{0}\"", s);\r
163                                                 } else {\r
164                                                         src += s;\r
165                                                 }\r
166                                         } else {\r
167                                                 // We are in *NIX or some other\r
168                                                 // GNU like shell\r
169                                                 src += s.Replace(" ", "\\ ");\r
170                                         }                       \r
171                         }\r
172                 }\r
173                 \r
174                 // Process resources for embedding\r
175                 res = "";\r
176                 string rootNS = this.name; \r
177                 string relPath;\r
178                 foreach (Mfconsulting.General.Prj2Make.Schema.Prjx.File f in m_projObject.Contents)\r
179                 {\r
180                         if(f.buildaction == Mfconsulting.General.Prj2Make.Schema.Prjx.FileBuildaction.EmbedAsResource)\r
181                         {\r
182                                 if (src != "") {\r
183                                         src += " \\\n\t";\r
184                                 }\r
185                         \r
186                                 relPath = f.name.Replace("\\", "/");\r
187                                 s = System.IO.Path.Combine(basePath, relPath);\r
188                                 s = String.Format(" -resource:{0},{1}", s, System.IO.Path.GetFileName(relPath));\r
189                                 s = s.Replace("\\", "/");\r
190                                 if (CmbxMaker.slash != "/")\r
191                                         s = s.Replace("/", CmbxMaker.slash);\r
192                                 res += s;\r
193                         }\r
194                 }\r
195         }\r
196     }    \r
197 }\r