mirror of
https://gitlab.redox-os.org/redox-os/redox.git
synced 2026-06-17 23:44:17 +08:00
Cook recipes with depedencies
This commit is contained in:
parent
5156207ff7
commit
0e5e9fbc58
@ -1090,18 +1090,37 @@ fn main() {
|
||||
let mut matching = true;
|
||||
let mut dry_run = false;
|
||||
let mut fetch_only = false;
|
||||
let mut with_package_deps = false;
|
||||
let mut quiet = false;
|
||||
let mut recipe_names = Vec::new();
|
||||
for arg in env::args().skip(1) {
|
||||
match arg.as_str() {
|
||||
"--" if matching => matching = false,
|
||||
"-d" | "--dry-run" if matching => dry_run = true,
|
||||
"--with-package-deps" if matching => with_package_deps = true,
|
||||
"--fetch-only" if matching => fetch_only = true,
|
||||
"-q" | "--quiet" if matching => quiet = true,
|
||||
_ => recipe_names.push(arg),
|
||||
}
|
||||
}
|
||||
|
||||
if with_package_deps {
|
||||
recipe_names = match CookRecipe::get_package_deps_recursive(&recipe_names, 16) {
|
||||
Ok(ok) => ok,
|
||||
Err(err) => {
|
||||
eprintln!(
|
||||
"{}{}cook - error:{}{} {}",
|
||||
style::Bold,
|
||||
color::Fg(color::AnsiValue(196)),
|
||||
color::Fg(color::Reset),
|
||||
style::Reset,
|
||||
err,
|
||||
);
|
||||
process::exit(1);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
let recipes = match CookRecipe::new_recursive(&recipe_names, 16) {
|
||||
Ok(ok) => ok,
|
||||
Err(err) => {
|
||||
|
||||
@ -175,6 +175,37 @@ impl CookRecipe {
|
||||
|
||||
Ok(recipes)
|
||||
}
|
||||
|
||||
pub fn get_package_deps_recursive(names: &[String], recursion: usize) -> Result<Vec<String>, String> {
|
||||
if recursion == 0 {
|
||||
return Err(format!(
|
||||
"recursion limit while processing package dependencies: {:#?}",
|
||||
names
|
||||
));
|
||||
}
|
||||
|
||||
let mut recipes = Vec::new();
|
||||
for name in names {
|
||||
let recipe = Self::new(name.clone())?;
|
||||
|
||||
let dependencies =
|
||||
Self::get_package_deps_recursive(&recipe.recipe.package.dependencies, recursion - 1).map_err(
|
||||
|err| format!("{}: failed on loading package dependencies:\n{}", name, err),
|
||||
)?;
|
||||
|
||||
for dependency in dependencies {
|
||||
if !recipes.contains(&dependency) {
|
||||
recipes.push(dependency);
|
||||
}
|
||||
}
|
||||
|
||||
if !recipes.contains(&name) {
|
||||
recipes.push(name.clone());
|
||||
}
|
||||
}
|
||||
|
||||
Ok(recipes)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@ -216,7 +247,6 @@ mod tests {
|
||||
},
|
||||
package: PackageRecipe {
|
||||
dependencies: Vec::new(),
|
||||
shared_deps: Vec::new(),
|
||||
},
|
||||
}
|
||||
);
|
||||
@ -259,7 +289,6 @@ mod tests {
|
||||
},
|
||||
package: PackageRecipe {
|
||||
dependencies: Vec::new(),
|
||||
shared_deps: Vec::new(),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user