@@ -554,9 +554,11 @@ impl Config {
554
554
. out_dir
555
555
. clone ( )
556
556
. unwrap_or_else ( || PathBuf :: from ( getenv_unwrap ( "OUT_DIR" ) ) ) ;
557
- let build = dst. join ( "build" ) ;
558
- self . maybe_clear ( & build) ;
559
- let _ = fs:: create_dir_all ( & build) ;
557
+
558
+ let build_dir = try_canonicalize ( & dst. join ( "build" ) ) ;
559
+
560
+ self . maybe_clear ( & build_dir) ;
561
+ let _ = fs:: create_dir_all ( & build_dir) ;
560
562
561
563
// Add all our dependencies to our cmake paths
562
564
let mut cmake_prefix_path = Vec :: new ( ) ;
@@ -582,7 +584,7 @@ impl Config {
582
584
cmd. arg ( "--debug-output" ) ;
583
585
}
584
586
585
- cmd. arg ( & self . path ) . current_dir ( & build ) ;
587
+ cmd. arg ( & self . path ) . current_dir ( & build_dir ) ;
586
588
let mut is_ninja = false ;
587
589
if let Some ( ref generator) = generator {
588
590
is_ninja = generator. to_string_lossy ( ) . contains ( "Ninja" ) ;
@@ -816,7 +818,7 @@ impl Config {
816
818
cmd. env ( k, v) ;
817
819
}
818
820
819
- if self . always_configure || !build . join ( "CMakeCache.txt" ) . exists ( ) {
821
+ if self . always_configure || !build_dir . join ( "CMakeCache.txt" ) . exists ( ) {
820
822
cmd. args ( & self . configure_args ) ;
821
823
run ( cmd. env ( "CMAKE_PREFIX_PATH" , cmake_prefix_path) , "cmake" ) ;
822
824
} else {
@@ -825,15 +827,15 @@ impl Config {
825
827
826
828
// And build!
827
829
let mut cmd = self . cmake_build_command ( & target) ;
828
- cmd. current_dir ( & build ) ;
830
+ cmd. current_dir ( & build_dir ) ;
829
831
830
832
for ( k, v) in c_compiler. env ( ) . iter ( ) . chain ( & self . env ) {
831
833
cmd. env ( k, v) ;
832
834
}
833
835
834
836
// If the generated project is Makefile based we should carefully transfer corresponding CARGO_MAKEFLAGS
835
837
let mut use_jobserver = false ;
836
- if fs:: metadata ( build . join ( "Makefile" ) ) . is_ok ( ) {
838
+ if fs:: metadata ( build_dir . join ( "Makefile" ) ) . is_ok ( ) {
837
839
match env:: var_os ( "CARGO_MAKEFLAGS" ) {
838
840
// Only do this on non-windows, non-bsd, and non-macos (unless a named pipe
839
841
// jobserver is available)
@@ -859,7 +861,7 @@ impl Config {
859
861
}
860
862
}
861
863
862
- cmd. arg ( "--build" ) . arg ( & build ) ;
864
+ cmd. arg ( "--build" ) . arg ( & build_dir ) ;
863
865
864
866
if !self . no_build_target {
865
867
let target = self
@@ -995,7 +997,8 @@ impl Config {
995
997
// CMake will apparently store canonicalized paths which normally
996
998
// isn't relevant to us but we canonicalize it here to ensure
997
999
// we're both checking the same thing.
998
- let path = fs:: canonicalize ( & self . path ) . unwrap_or_else ( |_| self . path . clone ( ) ) ;
1000
+ let path = try_canonicalize ( & self . path ) ;
1001
+
999
1002
let mut f = match File :: open ( dir. join ( "CMakeCache.txt" ) ) {
1000
1003
Ok ( f) => f,
1001
1004
Err ( ..) => return ,
@@ -1129,6 +1132,12 @@ fn uses_named_pipe_jobserver(makeflags: &OsStr) -> bool {
1129
1132
. contains ( "--jobserver-auth=fifo:" )
1130
1133
}
1131
1134
1135
+ /// Attempt to canonicalize; fall back to the original path if unsuccessful, in case `cmake` knows
1136
+ /// something we don't.
1137
+ fn try_canonicalize ( path : & Path ) -> PathBuf {
1138
+ path. canonicalize ( ) . unwrap_or_else ( |_| path. to_owned ( ) )
1139
+ }
1140
+
1132
1141
#[ cfg( test) ]
1133
1142
mod tests {
1134
1143
use super :: uses_named_pipe_jobserver;
0 commit comments