Commit 3165ae8d authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Merge branch 'mggmuggins-local-sources' into 'master'

Allow local non-git sources

See merge request !250
parents 8b9d3788 0c0aa91c
......@@ -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()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment