@@ -270,7 +270,7 @@ pub fn target_supported() -> bool {
270
270
pub fn get_variable ( package : & str , variable : & str ) -> Result < String , Error > {
271
271
let arg = format ! ( "--variable={}" , variable) ;
272
272
let cfg = Config :: new ( ) ;
273
- let out = run ( cfg. command ( package, & [ & arg] ) ) ?;
273
+ let out = cfg. run ( package, & [ & arg] ) ?;
274
274
Ok ( str:: from_utf8 ( & out) . unwrap ( ) . trim_end ( ) . to_owned ( ) )
275
275
}
276
276
@@ -392,17 +392,19 @@ impl Config {
392
392
393
393
let mut library = Library :: new ( ) ;
394
394
395
- let output = run ( self . command ( name, & [ "--libs" , "--cflags" ] ) ) . map_err ( |e| match e {
396
- Error :: Failure { command, output } => Error :: ProbeFailure {
397
- name : name. to_owned ( ) ,
398
- command,
399
- output,
400
- } ,
401
- other => other,
402
- } ) ?;
395
+ let output = self
396
+ . run ( name, & [ "--libs" , "--cflags" ] )
397
+ . map_err ( |e| match e {
398
+ Error :: Failure { command, output } => Error :: ProbeFailure {
399
+ name : name. to_owned ( ) ,
400
+ command,
401
+ output,
402
+ } ,
403
+ other => other,
404
+ } ) ?;
403
405
library. parse_libs_cflags ( name, & output, self ) ;
404
406
405
- let output = run ( self . command ( name, & [ "--modversion" ] ) ) ?;
407
+ let output = self . run ( name, & [ "--modversion" ] ) ?;
406
408
library. parse_modversion ( str:: from_utf8 ( & output) . unwrap ( ) ) ;
407
409
408
410
Ok ( library)
@@ -474,10 +476,31 @@ impl Config {
474
476
self . statik . unwrap_or_else ( || self . infer_static ( name) )
475
477
}
476
478
477
- fn command ( & self , name : & str , args : & [ & str ] ) -> Command {
479
+ fn run ( & self , name : & str , args : & [ & str ] ) -> Result < Vec < u8 > , Error > {
478
480
let exe = self
479
481
. targetted_env_var ( "PKG_CONFIG" )
480
482
. unwrap_or_else ( || OsString :: from ( "pkg-config" ) ) ;
483
+
484
+ let mut cmd = self . command ( exe, name, args) ;
485
+ match cmd. output ( ) {
486
+ Ok ( output) => {
487
+ if output. status . success ( ) {
488
+ Ok ( output. stdout )
489
+ } else {
490
+ Err ( Error :: Failure {
491
+ command : format ! ( "{:?}" , cmd) ,
492
+ output,
493
+ } )
494
+ }
495
+ }
496
+ Err ( cause) => Err ( Error :: Command {
497
+ command : format ! ( "{:?}" , cmd) ,
498
+ cause,
499
+ } ) ,
500
+ }
501
+ }
502
+
503
+ fn command ( & self , exe : OsString , name : & str , args : & [ & str ] ) -> Command {
481
504
let mut cmd = Command :: new ( exe) ;
482
505
if self . is_static ( name) {
483
506
cmd. arg ( "--static" ) ;
@@ -815,25 +838,6 @@ fn is_static_available(name: &str, system_roots: &[PathBuf], dirs: &[PathBuf]) -
815
838
} )
816
839
}
817
840
818
- fn run ( mut cmd : Command ) -> Result < Vec < u8 > , Error > {
819
- match cmd. output ( ) {
820
- Ok ( output) => {
821
- if output. status . success ( ) {
822
- Ok ( output. stdout )
823
- } else {
824
- Err ( Error :: Failure {
825
- command : format ! ( "{:?}" , cmd) ,
826
- output,
827
- } )
828
- }
829
- }
830
- Err ( cause) => Err ( Error :: Command {
831
- command : format ! ( "{:?}" , cmd) ,
832
- cause,
833
- } ) ,
834
- }
835
- }
836
-
837
841
/// Split output produced by pkg-config --cflags and / or --libs into separate flags.
838
842
///
839
843
/// Backslash in output is used to preserve literal meaning of following byte. Different words are
0 commit comments