Skip to content
Snippets Groups Projects

Rebuild sysroot if dependencies change

Merged bjorn3 requested to merge bjorn3/cookbook:rebuild_sysroot_if_deps_change into master
1 file
+ 18
13
Compare changes
  • Side-by-side
  • Inline
+ 18
13
@@ -356,12 +356,26 @@ fi"#);
@@ -356,12 +356,26 @@ fi"#);
}
}
fn build(recipe_dir: &Path, source_dir: &Path, target_dir: &Path, build: &BuildRecipe) -> Result<PathBuf, String> {
fn build(recipe_dir: &Path, source_dir: &Path, target_dir: &Path, build: &BuildRecipe) -> Result<PathBuf, String> {
 
let mut dep_pkgars = vec![];
 
for dependency in build.dependencies.iter() {
 
//TODO: sanitize name
 
let dependency_dir = recipe_find(dependency, Path::new("recipes"))?;
 
if dependency_dir.is_none() {
 
return Err(format!(
 
"failed to find recipe directory '{}'",
 
dependency
 
));
 
}
 
dep_pkgars.push(dependency_dir.unwrap().join("target").join(redoxer::target()).join("stage.pkgar"));
 
}
 
let source_modified = modified_dir_ignore_git(source_dir)?;
let source_modified = modified_dir_ignore_git(source_dir)?;
 
let deps_modified = dep_pkgars.iter().map(|pkgar| modified(pkgar)).max().unwrap_or(Ok(SystemTime::UNIX_EPOCH))?;
let sysroot_dir = target_dir.join("sysroot");
let sysroot_dir = target_dir.join("sysroot");
// Rebuild sysroot if source is newer
// Rebuild sysroot if source is newer
//TODO: rebuild on recipe changes
//TODO: rebuild on recipe changes
if sysroot_dir.is_dir() && modified_dir(&sysroot_dir)? < source_modified {
if sysroot_dir.is_dir() && (modified_dir(&sysroot_dir)? < source_modified || modified_dir(&sysroot_dir)? < deps_modified) {
eprintln!("DEBUG: '{}' newer than '{}'", source_dir.display(), sysroot_dir.display());
eprintln!("DEBUG: '{}' newer than '{}'", source_dir.display(), sysroot_dir.display());
remove_all(&sysroot_dir)?;
remove_all(&sysroot_dir)?;
}
}
@@ -375,24 +389,15 @@ fn build(recipe_dir: &Path, source_dir: &Path, target_dir: &Path, build: &BuildR
@@ -375,24 +389,15 @@ fn build(recipe_dir: &Path, source_dir: &Path, target_dir: &Path, build: &BuildR
// Make sure sysroot/lib exists
// Make sure sysroot/lib exists
create_dir(&sysroot_dir_tmp.join("lib"))?;
create_dir(&sysroot_dir_tmp.join("lib"))?;
for dependency in build.dependencies.iter() {
for archive_path in dep_pkgars {
let public_path = "build/id_ed25519.pub.toml";
let public_path = "build/id_ed25519.pub.toml";
//TODO: sanitize name
let dependency_dir = recipe_find(dependency, Path::new("recipes"))?;
if dependency_dir.is_none() {
return Err(format!(
"failed to find recipe directory '{}'",
dependency
));
}
let archive_path = format!("{}/target/{}/stage.pkgar", dependency_dir.unwrap().display(), redoxer::target());
pkgar::extract(
pkgar::extract(
public_path,
public_path,
&archive_path,
&archive_path,
sysroot_dir_tmp.to_str().unwrap()
sysroot_dir_tmp.to_str().unwrap()
).map_err(|err| format!(
).map_err(|err| format!(
"failed to install '{}' in '{}': {:?}",
"failed to install '{}' in '{}': {:?}",
archive_path,
archive_path.display(),
sysroot_dir_tmp.display(),
sysroot_dir_tmp.display(),
err
err
))?;
))?;
@@ -405,7 +410,7 @@ fn build(recipe_dir: &Path, source_dir: &Path, target_dir: &Path, build: &BuildR
@@ -405,7 +410,7 @@ fn build(recipe_dir: &Path, source_dir: &Path, target_dir: &Path, build: &BuildR
let stage_dir = target_dir.join("stage");
let stage_dir = target_dir.join("stage");
// Rebuild stage if source is newer
// Rebuild stage if source is newer
//TODO: rebuild on recipe changes
//TODO: rebuild on recipe changes
if stage_dir.is_dir() && modified_dir(&stage_dir)? < source_modified {
if stage_dir.is_dir() && (modified_dir(&stage_dir)? < source_modified || modified_dir(&stage_dir)? < deps_modified) {
eprintln!("DEBUG: '{}' newer than '{}'", source_dir.display(), stage_dir.display());
eprintln!("DEBUG: '{}' newer than '{}'", source_dir.display(), stage_dir.display());
remove_all(&stage_dir)?;
remove_all(&stage_dir)?;
}
}
Loading