1
1
use std:: env;
2
2
use std:: ffi:: OsString ;
3
+ use std:: fs;
4
+ use std:: io:: ErrorKind ;
3
5
use std:: iter;
4
6
use std:: path:: Path ;
5
7
use std:: process:: { self , Command , Stdio } ;
@@ -68,8 +70,16 @@ fn compile_probe(rustc_bootstrap: bool) -> bool {
68
70
69
71
let rustc = cargo_env_var ( "RUSTC" ) ;
70
72
let out_dir = cargo_env_var ( "OUT_DIR" ) ;
73
+ let out_subdir = Path :: new ( & out_dir) . join ( "probe" ) ;
71
74
let probefile = Path :: new ( "build" ) . join ( "probe.rs" ) ;
72
75
76
+ if let Err ( err) = fs:: create_dir ( & out_subdir) {
77
+ if err. kind ( ) != ErrorKind :: AlreadyExists {
78
+ eprintln ! ( "Failed to create {}: {}" , out_subdir. display( ) , err) ;
79
+ process:: exit ( 1 ) ;
80
+ }
81
+ }
82
+
73
83
let rustc_wrapper = env:: var_os ( "RUSTC_WRAPPER" ) . filter ( |wrapper| !wrapper. is_empty ( ) ) ;
74
84
let rustc_workspace_wrapper =
75
85
env:: var_os ( "RUSTC_WORKSPACE_WRAPPER" ) . filter ( |wrapper| !wrapper. is_empty ( ) ) ;
@@ -91,7 +101,7 @@ fn compile_probe(rustc_bootstrap: bool) -> bool {
91
101
. arg ( "--cap-lints=allow" )
92
102
. arg ( "--emit=dep-info,metadata" )
93
103
. arg ( "--out-dir" )
94
- . arg ( out_dir )
104
+ . arg ( & out_subdir )
95
105
. arg ( probefile) ;
96
106
97
107
if let Some ( target) = env:: var_os ( "TARGET" ) {
@@ -107,10 +117,22 @@ fn compile_probe(rustc_bootstrap: bool) -> bool {
107
117
}
108
118
}
109
119
110
- match cmd. status ( ) {
120
+ let success = match cmd. status ( ) {
111
121
Ok ( status) => status. success ( ) ,
112
122
Err ( _) => false ,
123
+ } ;
124
+
125
+ // Clean up to avoid leaving nondeterministic absolute paths in the dep-info
126
+ // file in OUT_DIR, which causes nonreproducible builds in build systems
127
+ // that treat the entire OUT_DIR as an artifact.
128
+ if let Err ( err) = fs:: remove_dir_all ( & out_subdir) {
129
+ if err. kind ( ) != ErrorKind :: NotFound {
130
+ eprintln ! ( "Failed to clean up {}: {}" , out_subdir. display( ) , err) ;
131
+ process:: exit ( 1 ) ;
132
+ }
113
133
}
134
+
135
+ success
114
136
}
115
137
116
138
fn cargo_env_var ( key : & str ) -> OsString {
0 commit comments