fix(cook): build shared dependencies

Before it was not check if the shared dependencies of a package had been
built. This resulted in the installer panicking as it tried to install
a non-built package. This commit fixes that issue.

Signed-off-by: Anhad Singh <andypython@protonmail.com>
This commit is contained in:
Anhad Singh 2025-01-28 21:52:34 +11:00
parent 443b55efd9
commit 212692e1ea
No known key found for this signature in database
GPG Key ID: 80E0357347554B89
2 changed files with 18 additions and 6 deletions

View File

@ -1,5 +1,5 @@
use cookbook::blake3::blake3_progress;
use cookbook::recipe::{BuildKind, BuildRecipe, PackageRecipe, Recipe, SourceRecipe};
use cookbook::recipe::{BuildKind, PackageRecipe, Recipe, SourceRecipe};
use cookbook::recipe_find::recipe_find;
use std::{
env, fs,
@ -454,10 +454,10 @@ fn build(
source_dir: &Path,
target_dir: &Path,
name: &str,
build: &BuildRecipe,
recipe: &Recipe,
) -> Result<PathBuf, String> {
let mut dep_pkgars = vec![];
for dependency in build.dependencies.iter() {
for dependency in recipe.dependencies_iter() {
//TODO: sanitize name
let dependency_dir = recipe_find(dependency, Path::new("recipes"))?;
if dependency_dir.is_none() {
@ -720,7 +720,7 @@ done
//TODO: better integration with redoxer (library instead of binary)
//TODO: configurable target
//TODO: Add more configurability, convert scripts to Rust?
let script = match &build.kind {
let script = match &recipe.build.kind {
BuildKind::Cargo {
package_path,
cargoflags,
@ -862,7 +862,7 @@ fn cook(recipe_dir: &Path, name: &str, recipe: &Recipe, fetch_only: bool) -> Res
create_dir(&target_dir)?;
}
let stage_dir = build(recipe_dir, &source_dir, &target_dir, name, &recipe.build)
let stage_dir = build(recipe_dir, &source_dir, &target_dir, name, &recipe)
.map_err(|err| format!("failed to build: {}", err))?;
let _package_file = package(recipe_dir, &stage_dir, &target_dir, name, &recipe.package)
@ -925,7 +925,7 @@ impl CookRecipe {
let recipe = Self::new(name.clone())?;
let dependencies =
Self::new_recursive(&recipe.recipe.build.dependencies, recursion - 1).map_err(
Self::new_recursive(&recipe.recipe.dependencies(), recursion - 1).map_err(
|err| format!("{}: failed on loading build dependencies:\n{}", name, err),
)?;

View File

@ -94,6 +94,18 @@ pub struct Recipe {
pub package: PackageRecipe,
}
impl Recipe {
#[inline]
pub fn dependencies_iter(&self) -> impl Iterator<Item = &String> {
self.build.dependencies.iter().chain(self.package.shared_deps.iter())
}
#[inline]
pub fn dependencies(&self) -> Vec<String> {
self.dependencies_iter().cloned().collect::<Vec<_>>()
}
}
#[cfg(test)]
mod tests {
#[test]