Merge pull request #487 from mayerwin/patch-1
[mono.git] / mcs / class / System / Microsoft.CSharp / CSharpCodeCompiler.cs
index c0c635ef2d64906b4a9407bab4a8b3d9893ff3f8..26039bdd79b3de87fccd138b2345b4f809967f16 100644 (file)
@@ -77,25 +77,11 @@ namespace Mono.CSharp
                                                "mono\\mono\\mini\\mono.exe");
                                if (!File.Exists (windowsMonoPath))
                                        throw new FileNotFoundException ("Windows mono path not found: " + windowsMonoPath);
-#if NET_4_0
-                               windowsMcsPath =
-                                       Path.Combine (p, "4.0\\dmcs.exe");
-#else
-                               windowsMcsPath =
-                                       Path.Combine (p, "2.0\\gmcs.exe");
-#endif
+
+                               windowsMcsPath = Path.Combine (p, "4.5\\mcs.exe");
                                if (!File.Exists (windowsMcsPath))
-#if NET_4_0
-                                       windowsMcsPath =
-                                               Path.Combine(
-                                                       Path.GetDirectoryName (p),
-                                                       "lib\\net_4_0\\dmcs.exe");
-#else
-                                       windowsMcsPath = 
-                                               Path.Combine(
-                                                       Path.GetDirectoryName (p),
-                                                       "lib\\net_2_0\\gmcs.exe");
-#endif
+                                       windowsMcsPath = Path.Combine(Path.GetDirectoryName (p), "lib\\build\\mcs.exe");
+                               
                                if (!File.Exists (windowsMcsPath))
                                        throw new FileNotFoundException ("Windows mcs path not found: " + windowsMcsPath);
                        }
@@ -179,29 +165,45 @@ namespace Mono.CSharp
 
                        CompilerResults results=new CompilerResults(options.TempFiles);
                        Process mcs=new Process();
-                       
+
                        // FIXME: these lines had better be platform independent.
                        if (Path.DirectorySeparatorChar == '\\') {
                                mcs.StartInfo.FileName = windowsMonoPath;
                                mcs.StartInfo.Arguments = "\"" + windowsMcsPath + "\" " +
                                        BuildArgs (options, fileNames, ProviderOptions);
                        } else {
-                               // FIXME: This is a temporary hack to make code genaration work in 2.0+
-#if NET_4_0
-                               mcs.StartInfo.FileName="dmcs";
-#else
-                               mcs.StartInfo.FileName="gmcs";
-#endif
+                               mcs.StartInfo.FileName="mcs";
                                mcs.StartInfo.Arguments=BuildArgs(options, fileNames, ProviderOptions);
                        }
 
                        mcsOutput = new StringCollection ();
                        mcsOutMutex = new Mutex ();
-
+#if !NET_4_0
+                       /*
+                        * !:. KLUDGE WARNING .:!
+                        *
+                        * When running the 2.0 test suite some assemblies will invoke mcs via
+                        * CodeDOM and the new mcs process will find the MONO_PATH variable in its
+                        * environment pointing to the net_2_0 library which will cause the runtime
+                        * to attempt to load the 2.0 corlib into 4.0 process and thus mcs will
+                        * fail. At the same time, we must not touch MONO_PATH when running outside
+                        * the test suite, thus the kludge.
+                        *
+                        * !:. KLUDGE WARNING .:!
+                        */
+                       if (Environment.GetEnvironmentVariable ("MONO_TESTS_IN_PROGRESS") != null) {
+                               string monoPath = Environment.GetEnvironmentVariable ("MONO_PATH");
+                               if (!String.IsNullOrEmpty (monoPath)) {
+                                       monoPath = monoPath.Replace ("/class/lib/net_2_0", "/class/lib/net_4_0");
+                                       mcs.StartInfo.EnvironmentVariables ["MONO_PATH"] = monoPath;
+                               }
+                       }
+#endif
+/*                    
                        string monoPath = Environment.GetEnvironmentVariable ("MONO_PATH");
-                       if (monoPath == null)
+                       if (monoPath != null)
                                monoPath = String.Empty;
-                       
+
                        string privateBinPath = AppDomain.CurrentDomain.SetupInformation.PrivateBinPath;
                        if (privateBinPath != null && privateBinPath.Length > 0)
                                monoPath = String.Format ("{0}:{1}", privateBinPath, monoPath);
@@ -213,7 +215,13 @@ namespace Mono.CSharp
                                else
                                        dict.Add ("MONO_PATH", monoPath);
                        }
-                       
+*/
+                       /*
+                        * reset MONO_GC_PARAMS - we are invoking compiler possibly with another GC that
+                        * may not handle some of the options causing compilation failure
+                        */
+                       mcs.StartInfo.EnvironmentVariables ["MONO_GC_PARAMS"] = String.Empty;
+
                        mcs.StartInfo.CreateNoWindow=true;
                        mcs.StartInfo.UseShellExecute=false;
                        mcs.StartInfo.RedirectStandardOutput=true;
@@ -273,7 +281,7 @@ namespace Mono.CSharp
                                        using (FileStream fs = File.OpenRead(options.OutputAssembly)) {
                                                byte[] buffer = new byte[fs.Length];
                                                fs.Read(buffer, 0, buffer.Length);
-                                               results.CompiledAssembly = Assembly.Load(buffer, null, options.Evidence);
+                                               results.CompiledAssembly = Assembly.Load(buffer, null);
                                                fs.Close();
                                        }
                                } else {
@@ -365,7 +373,7 @@ namespace Mono.CSharp
 
                                switch (langver) {
                                        case "2.0":
-                                               args.Append ("/langversion:ISO-2");
+                                               args.Append ("/langversion:ISO-2 ");
                                                break;
 
                                        case "3.5":
@@ -374,6 +382,14 @@ namespace Mono.CSharp
                                }
                        }
 
+#if NET_4_5                    
+                       args.Append("/sdk:4.5");
+#elif NET_4_0
+                       args.Append("/sdk:4");
+#else
+                       args.Append("/sdk:2");
+#endif
+
                        args.Append (" -- ");
                        foreach (string source in fileNames)
                                args.AppendFormat("\"{0}\" ",source);