Skip to content

Commit df6c73c

Browse files
committed
Create bootloader download crate in /tmp
Fixes #10
1 parent f627485 commit df6c73c

File tree

4 files changed

+64
-12
lines changed

4 files changed

+64
-12
lines changed

Cargo.lock

+53
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ byteorder = "1.2.1"
1111
toml = "0.4.5"
1212
xmas-elf = "0.6.1"
1313
cargo_metadata = "0.5.3"
14+
tempdir = "0.3.7"

src/build.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use config::{self, Config};
77
use cargo_metadata::{self, Metadata as CargoMetadata, Package as CrateMetadata};
88
use Error;
99
use xmas_elf;
10+
use tempdir::TempDir;
1011

1112
const BLOCK_SIZE: usize = 512;
1213
type KernelInfoBlock = [u8; BLOCK_SIZE];
@@ -78,7 +79,9 @@ fn build_impl(
7879
fs::remove_file(bootloader_cargo_lock)?;
7980
}
8081

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()?;
8285

8386
create_disk_image(&config, kernel, kernel_info_block, &bootloader)?;
8487

@@ -155,22 +158,16 @@ fn create_kernel_info_block(kernel_size: u64) -> KernelInfoBlock {
155158
kernel_info_block
156159
}
157160

158-
fn download_bootloader(out_dir: &Path, config: &Config) -> Result<CrateMetadata, Error> {
161+
fn download_bootloader(bootloader_dir: &Path, config: &Config) -> Result<CrateMetadata, Error> {
159162
use std::io::Write;
160163

161-
let bootloader_dir = {
162-
let mut dir = PathBuf::from(out_dir);
163-
dir.push("bootloader");
164-
dir
165-
};
166-
167164
let cargo_toml = {
168-
let mut dir = bootloader_dir.clone();
165+
let mut dir = bootloader_dir.to_owned();
169166
dir.push("Cargo.toml");
170167
dir
171168
};
172169
let src_lib = {
173-
let mut dir = bootloader_dir.clone();
170+
let mut dir = bootloader_dir.to_owned();
174171
dir.push("src");
175172
fs::create_dir_all(dir.as_path())?;
176173
dir.push("lib.rs");
@@ -262,10 +259,10 @@ fn download_bootloader(out_dir: &Path, config: &Config) -> Result<CrateMetadata,
262259
Ok(bootloader.clone())
263260
}
264261

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> {
266263
use std::io::Read;
267264

268-
let bootloader_metadata = download_bootloader(out_dir, config)?;
265+
let bootloader_metadata = download_bootloader(bootloader_dir, config)?;
269266
let bootloader_dir = Path::new(&bootloader_metadata.manifest_path)
270267
.parent()
271268
.unwrap();

src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
extern crate byteorder;
22
extern crate cargo_metadata;
3+
extern crate tempdir;
34
extern crate toml;
45
extern crate xmas_elf;
56

0 commit comments

Comments
 (0)