New test.
[mono.git] / mcs / class / System / Microsoft.CSharp / CSharpCodeCompiler.cs
index 36925e1167f75f2ac064db8e5e9bd5569488e78f..f63770b96a19cbb3e7b32ab6a83eafebc2a615a1 100644 (file)
@@ -63,6 +63,14 @@ namespace Mono.CSharp
                                                Path.GetDirectoryName (
                                                        Path.GetDirectoryName (p)),
                                                "bin\\mono.exe");
+                               if (!File.Exists (windowsMonoPath))
+                                       windowsMonoPath = Path.Combine (
+                                               Path.GetDirectoryName (
+                                                       Path.GetDirectoryName (
+                                                               Path.GetDirectoryName (p))),
+                                               "mono\\mono\\mini\\mono.exe");
+                               if (!File.Exists (windowsMonoPath))
+                                       throw new FileNotFoundException ("Windows mono path not found: " + windowsMonoPath);
 #if NET_2_0
                                windowsMcsPath =
                                        Path.Combine (p, "2.0\\gmcs.exe");
@@ -70,6 +78,20 @@ namespace Mono.CSharp
                                windowsMcsPath =
                                        Path.Combine (p, "1.0\\mcs.exe");
 #endif
+                               if (!File.Exists (windowsMcsPath))
+#if 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");
+#endif
+                               if (!File.Exists (windowsMcsPath))
+                                       throw new FileNotFoundException ("Windows mcs path not found: " + windowsMcsPath);
                        }
                }
 
@@ -148,13 +170,13 @@ namespace Mono.CSharp
                        Process mcs=new Process();
 
                        string mcs_output;
+                       string mcs_stdout;
                        string[] mcs_output_lines;
                        // FIXME: these lines had better be platform independent.
                        if (Path.DirectorySeparatorChar == '\\') {
                                mcs.StartInfo.FileName = windowsMonoPath;
-                               mcs.StartInfo.Arguments = windowsMcsPath + ' ' + BuildArgs (options, fileNames);
-                       }
-                       else {
+                               mcs.StartInfo.Arguments = "\"" + windowsMcsPath + "\" " + BuildArgs (options, fileNames);
+                       } else {
 #if NET_2_0
                                // FIXME: This is a temporary hack to make code genaration work in 2.0
                                mcs.StartInfo.FileName="gmcs";
@@ -171,10 +193,10 @@ namespace Mono.CSharp
                                mcs.Start();
                                // If there are a few kB in stdout, we might lock
                                mcs_output=mcs.StandardError.ReadToEnd();
-                               mcs.StandardOutput.ReadToEnd ();
+                               mcs_stdout=mcs.StandardOutput.ReadToEnd ();
                                mcs.WaitForExit();
-                       } finally {
                                results.NativeCompilerReturnValue = mcs.ExitCode;
+                       } finally {
                                mcs.Close();
                        }
                        mcs_output_lines=mcs_output.Split(
@@ -190,6 +212,10 @@ namespace Mono.CSharp
                                }
                        }
                        if (loadIt) {
+                               if (!File.Exists (options.OutputAssembly)) {
+                                       throw new Exception ("Compiler failed to produce the assembly. Stderr='"
+                                               +mcs_output+"', Stdout='"+mcs_stdout+"'");
+                               }
                                if (options.GenerateInMemory) {
                                        using (FileStream fs = File.OpenRead(options.OutputAssembly)) {
                                                byte[] buffer = new byte[fs.Length];
@@ -235,17 +261,28 @@ namespace Mono.CSharp
                                options.OutputAssembly = GetTempFileNameWithExtension (options.TempFiles, "dll", !options.GenerateInMemory);
                        args.AppendFormat("/out:\"{0}\" ",options.OutputAssembly);
 
-                       if (null != options.ReferencedAssemblies)
-                       {
-                               foreach (string import in options.ReferencedAssemblies)
-                                       args.AppendFormat("/r:\"{0}\" ",import);
+                       foreach (string import in options.ReferencedAssemblies) {
+                               if (import == null || import.Length == 0)
+                                       continue;
+
+                               args.AppendFormat("/r:\"{0}\" ",import);
                        }
 
                        if (options.CompilerOptions != null) {
                                args.Append (options.CompilerOptions);
                                args.Append (" ");
                        }
-                       
+
+#if NET_2_0
+                       foreach (string embeddedResource in options.EmbeddedResources) {
+                               args.AppendFormat("/resource:\"{0}\" ", embeddedResource);
+                       }
+
+                       foreach (string linkedResource in options.LinkedResources) {
+                               args.AppendFormat("/linkresource:\"{0}\" ", linkedResource);
+                       }
+#endif
+
                        args.Append (" -- ");
                        foreach (string source in fileNames)
                                args.AppendFormat("\"{0}\" ",source);
@@ -257,9 +294,11 @@ namespace Mono.CSharp
                        if (error_string.StartsWith ("BETA"))
                                return null;
 #endif
+                       if (error_string == null || error_string == "")
+                               return null;
 
                        CompilerError error=new CompilerError();
-                       Regex reg = new Regex (@"^(\s*(?<file>.*)\((?<line>\d*)(,(?<column>\d*))?\)\s+)*(?<level>\w+)\s*(?<number>.*):\s(?<message>.*)",
+                       Regex reg = new Regex (@"^(\s*(?<file>.*)\((?<line>\d*)(,(?<column>\d*))?\)(:)?\s+)*(?<level>\w+)\s*(?<number>.*):\s(?<message>.*)",
                                RegexOptions.Compiled | RegexOptions.ExplicitCapture);
                        Match match=reg.Match(error_string);
                        if (!match.Success) return null;
@@ -308,7 +347,7 @@ namespace Mono.CSharp
                                CodeCompileUnit compileUnit = ea[i];
                                fileNames[i] = GetTempFileNameWithExtension (options.TempFiles, i + ".cs");
                                FileStream f = new FileStream (fileNames[i], FileMode.OpenOrCreate);
-                               StreamWriter s = new StreamWriter (f);
+                               StreamWriter s = new StreamWriter (f, Encoding.UTF8);
                                if (compileUnit.ReferencedAssemblies != null) {
                                        foreach (string str in compileUnit.ReferencedAssemblies) {
                                                if (!assemblies.Contains (str))
@@ -338,7 +377,7 @@ namespace Mono.CSharp
                        for (int i = 0; i < sources.Length; i++) {
                                fileNames[i] = GetTempFileNameWithExtension (options.TempFiles, i + ".cs");
                                FileStream f = new FileStream (fileNames[i], FileMode.OpenOrCreate);
-                               using (StreamWriter s = new StreamWriter (f)) {
+                               using (StreamWriter s = new StreamWriter (f, Encoding.UTF8)) {
                                        s.Write (sources[i]);
                                        s.Close ();
                                }