Update to not recompile if code hasn't changed
This commit is contained in:
28
src/app.rs
28
src/app.rs
@@ -245,6 +245,22 @@ fn build(mode: &Option<String>) -> std::io::Result<()> {
|
||||
|
||||
std::fs::create_dir_all(format!("target/{}", build_config.name))?;
|
||||
|
||||
let hash = hash_src_tree()?;
|
||||
|
||||
let old_compute_path = PathBuf::from(format!("target/{}/.build_hash", build_config.name));
|
||||
|
||||
if old_compute_path.exists() {
|
||||
let text = std::fs::read_to_string(old_compute_path)?;
|
||||
|
||||
if hash.trim() == text.trim() {
|
||||
println!(
|
||||
" {} (code not changed, recompile not made)",
|
||||
"Finished".green().bold()
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
let mut command = Command::new("gcc");
|
||||
|
||||
for arg in &build_config.args {
|
||||
@@ -280,6 +296,18 @@ fn build(mode: &Option<String>) -> std::io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn hash_src_tree() -> std::io::Result<String> {
|
||||
let mut hashes = String::new();
|
||||
for entry in glob("src/").expect("a valid glob pattern") {
|
||||
if let Ok(file) = entry {
|
||||
let text = std::fs::read_to_string(file)?;
|
||||
let hash = sha256::digest(text);
|
||||
hashes.push_str(hash.as_str());
|
||||
}
|
||||
}
|
||||
Ok(sha256::digest(hashes))
|
||||
}
|
||||
|
||||
fn run(mode: &Option<String>, args: Option<Vec<String>>) -> std::io::Result<()> {
|
||||
let conf = match get_config() {
|
||||
Some(conf) => conf,
|
||||
|
||||
Reference in New Issue
Block a user