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
+
2
15
use tinyjson:: JsonValue ;
3
16
17
+ use crate :: output:: LineOutput ;
18
+
4
19
#[ derive( Debug , Copy , Clone ) ]
5
20
pub ( crate ) enum ErrorFormat {
6
21
Json ,
@@ -25,36 +40,39 @@ fn get_key(value: &JsonValue, key: &str) -> Option<String> {
25
40
}
26
41
}
27
42
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
35
50
pub ( crate ) fn stop_on_rmeta_completion (
36
51
line : String ,
37
52
error_format : ErrorFormat ,
38
- stop : & SyncSender < ( ) > ,
39
- ) -> Option < String > {
53
+ kill : & mut bool ,
54
+ ) -> LineOutput {
40
55
let parsed: JsonValue = line
41
56
. parse ( )
42
57
. expect ( "process wrapper error: expected json messages in pipeline mode" ) ;
43
58
if let Some ( emit) = get_key ( & parsed, "emit" ) {
44
59
// We don't want to print emit messages.
45
60
// 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
+ } ;
51
67
} ;
52
68
53
69
match error_format {
54
70
// If the output should be json, we just forward the messages as-is
55
- ErrorFormat :: Json => Some ( line) ,
71
+ ErrorFormat :: Json => LineOutput :: Message ( line) ,
56
72
// Otherwise we extract the "rendered" attribute.
57
73
// 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 ) ,
59
77
}
60
78
}
0 commit comments