@@ -11,7 +11,9 @@ use std::collections::hash_map::{Entry, HashMap};
11
11
use std:: collections:: { BTreeSet , HashSet } ;
12
12
use std:: path:: { Path , PathBuf } ;
13
13
use std:: str;
14
- use std:: sync:: Arc ;
14
+ use std:: sync:: { Arc , Mutex } ;
15
+
16
+ const CARGO_WARNING : & str = "cargo:warning=" ;
15
17
16
18
/// Contains the parsed output of a custom build script.
17
19
#[ derive( Clone , Debug , Hash , Default ) ]
@@ -343,9 +345,13 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
343
345
state. running ( & cmd) ;
344
346
let timestamp = paths:: set_invocation_time ( & script_run_dir) ?;
345
347
let prefix = format ! ( "[{} {}] " , id. name( ) , id. version( ) ) ;
348
+ let mut warnings_in_case_of_panic = Vec :: new ( ) ;
346
349
let output = cmd
347
350
. exec_with_streaming (
348
351
& mut |stdout| {
352
+ if stdout. starts_with ( CARGO_WARNING ) {
353
+ warnings_in_case_of_panic. push ( stdout[ CARGO_WARNING . len ( ) ..] . to_owned ( ) ) ;
354
+ }
349
355
if extra_verbose {
350
356
state. stdout ( format ! ( "{}{}" , prefix, stdout) ) ;
351
357
}
@@ -359,7 +365,19 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
359
365
} ,
360
366
true ,
361
367
)
362
- . chain_err ( || format ! ( "failed to run custom build command for `{}`" , pkg_name) ) ?;
368
+ . chain_err ( || format ! ( "failed to run custom build command for `{}`" , pkg_name) ) ;
369
+
370
+ if let Err ( error) = output {
371
+ insert_warnings_in_build_outputs (
372
+ build_script_outputs,
373
+ id,
374
+ metadata_hash,
375
+ warnings_in_case_of_panic,
376
+ ) ;
377
+ return Err ( error) ;
378
+ }
379
+
380
+ let output = output. unwrap ( ) ;
363
381
364
382
// After the build command has finished running, we need to be sure to
365
383
// remember all of its output so we can later discover precisely what it
@@ -429,6 +447,22 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
429
447
Ok ( job)
430
448
}
431
449
450
+ fn insert_warnings_in_build_outputs (
451
+ build_script_outputs : Arc < Mutex < BuildScriptOutputs > > ,
452
+ id : PackageId ,
453
+ metadata_hash : Metadata ,
454
+ warnings : Vec < String > ,
455
+ ) {
456
+ let build_output_with_only_warnings = BuildOutput {
457
+ warnings,
458
+ ..BuildOutput :: default ( )
459
+ } ;
460
+ build_script_outputs
461
+ . lock ( )
462
+ . unwrap ( )
463
+ . insert ( id, metadata_hash, build_output_with_only_warnings) ;
464
+ }
465
+
432
466
impl BuildOutput {
433
467
pub fn parse_file (
434
468
path : & Path ,
0 commit comments