@@ -15,8 +15,21 @@ macro_rules! println_stderr(
15
15
} }
16
16
) ;
17
17
18
- fn run_command_or_fail ( dir : & str , cmd : & str , args : & [ & str ] ) {
19
- println_stderr ! ( "Running command: \" {} {}\" in dir: {}" , cmd, args. join( " " ) , dir) ;
18
+ fn run_command_or_fail < P > ( dir : & str , cmd : P , args : & [ & str ] )
19
+ where
20
+ P : AsRef < Path > ,
21
+ {
22
+ let cmd = cmd. as_ref ( ) ;
23
+ let cmd = if cmd. components ( ) . count ( ) > 1 && cmd. is_relative ( ) {
24
+ // If `cmd` is a relative path (and not a bare command that should be
25
+ // looked up in PATH), absolutize it relative to `dir`, as otherwise the
26
+ // behavior of std::process::Command is undefined.
27
+ // https://github.com/rust-lang/rust/issues/37868
28
+ PathBuf :: from ( dir) . join ( cmd) . canonicalize ( ) . expect ( "canonicalization failed" )
29
+ } else {
30
+ PathBuf :: from ( cmd)
31
+ } ;
32
+ println_stderr ! ( "Running command: \" {} {}\" in dir: {}" , cmd. display( ) , args. join( " " ) , dir) ;
20
33
let ret = Command :: new ( cmd) . current_dir ( dir) . args ( args) . status ( ) ;
21
34
match ret. map ( |status| ( status. success ( ) , status. code ( ) ) ) {
22
35
Ok ( ( true , _) ) => { return } ,
@@ -109,7 +122,7 @@ fn build_librdkafka() {
109
122
}
110
123
111
124
println ! ( "Configuring librdkafka" ) ;
112
- run_command_or_fail ( "librdkafka" , "sh" , & [ & [ "-c" , " ./configure"] , configure_flags. as_slice ( ) ] . concat ( ) ) ;
125
+ run_command_or_fail ( "librdkafka" , "./configure" , configure_flags. as_slice ( ) ) ;
113
126
114
127
println ! ( "Compiling librdkafka" ) ;
115
128
make_librdkafka ( ) ;
0 commit comments