@@ -38,10 +38,11 @@ pub struct Semantic {
3838
3939/// The all model is combining the intercept and semantic modes.
4040pub struct All {
41- input : args:: BuildCommand ,
42- output : args:: BuildSemantic ,
41+ command : args:: BuildCommand ,
4342 intercept_config : config:: Intercept ,
44- output_config : config:: Output ,
43+ semantic_recognition : Recognition ,
44+ semantic_transform : Transformation ,
45+ output_writer : OutputWriter ,
4546}
4647
4748impl Intercept {
@@ -60,23 +61,22 @@ impl Intercept {
6061 /// Write the envelopes into the output file.
6162 fn write_to_file (
6263 output_file_name : String ,
63- envelopes : impl IntoIterator < Item = Envelope > ,
64+ envelopes : impl IntoIterator < Item = Envelope > ,
6465 ) -> anyhow:: Result < ( ) > {
6566 let mut writer = std:: fs:: File :: create ( & output_file_name)
6667 . map ( BufWriter :: new)
6768 . with_context ( || format ! ( "Failed to create output file: {:?}" , & output_file_name) ) ?;
6869 for envelope in envelopes {
69- envelope
70- . write_into ( & mut writer )
71- . with_context ( || "Failed to write the envelope" ) ?;
70+ envelope. write_into ( & mut writer ) . with_context ( || {
71+ format ! ( "Failed to write execution report: {:?}" , & output_file_name )
72+ } ) ?;
7273 }
7374 Ok ( ( ) )
7475 }
7576}
7677
7778impl Mode for Intercept {
7879 fn run ( self ) -> anyhow:: Result < ExitCode > {
79- // TODO: log failures with the right context
8080 let output_file_name = self . output . file_name . clone ( ) ;
8181 let service = InterceptService :: new ( move |envelopes| {
8282 Self :: write_to_file ( output_file_name, envelopes)
@@ -128,23 +128,58 @@ impl Mode for Semantic {
128128
129129impl All {
130130 pub fn new (
131- input : args:: BuildCommand ,
132- output : args:: BuildSemantic ,
131+ command : args:: BuildCommand ,
133132 intercept_config : config:: Intercept ,
134- output_config : config:: Output ,
133+ semantic_recognition : Recognition ,
134+ semantic_transform : Transformation ,
135+ output_writer : OutputWriter ,
135136 ) -> Self {
136137 Self {
137- input,
138- output,
138+ command,
139139 intercept_config,
140- output_config,
140+ semantic_recognition,
141+ semantic_transform,
142+ output_writer,
141143 }
142144 }
145+
146+ fn consume_for_analysis (
147+ semantic_recognition : Recognition ,
148+ semantic_transform : Transformation ,
149+ output_writer : OutputWriter ,
150+ envelopes : impl IntoIterator < Item = Envelope > ,
151+ ) -> anyhow:: Result < ( ) > {
152+ let entries = envelopes
153+ . into_iter ( )
154+ . map ( |envelope| envelope. event . execution )
155+ . flat_map ( |execution| semantic_recognition. apply ( execution) )
156+ . flat_map ( |semantic| semantic_transform. apply ( semantic) ) ;
157+
158+ output_writer. run ( entries)
159+ }
143160}
144161
145162impl Mode for All {
146163 fn run ( self ) -> anyhow:: Result < ExitCode > {
147- // TODO: Implement the all mode.
148- Ok ( ExitCode :: FAILURE )
164+ let semantic_recognition = self . semantic_recognition ;
165+ let semantic_transform = self . semantic_transform ;
166+ let output_writer = self . output_writer ;
167+ let service = InterceptService :: new ( move |envelopes| {
168+ Self :: consume_for_analysis (
169+ semantic_recognition,
170+ semantic_transform,
171+ output_writer,
172+ envelopes,
173+ )
174+ } )
175+ . with_context ( || "Failed to create the intercept service" ) ?;
176+ let environment = InterceptEnvironment :: new ( & self . intercept_config , service. address ( ) )
177+ . with_context ( || "Failed to create the intercept environment" ) ?;
178+
179+ let status = environment
180+ . execute_build_command ( self . command )
181+ . with_context ( || "Failed to execute the build command" ) ?;
182+
183+ Ok ( status)
149184 }
150185}
0 commit comments