Use a single source dir for the drivers and drivers-initfs recipes

This makes it easier to make driver changes. And in the future other
recipes could potentially benefit from the same infrastructure too.
This commit is contained in:
bjorn3 2024-07-06 21:01:57 +02:00
parent 5d3769b4c6
commit 4a2109c2c7
3 changed files with 28 additions and 1 deletions

View File

@ -1,5 +1,5 @@
[source]
git = "https://gitlab.redox-os.org/redox-os/drivers.git"
same_as = "../drivers"
[build]
template = "custom"

View File

@ -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() {

View File

@ -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