2 // This is a wrapper used to invoke one of the Mono C#
3 // compilers with the correct MONO_PATH depending on
4 // where this command is located.
6 // This allows us to use MSBuild CscToolPath property to
7 // point to this directory to use our compiler to drive
8 // the build and set the MONO_PATH as it is expected to
11 // The MONO_PATH and the compiler are chosen based on the
12 // directory that hosts the command.
14 // The directory specifies a profile, and the format is:
17 // Will request that the COMPILER compiler is used setting
18 // MONO_PATH to PROFILES. The PROFILES string can contain
19 // multiple directories, separated by dashes.
21 // COMPILER is one of:
22 // basic -> class/lib/basic/mcs.exe
23 // net_1_1_bootstrap -> class/lib/net_1_1_bootstrap/mcs.exe
24 // net_1_1 -> class/lib/net_1_1/mcs.exe
25 // net_2_0_bootstrap -> class/lib/net_2_0_bootstrap/gmcs.exe
26 // gmcs -> mcs/gmcs.exe
27 // moonlight_bootstrap -> class/lib/moonlight_bootstrap/smcs.exe
28 // moonlight_raw -> class/lib/moonlight_raw/smcs.exe
31 // moonlight_bootstrap-net_2_0-moonlight_bootstrap
33 // Will set MONO_PATH to "%MCS_ROOT%\class\lib\moonlight_bootstrap;%MCS_ROOT\class\lib\net_2_0"
34 // and run the compiler in %MCS_ROOT%\class\lib\moonlight_bootstrap
38 using System
.Collections
.Generic
;
41 using System
.Diagnostics
;
47 static int Main(string[] args
)
49 string cmd
= Environment
.GetCommandLineArgs () [0];
50 string tool
= Path
.GetFileName(cmd
);
51 string profile
= Path
.GetDirectoryName(cmd
);
52 int p
= profile
.LastIndexOf('\\');
54 Console
.Error
.WriteLine("Could not find the profile name from this {0}", profile
);
57 profile
= profile
.Substring(p
+1);
59 var root_mono
= Path
.GetFullPath(Path
.Combine(Path
.GetDirectoryName(cmd
), "..\\..\\.."));
60 if (!File
.Exists(Path
.Combine(root_mono
, "mono\\mini\\mini.c"))) {
61 Console
.WriteLine("My root is incorrect {0} based on {1}", root_mono
, cmd
);
62 Console
.WriteLine("Must be in mono/msvc/scripts/PROFILE/COMMAND.exe");
66 p
= profile
.LastIndexOf ('-');
68 Console
.Error
.WriteLine("The directory holding this executable should be MPATHS-COMPILER, instead it is: {0}", profile
);
72 var root_mcs
= Path
.GetFullPath (Path
.Combine (root_mono
, "..\\mcs"));
73 var mono_cmd
= root_mono
+ "\\msvc\\Win32_Debug_eglib\\bin\\mono.exe";
75 string compiler
= null;
76 switch (profile
.Substring (p
+1)){
78 compiler
= root_mcs
+ "\\class\\lib\\basic\\mcs.exe";
80 case "net_1_1_bootstrap":
81 compiler
= root_mcs
+ "\\class\\lib\\net_1_1_bootstrap\\mcs.exe";
85 compiler
= root_mcs
+ "\\class\\lib\\net_1_1\\mcs.exe";
88 case "net_2_0_bootstrap":
89 compiler
= root_mcs
+ "\\class\\lib\\net_2_0_bootstrap\\gmcs.exe";
94 compiler
= root_mcs
+ "\\mcs\\gmcs.exe";
97 case "moonlight_bootstrap":
98 compiler
= root_mcs
+ "\\class\\lib\\moonlight_bootstrap\\smcs.exe";
101 case "moonlight_raw":
102 compiler
= root_mcs
+ "\\class\\lib\\moonlight_raw\\smcs.exe";
106 Console
.WriteLine ("Unknown compiler configuration: {0}", profile
.Substring (p
+1));
110 var paths
= profile
.Substring (0, p
).Split (new char [] { '-' }
);
111 StringBuilder sb
= new StringBuilder ();
112 foreach (string dir
in paths
){
115 sb
.Append (root_mcs
+ "\\class\\lib\\" + dir
);
117 Environment
.SetEnvironmentVariable ("MONO_PATH", sb
.ToString ());
119 Console
.WriteLine ("Compiler: {0}", compiler
);
120 Console
.WriteLine ("MONO_PATH: {0}", sb
.ToString ());
121 var pi
= new ProcessStartInfo() {
123 WindowStyle
= ProcessWindowStyle
.Hidden
,
124 Arguments
= compiler
+ " " + String
.Join (" ", args
),
125 UseShellExecute
= false
129 var proc
= Process
.Start (pi
);
132 return proc
.ExitCode
;
133 } catch (System
.ComponentModel
.Win32Exception
){
134 Console
.Error
.WriteLine ("Chances are, it did not find {0}", mono_cmd
);