using System.Collections.Specialized;
using System.Diagnostics;
using System.Text.RegularExpressions;
-
-#if NET_2_0
using System.Threading;
using System.Collections.Generic;
-#endif
internal class CSharpCodeCompiler : CSharpCodeGenerator, ICodeCompiler
{
static string windowsMcsPath;
static string windowsMonoPath;
-#if NET_2_0
Mutex mcsOutMutex;
StringCollection mcsOutput;
-#endif
static CSharpCodeCompiler ()
{
#if NET_4_0
windowsMcsPath =
Path.Combine (p, "4.0\\dmcs.exe");
-#elif NET_2_0
- windowsMcsPath =
- Path.Combine (p, "2.0\\gmcs.exe");
#else
windowsMcsPath =
- Path.Combine (p, "1.0\\mcs.exe");
+ Path.Combine (p, "2.0\\gmcs.exe");
#endif
if (!File.Exists (windowsMcsPath))
#if NET_4_0
Path.Combine(
Path.GetDirectoryName (p),
"lib\\net_4_0\\dmcs.exe");
-#elif NET_2_0
- windowsMcsPath =
- Path.Combine(
- Path.GetDirectoryName (p),
- "lib\\net_2_0\\gmcs.exe");
#else
windowsMcsPath =
Path.Combine(
Path.GetDirectoryName (p),
- "lib\\default\\mcs.exe");
+ "lib\\net_2_0\\gmcs.exe");
#endif
if (!File.Exists (windowsMcsPath))
throw new FileNotFoundException ("Windows mcs path not found: " + windowsMcsPath);
{
}
-#if NET_2_0
public CSharpCodeCompiler (IDictionary <string, string> providerOptions) :
base (providerOptions)
{
}
-#endif
//
// Methods
CompilerResults results=new CompilerResults(options.TempFiles);
Process mcs=new Process();
-
-#if !NET_2_0
- string mcs_output;
- string mcs_stdout;
- string[] mcsOutput;
-#endif
// FIXME: these lines had better be platform independent.
if (Path.DirectorySeparatorChar == '\\') {
mcs.StartInfo.FileName = windowsMonoPath;
mcs.StartInfo.Arguments = "\"" + windowsMcsPath + "\" " +
-#if NET_2_0
BuildArgs (options, fileNames, ProviderOptions);
-#else
- BuildArgs (options, fileNames);
-#endif
} else {
-#if NET_2_0
// FIXME: This is a temporary hack to make code genaration work in 2.0+
#if NET_4_0
mcs.StartInfo.FileName="dmcs";
mcs.StartInfo.FileName="gmcs";
#endif
mcs.StartInfo.Arguments=BuildArgs(options, fileNames, ProviderOptions);
-#else
- mcs.StartInfo.FileName="mcs";
- mcs.StartInfo.Arguments=BuildArgs(options, fileNames);
-#endif
}
-#if NET_2_0
mcsOutput = new StringCollection ();
mcsOutMutex = new Mutex ();
-#endif
string monoPath = Environment.GetEnvironmentVariable ("MONO_PATH");
if (monoPath == null)
mcs.StartInfo.UseShellExecute=false;
mcs.StartInfo.RedirectStandardOutput=true;
mcs.StartInfo.RedirectStandardError=true;
-#if NET_2_0
mcs.ErrorDataReceived += new DataReceivedEventHandler (McsStderrDataReceived);
-#endif
try {
mcs.Start();
}
try {
-#if NET_2_0
mcs.BeginOutputReadLine ();
mcs.BeginErrorReadLine ();
-#else
- // If there are a few kB in stdout, we might lock
- mcs_output=mcs.StandardError.ReadToEnd();
- mcs_stdout=mcs.StandardOutput.ReadToEnd ();
-#endif
mcs.WaitForExit();
results.NativeCompilerReturnValue = mcs.ExitCode;
} finally {
-#if NET_2_0
mcs.CancelErrorRead ();
mcs.CancelOutputRead ();
-#endif
-
mcs.Close();
}
-#if NET_2_0
StringCollection sc = mcsOutput;
-#else
- mcsOutput = mcs_output.Split (System.Environment.NewLine.ToCharArray ());
- StringCollection sc = new StringCollection ();
-#endif
bool loadIt=true;
foreach (string error_line in mcsOutput) {
-#if !NET_2_0
- sc.Add (error_line);
-#endif
CompilerError error = CreateErrorFromString (error_line);
if (error != null) {
results.Errors.Add (error);
return results;
}
-#if NET_2_0
void McsStderrDataReceived (object sender, DataReceivedEventArgs args)
{
if (args.Data != null) {
}
private static string BuildArgs(CompilerParameters options,string[] fileNames, IDictionary <string, string> providerOptions)
-#else
- private static string BuildArgs(CompilerParameters options,string[] fileNames)
-#endif
{
StringBuilder args=new StringBuilder();
if (options.GenerateExecutable)
args.Append (" ");
}
-#if NET_2_0
foreach (string embeddedResource in options.EmbeddedResources) {
args.AppendFormat("/resource:\"{0}\" ", embeddedResource);
}
break;
}
}
-#endif
args.Append (" -- ");
foreach (string source in fileNames)
}
private static CompilerError CreateErrorFromString(string error_string)
{
-#if NET_2_0
if (error_string.StartsWith ("BETA"))
return null;
-#endif
+
if (error_string == null || error_string == "")
return null;