static System.Threading.Tasks.Task ProcessOutputStreamReader( System.IO.StreamReader reader, RustProjectNode rustProjectNode, string category = "BUILD", bool printBuildOutput = true, bool printRustcParsedMessages = false) { return(System.Threading.Tasks.Task.Run(() => { string errorOutput = reader.ReadToEnd(); var rustcErrors = RustcOutputProcessor.ParseOutput(errorOutput); if (printBuildOutput) { ProjectUtil.PrintToBuild(errorOutput); } foreach (var msg in rustcErrors) { TaskMessages.QueueRustcMessage("Rust", msg, rustProjectNode, refresh: false); if (printRustcParsedMessages) { ProjectUtil.PrintToBuild(msg.ToString()); } } TaskMessages.Refresh(); })); }
System.Threading.Tasks.Task ProcessOutputStreamReader( System.IO.StreamReader reader, string category = "BUILD", bool printBuildOutput = true, bool printRustcParsedMessages = false) { return(System.Threading.Tasks.Task.Run(() => { string output = reader.ReadToEnd(); var rustMessages = RustcOutputProcessor.ParseOutput(output); LogCriticalMessage(output); foreach (var msg in rustMessages) { Log.LogError("Rust", msg.ErrorCode, "", msg.File, msg.LineNumber, msg.ColumnNumber, msg.EndLineNumber, msg.EndColumnNumber, msg.Message); } })); }
private bool ExecuteInner() { string rustBinPath = VisualRust.Shared.Environment.FindInstallPath(VisualRust.Shared.Environment.DefaultTarget); if (rustBinPath == null) { Log.LogError("No Rust installation detected. You can download official Rust installer from rust-lang.org/install."); return(false); } StringBuilder sb = new StringBuilder(); if (ConfigFlags.Length > 0) { sb.AppendFormat(" --cfg {0}", String.Join(",", ConfigFlags)); } if (AdditionalLibPaths.Length > 0) { sb.AppendFormat(" -L {0}", String.Join(",", AdditionalLibPaths)); } if (CrateType.Length > 0) { sb.AppendFormat(" --crate-type {0}", String.Join(",", CrateType)); } if (Emit.Length > 0) { sb.AppendFormat(" --emit {0}", String.Join(",", Emit)); } if (!String.IsNullOrWhiteSpace(CrateName)) { sb.AppendFormat(" --crate-name {0}", CrateName); } if (DebugInfo) { sb.AppendFormat(" -g"); } if (OutputFile != null) { sb.AppendFormat(" -o {0}", OutputFile); } if (optimizationLevel.HasValue) { sb.AppendFormat(" -C opt-level={0}", Shared.OptimizationLevelExtension.Parse(OptimizationLevel.ToString()).ToBuildString()); } if (OutputDirectory != null) { sb.AppendFormat(" --out-dir {0}", OutputDirectory); } if (test.HasValue && test.Value) { sb.Append(" --test"); } if (TargetTriple != null && !String.Equals(TargetTriple, Shared.Environment.DefaultTarget, StringComparison.OrdinalIgnoreCase)) { sb.AppendFormat(" --target {0}", TargetTriple); } if (LintsAsWarnings.Length > 0) { sb.AppendFormat(" -W {0}", String.Join(",", LintsAsWarnings)); } if (LintsAsAllowed.Length > 0) { sb.AppendFormat(" -A {0}", String.Join(",", LintsAsAllowed)); } if (LintsAsDenied.Length > 0) { sb.AppendFormat(" -D {0}", String.Join(",", LintsAsDenied)); } if (LintsAsForbidden.Length > 0) { sb.AppendFormat(" -F {0}", String.Join(",", LintsAsForbidden)); } if (lto.HasValue && lto.Value) { sb.AppendFormat(" -C lto"); } if (CodegenOptions != null) { sb.AppendFormat(" -C {0}", CodegenOptions); } sb.AppendFormat(" {0}", Input); string target = TargetTriple ?? Shared.Environment.DefaultTarget; string installPath = Shared.Environment.FindInstallPath(target); if (installPath == null) { if (String.Equals(target, Shared.Environment.DefaultTarget, StringComparison.OrdinalIgnoreCase)) { Log.LogError("Could not find a Rust installation."); } else { Log.LogError("Could not find a Rust installation that can compile target {0}.", target); } return(false); } var psi = new ProcessStartInfo() { CreateNoWindow = true, FileName = Path.Combine(installPath, "rustc.exe"), UseShellExecute = false, WorkingDirectory = WorkingDirectory, Arguments = sb.ToString(), RedirectStandardError = true }; Log.LogCommandLine(String.Join(" ", psi.FileName, psi.Arguments)); try { Process process = new Process(); process.StartInfo = psi; StringBuilder error = new StringBuilder(); StringBuilder output = new StringBuilder(); using (AutoResetEvent errorWaitHandle = new AutoResetEvent(false)) //using (AutoResetEvent outputWaitHandle = new AutoResetEvent(false)) { process.OutputDataReceived += (sender, e) => { if (e.Data != null) { foreach (RustcParsedMessage msg in RustcOutputProcessor.ParseOutput(e.Data)) { RustcOutputProcessor.LogRustcMessage(msg, this.Log); } } //if (e.Data == null) // outputWaitHandle.Set(); //else // output.AppendLine(e.Data); }; process.ErrorDataReceived += (sender, e) => { if (e.Data == null) { errorWaitHandle.Set(); } else { error.AppendLine(e.Data); } }; process.Start(); process.BeginErrorReadLine(); process.WaitForExit(); errorWaitHandle.WaitOne(); } string errorOutput = error.ToString(); //string outputOutput = output.ToString(); // We found some warning or errors in the output, print them out IEnumerable <RustcParsedMessage> messages = RustcOutputProcessor.ParseOutput(errorOutput); // Other messages //IEnumerable<RustcParsedMessage> outputMessages = ParseOutput(outputOutput); // We found some warning or errors in the output, print them out foreach (RustcParsedMessage msg in messages) { RustcOutputProcessor.LogRustcMessage(msg, this.Log); } // Print other messages //foreach (RustcParsedMessage msg in outputMessages) // LogRustcMessage(msg); // rustc failed but we couldn't sniff anything from stderr // this could be an internal compiler error or a missing main() function (there are probably more errors without spans) if (process.ExitCode != 0 && !messages.Any()) { // FIXME: This automatically sets the file to VisualRust.Rust.targets. Is there a way to set no file instead? this.Log.LogError(errorOutput); return(false); } return(process.ExitCode == 0); } catch (Exception ex) { Log.LogErrorFromException(ex, true); return(false); } }