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 } ;
@@ -125,8 +127,16 @@ fn compile_probe(rustc_bootstrap: bool) -> bool {
125
127
126
128
let rustc = cargo_env_var ( "RUSTC" ) ;
127
129
let out_dir = cargo_env_var ( "OUT_DIR" ) ;
130
+ let out_subdir = Path :: new ( & out_dir) . join ( "probe" ) ;
128
131
let probefile = Path :: new ( "build" ) . join ( "probe.rs" ) ;
129
132
133
+ if let Err ( err) = fs:: create_dir ( & out_subdir) {
134
+ if err. kind ( ) != ErrorKind :: AlreadyExists {
135
+ eprintln ! ( "Failed to create {}: {}" , out_subdir. display( ) , err) ;
136
+ process:: exit ( 1 ) ;
137
+ }
138
+ }
139
+
130
140
let rustc_wrapper = env:: var_os ( "RUSTC_WRAPPER" ) . filter ( |wrapper| !wrapper. is_empty ( ) ) ;
131
141
let rustc_workspace_wrapper =
132
142
env:: var_os ( "RUSTC_WORKSPACE_WRAPPER" ) . filter ( |wrapper| !wrapper. is_empty ( ) ) ;
@@ -148,7 +158,7 @@ fn compile_probe(rustc_bootstrap: bool) -> bool {
148
158
. arg ( "--emit=dep-info,metadata" )
149
159
. arg ( "--cap-lints=allow" )
150
160
. arg ( "--out-dir" )
151
- . arg ( out_dir )
161
+ . arg ( & out_subdir )
152
162
. arg ( probefile) ;
153
163
154
164
if let Some ( target) = env:: var_os ( "TARGET" ) {
@@ -164,10 +174,22 @@ fn compile_probe(rustc_bootstrap: bool) -> bool {
164
174
}
165
175
}
166
176
167
- match cmd. status ( ) {
177
+ let success = match cmd. status ( ) {
168
178
Ok ( status) => status. success ( ) ,
169
179
Err ( _) => false ,
180
+ } ;
181
+
182
+ // Clean up to avoid leaving nondeterministic absolute paths in the dep-info
183
+ // file in OUT_DIR, which causes nonreproducible builds in build systems
184
+ // that treat the entire OUT_DIR as an artifact.
185
+ if let Err ( err) = fs:: remove_dir_all ( & out_subdir) {
186
+ if err. kind ( ) != ErrorKind :: NotFound {
187
+ eprintln ! ( "Failed to clean up {}: {}" , out_subdir. display( ) , err) ;
188
+ process:: exit ( 1 ) ;
189
+ }
170
190
}
191
+
192
+ success
171
193
}
172
194
173
195
fn rustc_minor_version ( ) -> Option < u32 > {
0 commit comments