fn maybe_clear(&self, dir: &Path) {
        // CMake will apparently store canonicalized paths which normally
        // isn't relevant to us but we canonicalize it here to ensure
        // we're both checking the same thing.
        let path = fs::canonicalize(&self.path).unwrap_or(self.path.clone());
        let src = match path.to_str() {
            Some(src) => src,
            None => return,
        };
        let mut f = match File::open(dir.join("CMakeCache.txt")) {
            Ok(f) => f,
            Err(..) => return,
        };
        let mut u8contents = Vec::new();
        match f.read_to_end(&mut u8contents) {
            Ok(f) => f,
            Err(..) => return,
        };
        let contents = String::from_utf8_lossy(&u8contents);
        drop(f);
        for line in contents.lines() {
            if line.contains("CMAKE_HOME_DIRECTORY") && !line.contains(src) {
                println!("detected home dir change, cleaning out entire build \
                          directory");
                fs::remove_dir_all(dir).unwrap();
                break
            }
        }
    }
// If a cmake project has previously been built (e.g. CMakeCache.txt already
// exists), then cmake will choke if the source directory for the original
// project being built has changed. Detect this situation through the
// `CMAKE_HOME_DIRECTORY` variable that cmake emits and if it doesn't match
// we blow away the build directory and start from scratch (the recommended
// solution apparently [1]).
//
// [1]: https://cmake.org/pipermail/cmake/2012-August/051545.html
If a cmake project has previously been built , then cmake will choke if the source directory for the original
project being built has changed. Detect this situation through the
`CMAKE_HOME_DIRECTORY` variable that cmake emits and if it doesn't match
we blow away the build directory and start from scratch (the recommended
solution apparently [1]).


If a cmake project has previously been built then cmake will choke if the source directory for the original project being built has changed . Detect this situation through the ` CMAKE_HOME_DIRECTORY ` variable that cmake emits and if it doesn ' t match we blow away the build directory and start from scratch ( the recommended solution apparently [ 1 ] ) .
fn maybe_clear(&self, dir: &Path) {
        // CMake will apparently store canonicalized paths which normally
        // isn't relevant to us but we canonicalize it here to ensure
        // we're both checking the same thing.
        let path = fs::canonicalize(&self.path).unwrap_or(self.path.clone());
        let src = match path.to_str() {
            Some(src) => src,
            None => return,
        };
        let mut f = match File::open(dir.join("CMakeCache.txt")) {
            Ok(f) => f,
            Err(..) => return,
        };
        let mut u8contents = Vec::new();
        match f.read_to_end(&mut u8contents) {
            Ok(f) => f,
            Err(..) => return,
        };
        let contents = String::from_utf8_lossy(&u8contents);
        drop(f);
        for line in contents.lines() {
            if line.contains("CMAKE_HOME_DIRECTORY") && !line.contains(src) {
                println!("detected home dir change, cleaning out entire build \
                          directory");
                fs::remove_dir_all(dir).unwrap();
                break
            }
        }
    }
fn maybe_clear ( & self , dir : & Path ) { // CMake will apparently store canonicalized paths which normally // isn't relevant to us but we canonicalize it here to ensure // we're both checking the same thing. let path = fs :: canonicalize ( & self . path ) . unwrap_or ( self . path . clone ( ) ) ; let src = match path . to_str ( ) { Some ( src ) => src , None => return , } ; let mut f = match File :: open ( dir . join ( " " ) ) { Ok ( f ) => f , Err ( .. ) => return , } ; let mut u8contents = Vec :: new ( ) ; match f . read_to_end ( & mut u8contents ) { Ok ( f ) => f , Err ( .. ) => return , } ; let contents = String :: from_utf8_lossy ( & u8contents ) ; drop ( f ) ; for line in contents . lines ( ) { if line . contains ( " " ) && ! line . contains ( src ) { println ! ( " \
 " ) ; fs :: remove_dir_all ( dir ) . unwrap ( ) ; break } } }
If a cmake project has previously been built (e.g.
If a cmake project has previously been built ( e . g .
&self
dir
&Path
&self
dir
&Path