1- use std:: sync:: mpsc:: SyncSender ;
1+ // Copyright 2020 The Bazel Authors. All rights reserved.
2+ //
3+ // Licensed under the Apache License, Version 2.0 (the "License");
4+ // you may not use this file except in compliance with the License.
5+ // You may obtain a copy of the License at
6+ //
7+ // http://www.apache.org/licenses/LICENSE-2.0
8+ //
9+ // Unless required by applicable law or agreed to in writing, software
10+ // distributed under the License is distributed on an "AS IS" BASIS,
11+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ // See the License for the specific language governing permissions and
13+ // limitations under the License.
14+
215use tinyjson:: JsonValue ;
316
17+ use crate :: output:: LineOutput ;
18+
419#[ derive( Debug , Copy , Clone ) ]
520pub ( crate ) enum ErrorFormat {
621 Json ,
@@ -25,36 +40,39 @@ fn get_key(value: &JsonValue, key: &str) -> Option<String> {
2540 }
2641}
2742
28- // stop_on_rmeta_completion takes an output line from rustc configured with
29- // --error-format=json, parses the json and returns the appropriate output
30- // according to the original --error-format supplied to rustc.
31- // In addition, it will send a signal to the stop channel when metadata is emitted
32- // so the compiler can be terminated.
33- // This is used to implement pipelining in rules_rust, please see
34- // https://internals.rust-lang.org/t/evaluating-pipelined-rustc-compilation/10199
43+ /// stop_on_rmeta_completion takes an output line from rustc configured with
44+ /// --error-format=json, parses the json and returns the appropriate output
45+ /// according to the original --error-format supplied to rustc.
46+ /// In addition, it will signal to stop when metadata is emitted
47+ /// so the compiler can be terminated.
48+ /// This is used to implement pipelining in rules_rust, please see
49+ /// https://internals.rust-lang.org/t/evaluating-pipelined-rustc-compilation/10199
3550pub ( crate ) fn stop_on_rmeta_completion (
3651 line : String ,
3752 error_format : ErrorFormat ,
38- stop : & SyncSender < ( ) > ,
39- ) -> Option < String > {
53+ kill : & mut bool ,
54+ ) -> LineOutput {
4055 let parsed: JsonValue = line
4156 . parse ( )
4257 . expect ( "process wrapper error: expected json messages in pipeline mode" ) ;
4358 if let Some ( emit) = get_key ( & parsed, "emit" ) {
4459 // We don't want to print emit messages.
4560 // If the emit messages is "metadata" we can signal the process to quit
46- if emit == "metadata" {
47- stop. send ( ( ) )
48- . expect ( "process wrapper error: receiver closed" ) ;
49- }
50- return None ;
61+ return if emit == "metadata" {
62+ * kill = true ;
63+ LineOutput :: Terminate
64+ } else {
65+ LineOutput :: Skip
66+ } ;
5167 } ;
5268
5369 match error_format {
5470 // If the output should be json, we just forward the messages as-is
55- ErrorFormat :: Json => Some ( line) ,
71+ ErrorFormat :: Json => LineOutput :: Message ( line) ,
5672 // Otherwise we extract the "rendered" attribute.
5773 // If we don't find it we skip the line.
58- _ => get_key ( & parsed, "rendered" ) ,
74+ _ => get_key ( & parsed, "rendered" )
75+ . map ( LineOutput :: Message )
76+ . unwrap_or ( LineOutput :: Skip ) ,
5977 }
6078}
0 commit comments