@@ -24,7 +24,7 @@ use rustc_parse::{parse_crate_from_file, parse_crate_from_source_str, validate_a
24
24
use rustc_passes:: { self , hir_stats, layout_test} ;
25
25
use rustc_plugin_impl as plugin;
26
26
use rustc_resolve:: Resolver ;
27
- use rustc_session:: config:: { CrateType , Input , OutputFilenames , OutputType } ;
27
+ use rustc_session:: config:: { CrateType , Input , OutFileName , OutputFilenames , OutputType } ;
28
28
use rustc_session:: cstore:: { MetadataLoader , Untracked } ;
29
29
use rustc_session:: output:: filename_for_input;
30
30
use rustc_session:: search_paths:: PathKind ;
@@ -373,19 +373,23 @@ fn generated_output_paths(
373
373
) -> Vec < PathBuf > {
374
374
let mut out_filenames = Vec :: new ( ) ;
375
375
for output_type in sess. opts . output_types . keys ( ) {
376
- let file = outputs. path ( * output_type) ;
376
+ let out_filename = outputs. path ( * output_type) ;
377
+ let file = out_filename. as_path ( ) . to_path_buf ( ) ;
377
378
match * output_type {
378
379
// If the filename has been overridden using `-o`, it will not be modified
379
380
// by appending `.rlib`, `.exe`, etc., so we can skip this transformation.
380
381
OutputType :: Exe if !exact_name => {
381
382
for crate_type in sess. crate_types ( ) . iter ( ) {
382
383
let p = filename_for_input ( sess, * crate_type, crate_name, outputs) ;
383
- out_filenames. push ( p) ;
384
+ out_filenames. push ( p. as_path ( ) . to_path_buf ( ) ) ;
384
385
}
385
386
}
386
387
OutputType :: DepInfo if sess. opts . unstable_opts . dep_info_omit_d_target => {
387
388
// Don't add the dep-info output when omitting it from dep-info targets
388
389
}
390
+ OutputType :: DepInfo if out_filename. is_stdout ( ) => {
391
+ // Don't add the dep-info output when it goes to stdout
392
+ }
389
393
_ => {
390
394
out_filenames. push ( file) ;
391
395
}
@@ -452,7 +456,8 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P
452
456
if !sess. opts . output_types . contains_key ( & OutputType :: DepInfo ) {
453
457
return ;
454
458
}
455
- let deps_filename = outputs. path ( OutputType :: DepInfo ) ;
459
+ let deps_output = outputs. path ( OutputType :: DepInfo ) ;
460
+ let deps_filename = deps_output. as_path ( ) ;
456
461
457
462
let result: io:: Result < ( ) > = try {
458
463
// Build a list of files used to compile the output and
@@ -515,33 +520,47 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P
515
520
}
516
521
}
517
522
518
- let mut file = BufWriter :: new ( fs :: File :: create ( & deps_filename ) ? ) ;
519
- for path in out_filenames {
520
- writeln ! ( file, "{}: {}\n " , path. display( ) , files. join( " " ) ) ?;
521
- }
523
+ let write_deps_to_file = | file : & mut dyn Write | -> io :: Result < ( ) > {
524
+ for path in out_filenames {
525
+ writeln ! ( file, "{}: {}\n " , path. display( ) , files. join( " " ) ) ?;
526
+ }
522
527
523
- // Emit a fake target for each input file to the compilation. This
524
- // prevents `make` from spitting out an error if a file is later
525
- // deleted. For more info see #28735
526
- for path in files {
527
- writeln ! ( file, "{path}:" ) ?;
528
- }
528
+ // Emit a fake target for each input file to the compilation. This
529
+ // prevents `make` from spitting out an error if a file is later
530
+ // deleted. For more info see #28735
531
+ for path in files {
532
+ writeln ! ( file, "{path}:" ) ?;
533
+ }
529
534
530
- // Emit special comments with information about accessed environment variables.
531
- let env_depinfo = sess. parse_sess . env_depinfo . borrow ( ) ;
532
- if !env_depinfo. is_empty ( ) {
533
- let mut envs: Vec < _ > = env_depinfo
534
- . iter ( )
535
- . map ( |( k, v) | ( escape_dep_env ( * k) , v. map ( escape_dep_env) ) )
536
- . collect ( ) ;
537
- envs. sort_unstable ( ) ;
538
- writeln ! ( file) ?;
539
- for ( k, v) in envs {
540
- write ! ( file, "# env-dep:{k}" ) ?;
541
- if let Some ( v) = v {
542
- write ! ( file, "={v}" ) ?;
543
- }
535
+ // Emit special comments with information about accessed environment variables.
536
+ let env_depinfo = sess. parse_sess . env_depinfo . borrow ( ) ;
537
+ if !env_depinfo. is_empty ( ) {
538
+ let mut envs: Vec < _ > = env_depinfo
539
+ . iter ( )
540
+ . map ( |( k, v) | ( escape_dep_env ( * k) , v. map ( escape_dep_env) ) )
541
+ . collect ( ) ;
542
+ envs. sort_unstable ( ) ;
544
543
writeln ! ( file) ?;
544
+ for ( k, v) in envs {
545
+ write ! ( file, "# env-dep:{k}" ) ?;
546
+ if let Some ( v) = v {
547
+ write ! ( file, "={v}" ) ?;
548
+ }
549
+ writeln ! ( file) ?;
550
+ }
551
+ }
552
+
553
+ Ok ( ( ) )
554
+ } ;
555
+
556
+ match deps_output {
557
+ OutFileName :: Stdout => {
558
+ let mut file = BufWriter :: new ( io:: stdout ( ) ) ;
559
+ write_deps_to_file ( & mut file) ?;
560
+ }
561
+ OutFileName :: Real ( ref path) => {
562
+ let mut file = BufWriter :: new ( fs:: File :: create ( path) ?) ;
563
+ write_deps_to_file ( & mut file) ?;
545
564
}
546
565
}
547
566
} ;
0 commit comments