Update
authorMiguel de Icaza <miguel@gnome.org>
Thu, 30 Apr 2009 00:00:27 +0000 (00:00 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Thu, 30 Apr 2009 00:00:27 +0000 (00:00 -0000)
svn path=/trunk/mono/; revision=133096

msvc/scripts/monowrap.cs

index 0caa1ba6d7b14c78b926cab26dfe552a65735328..63326f2e8bf4a43f618261ff4b7b51c2019e021b 100755 (executable)
@@ -1,4 +1,40 @@
-using System;
+//
+// This is a wrapper used to invoke one of the Mono C#
+// compilers with the correct MONO_PATH depending on
+// where this command is located.   
+//
+// This allows us to use MSBuild CscToolPath property to
+// point to this directory to use our compiler to drive
+// the build and set the MONO_PATH as it is expected to
+// be for bootstrap
+//
+// The MONO_PATH and the compiler are chosen based on the
+// directory that hosts the command.
+//
+// The directory specifies a profile, and the format is:
+//     PROFILES-COMPILER
+//
+// Will request that the COMPILER compiler is used setting
+// MONO_PATH to PROFILES.   The PROFILES string can contain
+// multiple directories, separated by dashes.
+//
+// COMPILER is one of:
+//    basic             -> class/lib/basic/mcs.exe
+//    net_1_1_bootstrap -> class/lib/net_1_1_bootstrap/mcs.exe
+//    net_1_1           -> class/lib/net_1_1/mcs.exe
+//    net_2_0_bootstrap -> class/lib/net_2_0_bootstrap/gmcs.exe
+//    gmcs              -> mcs/gmcs.exe
+//    net_2_1_bootstrap -> class/lib/net_2_1_bootstrap/smcs.exe
+//    net_2_1_raw       -> class/lib/net_2_1_raw/smcs.exe
+//
+// So for example:
+// net_2_1_bootstrap-net_2_0-net_2_1_bootstrap
+//
+// Will set MONO_PATH to "%MCS_ROOT%\class\lib\net_2_1_bootstrap;%MCS_ROOT\class\lib\net_2_0"
+// and run the compiler in %MCS_ROOT%\class\lib\net_2_1_bootstrap
+//
+
+using System;
 using System.Collections.Generic;
 using System.IO;
 using System.Text;
@@ -6,64 +42,92 @@ using System.Diagnostics;
 
 namespace csc
 {
-    class Program
-    {
-        //
-        // Executes the Mono command with MONO_PATH set to the
-        // class/lib/PROFILE where PROFILE is the directory where
-        // this executable is hosted, and the tool is the name
-        // of this executable
-        //
-        // This allows us to use MSBuild CscToolPath property to
-        // point to this directory to use our compiler to drive
-        // the build and set the MONO_PATH as it is expected to
-        // be for bootstrap
-        //
-        static int Main(string[] args)
-        {
-            string cmd = Environment.GetCommandLineArgs () [0];
-            string tool = Path.GetFileName(cmd);
-            string profile = Path.GetDirectoryName(cmd);
-            int p = profile.LastIndexOf('\\');
-            if (p == -1) {
-                Console.Error.WriteLine("Could not find the profile name from this {0}", profile);
-                return 1;
-            }
-            profile = profile.Substring(p+1);
+       class Program
+       {
+               static int Main(string[] args)
+               {
+                       string cmd = Environment.GetCommandLineArgs () [0];
+                       string tool = Path.GetFileName(cmd);
+                       string profile = Path.GetDirectoryName(cmd);
+                       int p = profile.LastIndexOf('\\');
+                       if (p == -1) {
+                               Console.Error.WriteLine("Could not find the profile name from this {0}", profile);
+                               return 1;
+                       }
+                       profile = profile.Substring(p+1);
+
+                       var root_mono = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(cmd), "..\\..\\.."));
+                       if (!File.Exists(Path.Combine(root_mono, "mono\\mini\\mini.c"))) {
+                               Console.WriteLine("My root is incorrect {0} based on {1}", root_mono, cmd);
+                               Console.WriteLine("Must be in mono/msvc/scripts/PROFILE/COMMAND.exe");
+                               return 1;
+                       }
+
+                       p = profile.LastIndexOf ('-');
+                       if (p == -1){
+                               Console.Error.WriteLine("The directory holding this executable should be MPATHS-COMPILER, instead it is: {0}", profile);
+                               return 1;
+                       }
+
+                       var root_mcs = Path.GetFullPath (Path.Combine (root_mono, "..\\mcs"));
+                       var mono_cmd = root_mono + "\\msvc\\Win32_Debug_eglib\\bin\\mono.exe";
 
-           if (tool.ToLower () == "csc.exe"){
-               if (profile.IndexOf ("net_2_0") != -1)
-                  tool = "gmcs.exe";
-                else if (profile.IndexOf ("net_2_1") != -1)
-                  tool = "smcs.exe";
-               else
-                  tool = "mcs.exe";
-           }
+                       string compiler = null;
+                       switch (profile.Substring (p+1)){
+                       case "basic":
+                               compiler = root_mcs + "\\class\\lib\\basic\\mcs.exe";
+                               break;
+                       case "net_1_1_bootstrap":
+                               compiler = root_mcs + "\\class\\lib\\net_1_1_bootstrap\\mcs.exe";
+                               break;
+                               
+                       case "net_1_1":
+                               compiler = root_mcs + "\\class\\lib\\net_1_1\\mcs.exe";
+                               break;
+                               
+                       case "net_2_0_bootstrap":
+                               compiler = root_mcs + "\\class\\lib\\net_2_0_bootstrap\\gmcs.exe";
+                               break;
+                               
+                       case "mcs":
+                               compiler = root_mcs + "\\mcs\\gmcs.exe";
+                               break;
+                               
+                       case "net_2_1_bootstrap":
+                               compiler = root_mcs + "\\class\\lib\\net_2_1_bootstrap\\smcs.exe";
+                               break;
+                               
+                       case "net_2_1_raw":
+                               compiler = root_mcs + "\\class\\lib\\net_2_1_raw\\smcs.exe";
+                               break;
 
-            var root_mono = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(cmd), "..\\..\\.."));
-            if (!File.Exists(Path.Combine(root_mono, "mono\\mini\\mini.c"))) {
-                Console.WriteLine("My root is incorrect {0} based on {1}", root_mono, cmd);
-                Console.WriteLine("Must be in mono/msvc/scripts/PROFILE/COMMAND.exe");
-                return 1;
-            }
-            var root_mcs = Path.GetFullPath (Path.Combine (root_mono, "..\\mcs"));
-            var mono_cmd = root_mono + "\\msvc\\Win32_Debug_eglib\\bin\\mono.exe";
-            var tool_cmd = root_mcs + "\\class\\lib\\" + profile + "\\" + tool;
+                       default:
+                               Console.WriteLine ("Unknown compiler configuration: {0}", profile.Substring (p+1));
+                               return 1;
 
-            Console.WriteLine("root_mcs={0}\nmono_cmd={1}\ntool_cmd={2}", root_mcs, mono_cmd, tool_cmd);
-            Environment.SetEnvironmentVariable ("MONO_PATH", root_mcs + "\\class\\lib\\net_1_1_bootstrap");
+                       }
+                       var paths = profile.Substring (0, p).Split (new char [] { '-' });
+                       StringBuilder sb = new StringBuilder ();
+                       foreach (string dir in paths){
+                               if (sb.Length != 0)
+                                       sb.Append (";");
+                               sb.Append (root_mcs + "\\class\\lib\\" + dir);
+                       }
+                       Environment.SetEnvironmentVariable ("MONO_PATH", sb.ToString ());
 
-            var pi = new ProcessStartInfo() {
-                FileName = mono_cmd,
-                WindowStyle = ProcessWindowStyle.Hidden,
-                Arguments = tool_cmd + " " + String.Join (" ", args),
-                UseShellExecute = false
-            };
+                       Console.WriteLine ("Compiler: {0}", compiler);
+                       Console.WriteLine ("MONO_PATH: {0}", sb.ToString ());
+                       var pi = new ProcessStartInfo() {
+                               FileName = mono_cmd,
+                               WindowStyle = ProcessWindowStyle.Hidden,
+                               Arguments = compiler + " " + String.Join (" ", args),
+                               UseShellExecute = false
+                       };
 
-            var proc = Process.Start (pi);
+                       var proc = Process.Start (pi);
 
-            proc.WaitForExit();
-            return proc.ExitCode;
-        }
-    }
+                       proc.WaitForExit();
+                       return proc.ExitCode;
+               }
+       }
 }