mirror of
https://gitlab.redox-os.org/redox-os/redox.git
synced 2026-06-20 03:44:18 +08:00
Allow local sources
This makes the source section of recipe.toml optional, so that one can simply create a recipe with a build recipe and a source folder and not have to worry about git at all just to get a program running in redox. I also ran into a situation where a source directory without a git repository in it caused cookbook to reset it's own origin URL to the URL specified in the recipe for that source directory. I added a check to prevent that happening to anybody else.
This commit is contained in:
parent
8b9d3788c4
commit
0c0aa91cab
@ -159,10 +159,10 @@ fn run_command_stdin(mut command: process::Command, stdin_data: &[u8]) -> Result
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn fetch(recipe_dir: &Path, source: &SourceRecipe) -> Result<PathBuf, String> {
|
||||
fn fetch(recipe_dir: &Path, source: &Option<SourceRecipe>) -> Result<PathBuf, String> {
|
||||
let source_dir = recipe_dir.join("source");
|
||||
match source {
|
||||
SourceRecipe::Git { git, upstream, branch, rev } => {
|
||||
Some(SourceRecipe::Git { git, upstream, branch, rev }) => {
|
||||
//TODO: use libgit?
|
||||
if ! source_dir.is_dir() {
|
||||
// Create source.tmp
|
||||
@ -181,6 +181,15 @@ fn fetch(recipe_dir: &Path, source: &SourceRecipe) -> Result<PathBuf, String> {
|
||||
// Move source.tmp to source atomically
|
||||
rename(&source_dir_tmp, &source_dir)?;
|
||||
} else {
|
||||
// Don't let this code reset the origin for the cookbook repo
|
||||
let source_git_dir = source_dir.join(".git");
|
||||
if ! source_git_dir.is_dir() {
|
||||
return Err(format!(
|
||||
"'{}' is not a git repository, but recipe indicated git source",
|
||||
source_dir.display(),
|
||||
));
|
||||
}
|
||||
|
||||
// Reset origin
|
||||
let mut command = Command::new("git");
|
||||
command.arg("-C").arg(&source_dir);
|
||||
@ -240,7 +249,7 @@ fi"#);
|
||||
command.arg("submodule").arg("update").arg("--init").arg("--recursive");
|
||||
run_command(command)?;
|
||||
},
|
||||
SourceRecipe::Tar { tar, blake3, sha256, patches, script } => {
|
||||
Some(SourceRecipe::Tar { tar, blake3, sha256, patches, script }) => {
|
||||
if ! source_dir.is_dir() {
|
||||
// Download tar
|
||||
//TODO: replace wget
|
||||
@ -350,7 +359,16 @@ fi"#);
|
||||
// Move source.tmp to source atomically
|
||||
rename(&source_dir_tmp, &source_dir)?;
|
||||
}
|
||||
}
|
||||
},
|
||||
// Local Sources
|
||||
None => {
|
||||
if ! source_dir.is_dir() {
|
||||
return Err(format!(
|
||||
"Recipe without source section expected source dir at '{}'",
|
||||
source_dir.display(),
|
||||
))
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
Ok(source_dir)
|
||||
|
||||
@ -69,7 +69,7 @@ pub struct PackageRecipe {
|
||||
#[derive(Debug, Deserialize, PartialEq, Serialize)]
|
||||
pub struct Recipe {
|
||||
/// Specifies how to donload the source for this recipe
|
||||
pub source: SourceRecipe,
|
||||
pub source: Option<SourceRecipe>,
|
||||
/// Specifies how to build this recipe
|
||||
pub build: BuildRecipe,
|
||||
/// Specifies how to package this recipe
|
||||
@ -95,12 +95,12 @@ mod tests {
|
||||
"#).unwrap();
|
||||
|
||||
assert_eq!(recipe, Recipe {
|
||||
source: SourceRecipe::Git {
|
||||
source: Some(SourceRecipe::Git {
|
||||
git: "https://gitlab.redox-os.org/redox-os/acid.git".to_string(),
|
||||
upstream: None,
|
||||
branch: Some("master".to_string()),
|
||||
rev: Some("06344744d3d55a5ac9a62a6059cb363d40699bbc".to_string()),
|
||||
},
|
||||
}),
|
||||
build: BuildRecipe {
|
||||
kind: BuildKind::Cargo,
|
||||
dependencies: Vec::new(),
|
||||
@ -126,13 +126,13 @@ mod tests {
|
||||
"#).unwrap();
|
||||
|
||||
assert_eq!(recipe, Recipe {
|
||||
source: SourceRecipe::Tar {
|
||||
source: Some(SourceRecipe::Tar {
|
||||
tar: "http://downloads.xiph.org/releases/ogg/libogg-1.3.3.tar.xz".to_string(),
|
||||
blake3: None,
|
||||
sha256: Some("4f3fc6178a533d392064f14776b23c397ed4b9f48f5de297aba73b643f955c08".to_string()),
|
||||
patches: Vec::new(),
|
||||
script: None,
|
||||
},
|
||||
}),
|
||||
build: BuildRecipe {
|
||||
kind: BuildKind::Custom {
|
||||
script: "make".to_string()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user