11use crate :: config:: { Channel , ConfigInfo } ;
2- use crate :: utils:: { run_command, run_command_with_output_and_env, walk_dir} ;
2+ use crate :: utils:: { create_dir , run_command, run_command_with_output_and_env, walk_dir} ;
33use std:: collections:: HashMap ;
44use std:: ffi:: OsStr ;
55use std:: fs;
@@ -103,6 +103,7 @@ fn cleanup_sysroot_previous_build(start_dir: &Path) {
103103
104104pub fn build_sysroot ( env : & HashMap < String , String > , config : & ConfigInfo ) -> Result < ( ) , String > {
105105 let start_dir = Path :: new ( "build_sysroot" ) ;
106+
106107 cleanup_sysroot_previous_build ( & start_dir) ;
107108
108109 // Builds libs
@@ -136,13 +137,7 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
136137
137138 // Copy files to sysroot
138139 let sysroot_path = start_dir. join ( format ! ( "sysroot/lib/rustlib/{}/lib/" , config. target_triple) ) ;
139- fs:: create_dir_all ( & sysroot_path) . map_err ( |error| {
140- format ! (
141- "Failed to create directory `{}`: {:?}" ,
142- sysroot_path. display( ) ,
143- error
144- )
145- } ) ?;
140+ create_dir ( & sysroot_path) ?;
146141 let copier = |dir_to_copy : & Path | {
147142 // FIXME: should not use shell command!
148143 run_command ( & [ & "cp" , & "-r" , & dir_to_copy, & sysroot_path] , None ) . map ( |_| ( ) )
@@ -155,13 +150,7 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
155150
156151 // Copy the source files to the sysroot (Rust for Linux needs this).
157152 let sysroot_src_path = start_dir. join ( "sysroot/lib/rustlib/src/rust" ) ;
158- fs:: create_dir_all ( & sysroot_src_path) . map_err ( |error| {
159- format ! (
160- "Failed to create directory `{}`: {:?}" ,
161- sysroot_src_path. display( ) ,
162- error
163- )
164- } ) ?;
153+ create_dir ( & sysroot_src_path) ?;
165154 run_command (
166155 & [
167156 & "cp" ,
@@ -216,12 +205,7 @@ fn build_codegen(args: &mut BuildArg) -> Result<(), String> {
216205 // We voluntarily ignore the error.
217206 let _ = fs:: remove_dir_all ( "target/out" ) ;
218207 let gccjit_target = "target/out/gccjit" ;
219- fs:: create_dir_all ( gccjit_target) . map_err ( |error| {
220- format ! (
221- "Failed to create directory `{}`: {:?}" ,
222- gccjit_target, error
223- )
224- } ) ?;
208+ create_dir ( gccjit_target) ?;
225209
226210 println ! ( "[BUILD] sysroot" ) ;
227211 build_sysroot ( & env, & args. config_info ) ?;
0 commit comments