3 using System.Diagnostics;
4 using System.Configuration;
6 using System.Collections;
7 using System.Collections.Specialized;
9 namespace ReactOS.Verify
11 public class MainClass
14 /// Run the application.
16 /// <param name="script">Script to run.</param>
17 /// <param name="args">Arguments to pass to script.</param>
18 /// <param name="workingDirectory">Working directory.</param>
19 /// <param name="standardOutput">Receives standard output.</param>
20 /// <param name="standardError">Receives standard error.</param>
24 private static int RunScript(string script,
26 string workingDirectory,
27 StringDictionary environmentVarables,
28 out string standardOutput,
29 out string standardError)
31 ProcessStartInfo scriptProcessStartInfo = new ProcessStartInfo(script,
33 scriptProcessStartInfo.CreateNoWindow = true;
35 * All standard streams must be redirected.
36 * Otherwise DuplicateHandle() will fail.
38 scriptProcessStartInfo.RedirectStandardInput = true;
39 scriptProcessStartInfo.RedirectStandardError = true;
40 scriptProcessStartInfo.RedirectStandardOutput = true;
41 scriptProcessStartInfo.UseShellExecute = false;
42 scriptProcessStartInfo.WorkingDirectory = workingDirectory;
43 if (environmentVarables != null)
45 foreach (DictionaryEntry de in environmentVarables)
46 scriptProcessStartInfo.EnvironmentVariables.Add(de.Key as string, de.Value as string);
48 RedirectableProcess redirectableProcess = new RedirectableProcess(scriptProcessStartInfo);
49 standardOutput = redirectableProcess.ProcessOutput;
50 standardError = redirectableProcess.ProcessError;
51 return redirectableProcess.ExitCode;
55 /// Retrieve value of configuration from configuration file.
57 /// <param name="name">Name of configuration option.</param>
58 /// <param name="defaultValue">
59 /// Default value to be returned if the option does not exist.
62 /// Value of configuration option or null if the option does not
63 /// exist and no default value is provided.
65 private static string GetConfigurationOption(string name,
68 if (ConfigurationSettings.AppSettings[name] != null)
70 string s = ConfigurationSettings.AppSettings[name].Trim();
71 return s.Equals(String.Empty) ? defaultValue : s;
80 /// <param name="subject">Subject of the email.</param>
81 /// <param name="body">Content of the email.</param>
82 private static void SendErrorMail(string subject, string body)
86 string smtpServer = GetConfigurationOption("smtpServer", "localhost");
87 string email = GetConfigurationOption("errorEmail", null);
90 MailMessage mm = new MailMessage();
91 mm.Priority = MailPriority.Normal;
97 mm.BodyFormat = MailFormat.Html;
98 SmtpMail.SmtpServer = smtpServer;
103 Console.Error.WriteLine(ex.Message);
108 /// Fail with an error message.
110 /// <param name="text">Error message.</param>
111 private static void Fail(string text)
113 Console.WriteLine(text);
117 /// Paths to fast disk for temporary files.
119 private static string TemporaryFastDisk
123 string temporaryFastDisk = GetConfigurationOption("temporaryFastDisk", null);
124 if (temporaryFastDisk == null || temporaryFastDisk.Trim().Equals(String.Empty))
126 return temporaryFastDisk.Trim();
131 /// Paths to fast disk for intermediate files.
133 private static string IntermediateFastDisk
137 string intermediateFastDisk = GetConfigurationOption("intermediateFastDisk", null);
138 if (intermediateFastDisk == null || intermediateFastDisk.Trim().Equals(String.Empty))
140 return intermediateFastDisk.Trim();
145 /// Paths to fast disk for output files.
147 private static string OutputFastDisk
151 string outputFastDisk = GetConfigurationOption("outputFastDisk", null);
152 if (outputFastDisk == null || outputFastDisk.Trim().Equals(String.Empty))
154 return outputFastDisk.Trim();
159 /// Return collection of environment variables.
161 /// <returns>Collection of environment variables or null if there is none.</returns>
162 private static StringDictionary GetEnvironmentVarables()
164 StringDictionary environmentVarables = new StringDictionary();
165 if (TemporaryFastDisk != null)
166 environmentVarables.Add("ROS_TEMPORARY", TemporaryFastDisk);
167 if (IntermediateFastDisk != null)
168 environmentVarables.Add("ROS_INTERMEDIATE", IntermediateFastDisk);
169 if (OutputFastDisk != null)
170 environmentVarables.Add("ROS_OUTPUT", OutputFastDisk);
171 return environmentVarables;
177 /// <param name="arguments">Arguments.</param>
178 /// <param name="standardOutput">Receives standard output.</param>
179 /// <param name="standardError">Receives standard error.</param>
180 /// <returns>Make exit code.</returns>
181 private static int RunMake(string arguments,
182 out string standardOutput,
183 out string standardError)
185 string make = "mingw32-make";
186 string makeParameters = GetConfigurationOption("makeParameters", "");
187 string reactosDirectory = Path.Combine(System.Environment.CurrentDirectory,
189 return RunScript(make,
190 makeParameters + " " + arguments,
192 GetEnvironmentVarables(),
198 /// Verify a revision of ReactOS by building it all.
200 private static int VerifyFull()
202 string standardOutput;
203 string standardError;
204 int exitCode = RunMake("bootcd",
209 Fail(String.Format("make bootcd failed: (error: {0}) {1}",
215 string reactosDirectory = Path.Combine(System.Environment.CurrentDirectory,
217 string isoFilename = Path.Combine(reactosDirectory,
219 if (!File.Exists(isoFilename))
220 Fail("make bootcd produced no ReactOS.iso");
226 /// Verify a revision of ReactOS by building parts.
228 /// <param name="components">Comma separated list of components to build.</param>
229 private static int VerifyPartial(string components)
231 string standardOutput;
232 string standardError;
233 string componentParameters = "\"" + components.Replace(",", "\" \"") + "\"";
234 int exitCode = RunMake(componentParameters,
238 Fail(String.Format("make failed for targets {0}: (error: {1}) {2}",
246 /// Verify a revision of ReactOS.
248 /// <param name="args">Arguments from command line.</param>
249 private static int Verify(string[] args)
252 return VerifyPartial(args[0]);
258 /// Program entry point.
260 /// <param name="args">Arguments from command line.</param>
262 /// If exit code is 0, then the commit was processed successfully.
263 /// If exit code is 1, then the commit was not processed successfully.
265 public static void Main(string[] args)
269 System.Environment.ExitCode = Verify(args);
273 string text = String.Format("Exception: {0}", ex);
274 SendErrorMail("ReactOS Verify Error", text);
275 System.Environment.ExitCode = 1;