@@ -5,6 +5,7 @@ use std::path::{Path, PathBuf};
5
5
use std:: str;
6
6
use std:: sync:: { Arc , Mutex } ;
7
7
8
+ use crate :: core:: compiler:: job_queue:: JobState ;
8
9
use crate :: core:: PackageId ;
9
10
use crate :: util:: errors:: { CargoResult , CargoResultExt } ;
10
11
use crate :: util:: machine_message;
@@ -96,20 +97,21 @@ pub fn prepare<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRe
96
97
}
97
98
}
98
99
99
- fn emit_build_output ( output : & BuildOutput , package_id : PackageId ) {
100
+ fn emit_build_output ( state : & JobState < ' _ > , output : & BuildOutput , package_id : PackageId ) {
100
101
let library_paths = output
101
102
. library_paths
102
103
. iter ( )
103
104
. map ( |l| l. display ( ) . to_string ( ) )
104
105
. collect :: < Vec < _ > > ( ) ;
105
106
106
- machine_message:: emit ( & machine_message:: BuildScript {
107
+ let msg = machine_message:: emit ( & machine_message:: BuildScript {
107
108
package_id,
108
109
linked_libs : & output. library_links ,
109
110
linked_paths : & library_paths,
110
111
cfgs : & output. cfgs ,
111
112
env : & output. env ,
112
113
} ) ;
114
+ state. stdout ( & msg) ;
113
115
}
114
116
115
117
fn build_work < ' a , ' cfg > ( cx : & mut Context < ' a , ' cfg > , unit : & Unit < ' a > ) -> CargoResult < Job > {
@@ -299,52 +301,58 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
299
301
}
300
302
}
301
303
302
- // And now finally, run the build command itself!
303
304
if build_plan {
304
305
state. build_plan ( invocation_name, cmd. clone ( ) , Arc :: new ( Vec :: new ( ) ) ) ;
305
- } else {
306
- state. running ( & cmd) ;
307
- let timestamp = paths:: set_invocation_time ( & script_run_dir) ?;
308
- let output = if extra_verbose {
309
- let prefix = format ! ( "[{} {}] " , id. name( ) , id. version( ) ) ;
310
- state. capture_output ( & cmd, Some ( prefix) , true )
311
- } else {
312
- cmd. exec_with_output ( )
313
- } ;
314
- let output = output. map_err ( |e| {
315
- failure:: format_err!(
316
- "failed to run custom build command for `{}`\n {}" ,
317
- pkg_name,
318
- e
319
- )
320
- } ) ?;
306
+ return Ok ( ( ) ) ;
307
+ }
321
308
322
- // After the build command has finished running, we need to be sure to
323
- // remember all of its output so we can later discover precisely what it
324
- // was, even if we don't run the build command again (due to freshness).
325
- //
326
- // This is also the location where we provide feedback into the build
327
- // state informing what variables were discovered via our script as
328
- // well.
329
- paths:: write ( & output_file, & output. stdout ) ?;
330
- filetime:: set_file_times ( output_file, timestamp, timestamp) ?;
331
- paths:: write ( & err_file, & output. stderr ) ?;
332
- paths:: write ( & root_output_file, util:: path2bytes ( & script_out_dir) ?) ?;
333
- let parsed_output =
334
- BuildOutput :: parse ( & output. stdout , & pkg_name, & script_out_dir, & script_out_dir) ?;
335
-
336
- if json_messages {
337
- emit_build_output ( & parsed_output, id) ;
338
- }
339
- build_state. insert ( id, kind, parsed_output) ;
309
+ // And now finally, run the build command itself!
310
+ state. running ( & cmd) ;
311
+ let timestamp = paths:: set_invocation_time ( & script_run_dir) ?;
312
+ let prefix = format ! ( "[{} {}] " , id. name( ) , id. version( ) ) ;
313
+ let output = cmd
314
+ . exec_with_streaming (
315
+ & mut |stdout| {
316
+ if extra_verbose {
317
+ state. stdout ( & format ! ( "{}{}" , prefix, stdout) ) ;
318
+ }
319
+ Ok ( ( ) )
320
+ } ,
321
+ & mut |stderr| {
322
+ if extra_verbose {
323
+ state. stderr ( & format ! ( "{}{}" , prefix, stderr) ) ;
324
+ }
325
+ Ok ( ( ) )
326
+ } ,
327
+ true ,
328
+ )
329
+ . chain_err ( || format ! ( "failed to run custom build command for `{}`" , pkg_name) ) ?;
330
+
331
+ // After the build command has finished running, we need to be sure to
332
+ // remember all of its output so we can later discover precisely what it
333
+ // was, even if we don't run the build command again (due to freshness).
334
+ //
335
+ // This is also the location where we provide feedback into the build
336
+ // state informing what variables were discovered via our script as
337
+ // well.
338
+ paths:: write ( & output_file, & output. stdout ) ?;
339
+ filetime:: set_file_times ( output_file, timestamp, timestamp) ?;
340
+ paths:: write ( & err_file, & output. stderr ) ?;
341
+ paths:: write ( & root_output_file, util:: path2bytes ( & script_out_dir) ?) ?;
342
+ let parsed_output =
343
+ BuildOutput :: parse ( & output. stdout , & pkg_name, & script_out_dir, & script_out_dir) ?;
344
+
345
+ if json_messages {
346
+ emit_build_output ( state, & parsed_output, id) ;
340
347
}
348
+ build_state. insert ( id, kind, parsed_output) ;
341
349
Ok ( ( ) )
342
350
} ) ;
343
351
344
352
// Now that we've prepared our work-to-do, we need to prepare the fresh work
345
353
// itself to run when we actually end up just discarding what we calculated
346
354
// above.
347
- let fresh = Work :: new ( move |_tx | {
355
+ let fresh = Work :: new ( move |state | {
348
356
let ( id, pkg_name, build_state, output_file, script_out_dir) = all;
349
357
let output = match prev_output {
350
358
Some ( output) => output,
@@ -357,7 +365,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
357
365
} ;
358
366
359
367
if json_messages {
360
- emit_build_output ( & output, id) ;
368
+ emit_build_output ( state , & output, id) ;
361
369
}
362
370
363
371
build_state. insert ( id, kind, output) ;
0 commit comments