33pub mod intercept;
44pub mod semantic;
55
6- use crate :: intercept:: persistence;
76use crate :: modes:: intercept:: BuildInterceptor ;
87use crate :: modes:: semantic:: SemanticAnalysisPipeline ;
8+ use crate :: output:: { ExecutionEventDatabase , FileFormat } ;
99use crate :: { args, config} ;
1010use anyhow:: Context ;
11- use std:: fs:: { File , OpenOptions } ;
12- use std:: io;
1311use std:: io:: BufReader ;
1412use std:: process:: ExitCode ;
13+ use std:: { fs, io, path} ;
1514
1615/// The mode trait is used to run the application in different modes.
1716pub trait Mode {
@@ -32,17 +31,13 @@ impl Intercept {
3231 output : args:: BuildEvents ,
3332 config : config:: Main ,
3433 ) -> anyhow:: Result < Self > {
35- let file_name = output. file_name . as_str ( ) ;
36- let output_file = OpenOptions :: new ( )
37- . write ( true )
38- . create ( true )
39- . truncate ( true )
40- . open ( file_name)
34+ let file_name = path:: PathBuf :: from ( output. file_name ) ;
35+ let output_file = fs:: File :: create ( file_name. as_path ( ) )
4136 . map ( io:: BufWriter :: new)
4237 . with_context ( || format ! ( "Failed to open file: {:?}" , file_name) ) ?;
4338
4439 let interceptor = BuildInterceptor :: create ( config, move |events| {
45- persistence :: write ( output_file, events)
40+ ExecutionEventDatabase :: write ( output_file, events. iter ( ) ) . map_err ( anyhow :: Error :: from )
4641 } ) ?;
4742
4843 Ok ( Self {
@@ -66,7 +61,8 @@ impl Mode for Intercept {
6661/// The semantic mode we are deduct the semantic meaning of the
6762/// executed commands from the build process.
6863pub struct Semantic {
69- event_file : BufReader < File > ,
64+ event_file : BufReader < fs:: File > ,
65+ event_file_name : path:: PathBuf ,
7066 semantic : SemanticAnalysisPipeline ,
7167}
7268
@@ -76,17 +72,16 @@ impl Semantic {
7672 output : args:: BuildSemantic ,
7773 config : config:: Main ,
7874 ) -> anyhow:: Result < Self > {
79- let file_name = input. file_name . as_str ( ) ;
80- let event_file = OpenOptions :: new ( )
81- . read ( true )
82- . open ( file_name)
75+ let event_file_name = path:: PathBuf :: from ( input. file_name ) ;
76+ let event_file = fs:: File :: open ( event_file_name. as_path ( ) )
8377 . map ( BufReader :: new)
84- . with_context ( || format ! ( "Failed to open file: {:?}" , file_name ) ) ?;
78+ . with_context ( || format ! ( "Failed to open file: {:?}" , event_file_name ) ) ?;
8579
8680 let semantic = SemanticAnalysisPipeline :: create ( output, & config) ?;
8781
8882 Ok ( Self {
8983 event_file,
84+ event_file_name,
9085 semantic,
9186 } )
9287 }
@@ -98,7 +93,10 @@ impl Mode for Semantic {
9893 /// The exit code is based on the result of the output writer.
9994 fn run ( self ) -> anyhow:: Result < ExitCode > {
10095 self . semantic
101- . analyze_and_write ( persistence:: read ( self . event_file ) )
96+ . analyze_and_write ( ExecutionEventDatabase :: read_and_ignore (
97+ self . event_file ,
98+ self . event_file_name ,
99+ ) )
102100 . map ( |_| ExitCode :: SUCCESS )
103101 }
104102}
0 commit comments