// (C) 2002 Jackson Harper, All rights reserved.
//
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
using System;
using System.IO;
using System.Text;
namespace Microsoft.CSharp {
+ [System.Obsolete]
public class Compiler {
- public Compiler()
+ private Compiler()
{
}
string[] temp_cs_files;
CompilerError[] errors;
-
+ string bugreport_path = null;
+ StreamWriter bug_report = null;
+
temp_cs_files = CreateCsFiles (sourceTexts, sourceTextNames);
+ if (options != null)
+ bugreport_path = (string)options["bugreport"];
+
+ if (bugreport_path != null) {
+ bug_report = CreateBugReport (sourceTexts, sourceTextNames, bugreport_path);
+ }
+
try {
- errors = CompileFiles (temp_cs_files, target, imports, options);
+ errors = CompileFiles (temp_cs_files, target, imports, options, bug_report);
} catch {
throw;
} finally {
FileInfo file = new FileInfo (temp_file);
file.Delete ();
}
+ if (bug_report != null)
+ bug_report.Close ();
}
return errors;
//
private static CompilerError[] CompileFiles (string[] cs_files,
- string target, string[] imports, IDictionary options)
+ string target, string[] imports, IDictionary options, StreamWriter bug_report)
{
ArrayList error_list = new ArrayList ();
Process mcs = new Process ();
mcs.StartInfo.CreateNoWindow = true;
mcs.StartInfo.UseShellExecute = false;
mcs.StartInfo.RedirectStandardOutput = true;
+ mcs.StartInfo.RedirectStandardError = true;
try {
mcs.Start ();
- mcs_output = mcs.StandardOutput.ReadToEnd();
+ mcs_output = mcs.StandardError.ReadToEnd ();
+ mcs.StandardOutput.ReadToEnd ();
mcs.WaitForExit ();
} finally {
mcs.Close ();
error_list.Add (error);
}
+ if (bug_report != null) {
+ bug_report.WriteLine ("### Compiler Output");
+ bug_report.Write (mcs_output);
+ }
+
return (CompilerError[])error_list.ToArray (typeof(CompilerError));
}
if (null != options) {
foreach (object option in options.Keys) {
object value = options[option];
+ if (!ValidOption ((string)option))
+ continue;
args.AppendFormat ("{0} ", OptionString (option,value));
}
}
throw new IndexOutOfRangeException ();
}
+ private static StreamWriter CreateBugReport (string[] source_texts,
+ string[] source_names, string path)
+ {
+ StreamWriter bug_report = null;
+
+ try {
+ bug_report = new StreamWriter (path);
+ bug_report.WriteLine ("### C# Compiler Defect Report," +
+ " created {0}", DateTime.Now);
+ // Compiler Version
+ // Runtime
+ // Operating System
+ // Username
+ for (int i=0; i<source_texts.Length; i++) {
+ bug_report.WriteLine ("### Source file: '{0}'",
+ source_names[i]);
+ bug_report.Write (source_texts[i]);
+ }
+ } catch {
+ if (bug_report != null)
+ bug_report.Close ();
+ throw;
+ }
+
+ return bug_report;
+ }
+
+
+ private static bool ValidOption (string option)
+ {
+ switch (option) {
+ case "addmodule":
+ case "baseaddress":
+ case "checked":
+ case "d":
+ case "debug":
+ case "doc":
+ case "filealign":
+ case "incr":
+ case "lib":
+ case "linkres":
+ case "m":
+ case "nostdlib":
+ case "nowarn":
+ case "o":
+ case "r":
+ case "res":
+ case "target":
+ case "unsafe":
+ case "w":
+ case "warnaserror":
+ case "win32icon":
+ case "win32res":
+ return true;
+ }
+ return false;
+ }
+
}
}