@@ -3,7 +3,6 @@ use std::ffi::OsString;
3
3
use std:: fs:: { self , File } ;
4
4
use std:: io:: { BufRead , BufReader , BufWriter , ErrorKind , Write } ;
5
5
use std:: path:: { Path , PathBuf } ;
6
- use std:: process:: { Command , Stdio } ;
7
6
use std:: sync:: OnceLock ;
8
7
9
8
use xz2:: bufread:: XzDecoder ;
@@ -16,14 +15,7 @@ use crate::{Config, t};
16
15
17
16
static SHOULD_FIX_BINS_AND_DYLIBS : OnceLock < bool > = OnceLock :: new ( ) ;
18
17
19
- /// `Config::try_run` wrapper for this module to avoid warnings on `try_run`, since we don't have access to a `builder` yet.
20
- fn try_run ( config : & Config , cmd : & mut Command ) -> Result < ( ) , ( ) > {
21
- #[ expect( deprecated) ]
22
- config. try_run ( cmd)
23
- }
24
-
25
- fn extract_curl_version ( out : & [ u8 ] ) -> semver:: Version {
26
- let out = String :: from_utf8_lossy ( out) ;
18
+ fn extract_curl_version ( out : String ) -> semver:: Version {
27
19
// The output should look like this: "curl <major>.<minor>.<patch> ..."
28
20
out. lines ( )
29
21
. next ( )
@@ -32,16 +24,21 @@ fn extract_curl_version(out: &[u8]) -> semver::Version {
32
24
. unwrap_or ( semver:: Version :: new ( 1 , 0 , 0 ) )
33
25
}
34
26
35
- fn curl_version ( ) -> semver:: Version {
36
- let mut curl = Command :: new ( "curl" ) ;
37
- curl. arg ( "-V" ) ;
38
- let Ok ( out) = curl. output ( ) else { return semver:: Version :: new ( 1 , 0 , 0 ) } ;
39
- let out = out. stdout ;
40
- extract_curl_version ( & out)
41
- }
42
-
27
+ #[ allow( warnings) ]
43
28
/// Generic helpers that are useful anywhere in bootstrap.
44
29
impl Config {
30
+ fn curl_version ( & self ) -> semver:: Version {
31
+ let mut curl = command ( "curl" ) ;
32
+ curl. arg ( "-V" ) ;
33
+ let curl = curl. run_capture_stdout ( self . context ( ) ) ;
34
+ if curl. is_failure ( ) {
35
+ return semver:: Version :: new ( 1 , 0 , 0 ) ;
36
+ }
37
+ let output = curl. stdout ( ) ;
38
+ let out = output;
39
+ extract_curl_version ( out)
40
+ }
41
+
45
42
pub fn is_verbose ( & self ) -> bool {
46
43
self . verbose > 0
47
44
}
@@ -85,18 +82,13 @@ impl Config {
85
82
/// on NixOS
86
83
fn should_fix_bins_and_dylibs ( & self ) -> bool {
87
84
let val = * SHOULD_FIX_BINS_AND_DYLIBS . get_or_init ( || {
88
- match Command :: new ( "uname" ) . arg ( "-s" ) . stderr ( Stdio :: inherit ( ) ) . output ( ) {
89
- Err ( _) => return false ,
90
- Ok ( output) if !output. status . success ( ) => return false ,
91
- Ok ( output) => {
92
- let mut os_name = output. stdout ;
93
- if os_name. last ( ) == Some ( & b'\n' ) {
94
- os_name. pop ( ) ;
95
- }
96
- if os_name != b"Linux" {
97
- return false ;
98
- }
99
- }
85
+ let uname = command ( "uname" ) . arg ( "-s" ) . run_capture_stdout ( self . context ( ) ) ;
86
+ if uname. is_failure ( ) {
87
+ return false ;
88
+ }
89
+ let output = uname. stdout ( ) ;
90
+ if output. starts_with ( "Linux" ) {
91
+ return false ;
100
92
}
101
93
102
94
// If the user has asked binaries to be patched for Nix, then
@@ -173,35 +165,31 @@ impl Config {
173
165
];
174
166
}
175
167
" ;
176
- nix_build_succeeded = try_run (
177
- self ,
178
- Command :: new ( "nix-build" ) . args ( [
179
- Path :: new ( "-E" ) ,
180
- Path :: new ( NIX_EXPR ) ,
181
- Path :: new ( "-o" ) ,
182
- & nix_deps_dir,
183
- ] ) ,
184
- )
185
- . is_ok ( ) ;
168
+ nix_build_succeeded = command ( "nix-build" )
169
+ . allow_failure ( )
170
+ . args ( [ Path :: new ( "-E" ) , Path :: new ( NIX_EXPR ) , Path :: new ( "-o" ) , & nix_deps_dir] )
171
+ . run_capture ( self . context ( ) )
172
+ . is_success ( ) ;
186
173
nix_deps_dir
187
174
} ) ;
188
175
if !nix_build_succeeded {
189
176
return ;
190
177
}
191
178
192
- let mut patchelf = Command :: new ( nix_deps_dir. join ( "bin/patchelf " ) ) ;
193
- patchelf. args ( & [
179
+ let mut patchelf = command ( nix_deps_dir. join ( "bin/patcheld " ) ) ;
180
+ let patchelf = patchelf. args ( & [
194
181
OsString :: from ( "--add-rpath" ) ,
195
182
OsString :: from ( t ! ( fs:: canonicalize( nix_deps_dir) ) . join ( "lib" ) ) ,
196
183
] ) ;
184
+
197
185
if !path_is_dylib ( fname) {
198
186
// Finally, set the correct .interp for binaries
199
187
let dynamic_linker_path = nix_deps_dir. join ( "nix-support/dynamic-linker" ) ;
200
188
let dynamic_linker = t ! ( fs:: read_to_string( dynamic_linker_path) ) ;
201
189
patchelf. args ( [ "--set-interpreter" , dynamic_linker. trim_end ( ) ] ) ;
202
190
}
203
191
204
- let _ = try_run ( self , patchelf . arg ( fname ) ) ;
192
+ let _ = patchelf . run_capture ( & self . context ( ) ) ;
205
193
}
206
194
207
195
fn download_file ( & self , url : & str , dest_path : & Path , help_on_error : & str ) {
@@ -267,23 +255,25 @@ impl Config {
267
255
curl. arg ( "--progress-bar" ) ;
268
256
}
269
257
// --retry-all-errors was added in 7.71.0, don't use it if curl is old.
270
- if curl_version ( ) >= semver:: Version :: new ( 7 , 71 , 0 ) {
258
+ if self . curl_version ( ) >= semver:: Version :: new ( 7 , 71 , 0 ) {
271
259
curl. arg ( "--retry-all-errors" ) ;
272
260
}
273
261
curl. arg ( url) ;
274
262
if !self . check_run ( & mut curl) {
275
263
if self . build . contains ( "windows-msvc" ) {
276
264
eprintln ! ( "Fallback to PowerShell" ) ;
277
265
for _ in 0 ..3 {
278
- if try_run ( self , Command :: new ( "PowerShell.exe" ) . args ( [
266
+ let powershell = command ( "PowerShell.exe" ) . allow_failure ( ) . args ( [
279
267
"/nologo" ,
280
268
"-Command" ,
281
269
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;" ,
282
270
& format ! (
283
271
"(New-Object System.Net.WebClient).DownloadFile('{}', '{}')" ,
284
272
url, tempfile. to_str( ) . expect( "invalid UTF-8 not supported with powershell downloads" ) ,
285
273
) ,
286
- ] ) ) . is_err ( ) {
274
+ ] ) . run_capture_stdout ( & self . context ( ) ) ;
275
+
276
+ if powershell. is_failure ( ) {
287
277
return ;
288
278
}
289
279
eprintln ! ( "\n spurious failure, trying again" ) ;
0 commit comments