diff --git a/recipes/core/drivers-initfs/recipe.toml b/recipes/core/drivers-initfs/recipe.toml index 8baa45ab0e52bdcf3c96ce017bae733ef4eab559..bf4fd64e789b0ab10f44798f4c247832b8ab13e9 100644 --- a/recipes/core/drivers-initfs/recipe.toml +++ b/recipes/core/drivers-initfs/recipe.toml @@ -1,5 +1,5 @@ [source] -git = "https://gitlab.redox-os.org/redox-os/drivers.git" +same_as = "../drivers" [build] template = "custom" diff --git a/src/bin/cook.rs b/src/bin/cook.rs index d271117a046aabf9b0181f87641f74c6535abe3b..0908b4653c9c32a013700b585a357ab59155a3ba 100644 --- a/src/bin/cook.rs +++ b/src/bin/cook.rs @@ -162,6 +162,25 @@ fn run_command_stdin(mut command: process::Command, stdin_data: &[u8]) -> Result fn fetch(recipe_dir: &Path, source: &Option<SourceRecipe>) -> Result<PathBuf, String> { let source_dir = recipe_dir.join("source"); match source { + Some(SourceRecipe::SameAs { same_as }) => { + if ! source_dir.is_symlink() { + if source_dir.is_dir() { + return Err(format!( + "'{dir}' is a directory, but recipe indicated a symlink. \n\ + try removing '{dir}' if you haven't made any changes that would be lost", + dir=source_dir.display(), + )); + } + let original = Path::new(same_as).join("source"); + std::os::unix::fs::symlink(&original, &source_dir).map_err(|err| format!( + "failed to symlink '{}' to '{}': {}\n{:?}", + original.display(), + source_dir.display(), + err, + err + ))?; + } + } Some(SourceRecipe::Git { git, upstream, branch, rev }) => { //TODO: use libgit? if ! source_dir.is_dir() { diff --git a/src/recipe.rs b/src/recipe.rs index ca74754f33ad2ac6992c682f235a4ef716472466..e69742a85efe0fb947cb268a1ce7f2c670b6f731 100644 --- a/src/recipe.rs +++ b/src/recipe.rs @@ -4,6 +4,14 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Deserialize, PartialEq, Serialize)] #[serde(untagged)] pub enum SourceRecipe { + /// Reuse the source directory of another package + /// + /// This is useful when a single source repo contains multiple projects which each have their + /// own recipe to build them. + SameAs { + /// Relative path to the package for which to reuse the source dir + same_as: String, + }, /// A git repository source Git { /// The URL for the git repository, such as https://gitlab.redox-os.org/redox-os/ion.git