3
3
4
4
use std:: env;
5
5
use std:: ffi:: OsString ;
6
+ use std:: fs;
7
+ use std:: io:: ErrorKind ;
6
8
use std:: iter;
7
9
use std:: path:: Path ;
8
10
use std:: process:: { self , Command , Stdio } ;
@@ -146,8 +148,16 @@ fn compile_probe(rustc_bootstrap: bool) -> bool {
146
148
147
149
let rustc = cargo_env_var ( "RUSTC" ) ;
148
150
let out_dir = cargo_env_var ( "OUT_DIR" ) ;
151
+ let out_subdir = Path :: new ( & out_dir) . join ( "probe" ) ;
149
152
let probefile = Path :: new ( "build" ) . join ( "probe.rs" ) ;
150
153
154
+ if let Err ( err) = fs:: create_dir ( & out_subdir) {
155
+ if err. kind ( ) != ErrorKind :: AlreadyExists {
156
+ eprintln ! ( "Failed to create {}: {}" , out_subdir. display( ) , err) ;
157
+ process:: exit ( 1 ) ;
158
+ }
159
+ }
160
+
151
161
let rustc_wrapper = env:: var_os ( "RUSTC_WRAPPER" ) . filter ( |wrapper| !wrapper. is_empty ( ) ) ;
152
162
let rustc_workspace_wrapper =
153
163
env:: var_os ( "RUSTC_WORKSPACE_WRAPPER" ) . filter ( |wrapper| !wrapper. is_empty ( ) ) ;
@@ -169,7 +179,7 @@ fn compile_probe(rustc_bootstrap: bool) -> bool {
169
179
. arg ( "--cap-lints=allow" )
170
180
. arg ( "--emit=dep-info,metadata" )
171
181
. arg ( "--out-dir" )
172
- . arg ( out_dir )
182
+ . arg ( & out_subdir )
173
183
. arg ( probefile) ;
174
184
175
185
if let Some ( target) = env:: var_os ( "TARGET" ) {
@@ -185,10 +195,22 @@ fn compile_probe(rustc_bootstrap: bool) -> bool {
185
195
}
186
196
}
187
197
188
- match cmd. status ( ) {
198
+ let success = match cmd. status ( ) {
189
199
Ok ( status) => status. success ( ) ,
190
200
Err ( _) => false ,
201
+ } ;
202
+
203
+ // Clean up to avoid leaving nondeterministic absolute paths in the dep-info
204
+ // file in OUT_DIR, which causes nonreproducible builds in build systems
205
+ // that treat the entire OUT_DIR as an artifact.
206
+ if let Err ( err) = fs:: remove_dir_all ( & out_subdir) {
207
+ if err. kind ( ) != ErrorKind :: NotFound {
208
+ eprintln ! ( "Failed to clean up {}: {}" , out_subdir. display( ) , err) ;
209
+ process:: exit ( 1 ) ;
210
+ }
191
211
}
212
+
213
+ success
192
214
}
193
215
194
216
fn rustc_minor_version ( ) -> Option < u32 > {
0 commit comments