@@ -7,6 +7,7 @@ use config::{self, Config};
7
7
use cargo_metadata:: { self , Metadata as CargoMetadata , Package as CrateMetadata } ;
8
8
use Error ;
9
9
use xmas_elf;
10
+ use tempdir:: TempDir ;
10
11
11
12
const BLOCK_SIZE : usize = 512 ;
12
13
type KernelInfoBlock = [ u8 ; BLOCK_SIZE ] ;
@@ -78,7 +79,9 @@ fn build_impl(
78
79
fs:: remove_file ( bootloader_cargo_lock) ?;
79
80
}
80
81
81
- let bootloader = build_bootloader ( & out_dir, & config) ?;
82
+ let tmp_dir = TempDir :: new ( "bootloader" ) ?;
83
+ let bootloader = build_bootloader ( tmp_dir. path ( ) , & config) ?;
84
+ tmp_dir. close ( ) ?;
82
85
83
86
create_disk_image ( & config, kernel, kernel_info_block, & bootloader) ?;
84
87
@@ -155,22 +158,16 @@ fn create_kernel_info_block(kernel_size: u64) -> KernelInfoBlock {
155
158
kernel_info_block
156
159
}
157
160
158
- fn download_bootloader ( out_dir : & Path , config : & Config ) -> Result < CrateMetadata , Error > {
161
+ fn download_bootloader ( bootloader_dir : & Path , config : & Config ) -> Result < CrateMetadata , Error > {
159
162
use std:: io:: Write ;
160
163
161
- let bootloader_dir = {
162
- let mut dir = PathBuf :: from ( out_dir) ;
163
- dir. push ( "bootloader" ) ;
164
- dir
165
- } ;
166
-
167
164
let cargo_toml = {
168
- let mut dir = bootloader_dir. clone ( ) ;
165
+ let mut dir = bootloader_dir. to_owned ( ) ;
169
166
dir. push ( "Cargo.toml" ) ;
170
167
dir
171
168
} ;
172
169
let src_lib = {
173
- let mut dir = bootloader_dir. clone ( ) ;
170
+ let mut dir = bootloader_dir. to_owned ( ) ;
174
171
dir. push ( "src" ) ;
175
172
fs:: create_dir_all ( dir. as_path ( ) ) ?;
176
173
dir. push ( "lib.rs" ) ;
@@ -262,10 +259,10 @@ fn download_bootloader(out_dir: &Path, config: &Config) -> Result<CrateMetadata,
262
259
Ok ( bootloader. clone ( ) )
263
260
}
264
261
265
- fn build_bootloader ( out_dir : & Path , config : & Config ) -> Result < Box < [ u8 ] > , Error > {
262
+ fn build_bootloader ( bootloader_dir : & Path , config : & Config ) -> Result < Box < [ u8 ] > , Error > {
266
263
use std:: io:: Read ;
267
264
268
- let bootloader_metadata = download_bootloader ( out_dir , config) ?;
265
+ let bootloader_metadata = download_bootloader ( bootloader_dir , config) ?;
269
266
let bootloader_dir = Path :: new ( & bootloader_metadata. manifest_path )
270
267
. parent ( )
271
268
. unwrap ( ) ;
0 commit comments