reorganized build script a bit
This commit is contained in:
parent
dc2a7f7a1f
commit
2dec4334f4
53
build.rs
53
build.rs
@ -7,39 +7,50 @@ fn main() -> Result<()> {
|
|||||||
build_phinit()?;
|
build_phinit()?;
|
||||||
run_simple_make("sommelier")?;
|
run_simple_make("sommelier")?;
|
||||||
run_simple_make("kernel")?;
|
run_simple_make("kernel")?;
|
||||||
|
// Rerun build.rs upon making or pulling in new commits
|
||||||
|
println!("cargo:rerun-if-changed=.git/refs/heads/master");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_phinit() -> Result<()> {
|
fn build_phinit() -> Result<()> {
|
||||||
run_command_in_directory(
|
let _dir = ChdirTo::path("ph-init");
|
||||||
"ph-init",
|
|
||||||
"cargo",
|
Command::new("cargo")
|
||||||
&["build", "--release"]
|
.arg("build")
|
||||||
)?;
|
.arg("--release")
|
||||||
run_command_in_directory(
|
.status()?;
|
||||||
"ph-init",
|
|
||||||
"strip",
|
Command::new("strip")
|
||||||
&["target/release/ph-init"]
|
.arg("target/release/ph-init")
|
||||||
)?;
|
.status()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_simple_make<P: AsRef<Path>>(directory: P) -> Result<()> {
|
fn run_simple_make<P: AsRef<Path>>(directory: P) -> Result<()> {
|
||||||
run_command_in_directory(directory, "make", &[])
|
let _dir = ChdirTo::path(directory);
|
||||||
|
Command::new("make").status()?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_command_in_directory<P: AsRef<Path>>(directory: P, cmd: &str, args: &[&str]) -> Result<()> {
|
struct ChdirTo {
|
||||||
let saved = push_directory(directory)?;
|
saved: PathBuf,
|
||||||
Command::new(cmd).args(args).status()?;
|
|
||||||
env::set_current_dir(saved)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push_directory<P: AsRef<Path>>(directory: P) -> Result<PathBuf> {
|
impl ChdirTo {
|
||||||
let current = env::current_dir()?;
|
fn path<P: AsRef<Path>>(directory: P) -> ChdirTo {
|
||||||
env::set_current_dir(directory.as_ref())?;
|
let saved = env::current_dir()
|
||||||
Ok(current)
|
.expect("current_dir()");
|
||||||
|
env::set_current_dir(directory.as_ref())
|
||||||
|
.expect("set_current_dir()");
|
||||||
|
ChdirTo { saved }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Drop for ChdirTo {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
env::set_current_dir(&self.saved)
|
||||||
|
.expect("restore current dir");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user