mirror of
https://gitlab.redox-os.org/redox-os/redox.git
synced 2026-06-25 22:34:18 +08:00
Refactor out deps helper fn
This commit is contained in:
parent
bd78177329
commit
7654063412
@ -10,7 +10,7 @@ use cookbook::cook::pty::{PtyOut, UnixSlavePty, flush_pty, setup_pty};
|
||||
use cookbook::cook::script::KILL_ALL_PID;
|
||||
use cookbook::cook::tree::{WalkTreeEntry, display_tree_entry, format_size, walk_tree_entry};
|
||||
use cookbook::log_to_pty;
|
||||
use cookbook::recipe::CookRecipe;
|
||||
use cookbook::recipe::{CookRecipe, recipes_flatten_package_names, recipes_mark_as_deps};
|
||||
use pkg::PackageName;
|
||||
use pkg::package::PackageError;
|
||||
use ratatui::Terminal;
|
||||
@ -492,13 +492,14 @@ fn parse_args(args: Vec<String>) -> anyhow::Result<(CliConfig, CliCommand, Vec<C
|
||||
recipe_names = CookRecipe::get_package_deps_recursive(&recipe_names, true)
|
||||
.context("failed get package deps")?;
|
||||
}
|
||||
CookRecipe::get_build_deps_recursive(
|
||||
&recipe_names,
|
||||
!command.is_pushing(),
|
||||
let mut packages =
|
||||
CookRecipe::get_build_deps_recursive(&recipe_names, !command.is_pushing())?;
|
||||
if command.is_pushing() || !config.with_package_deps {
|
||||
// In CliCommand::Cook, is_deps==true will make it skip checking source
|
||||
command.is_pushing() || !config.with_package_deps,
|
||||
true,
|
||||
)?
|
||||
recipes_mark_as_deps(&recipe_names, &mut packages);
|
||||
}
|
||||
packages = recipes_flatten_package_names(packages);
|
||||
packages
|
||||
} else {
|
||||
recipe_names
|
||||
.iter()
|
||||
|
||||
@ -194,8 +194,8 @@ pub fn build(
|
||||
&recipe.build.dev_dependencies[..],
|
||||
]
|
||||
.concat();
|
||||
let build_deps = CookRecipe::get_build_deps_recursive(&build_deps, false, false, false)
|
||||
.map_err(|e| format!("{:?}", e))?;
|
||||
let build_deps =
|
||||
CookRecipe::get_build_deps_recursive(&build_deps, false).map_err(|e| format!("{:?}", e))?;
|
||||
for dependency in build_deps.iter() {
|
||||
let (_, pkgar, _) = dependency.stage_paths();
|
||||
if dependency.name.is_host() {
|
||||
|
||||
@ -282,7 +282,7 @@ impl CookRecipe {
|
||||
Self::new(name, dir.to_path_buf(), recipe)
|
||||
}
|
||||
|
||||
pub fn new_recursive(
|
||||
fn new_recursive(
|
||||
names: &[PackageName],
|
||||
recurse_build_deps: bool,
|
||||
recurse_dev_build_deps: bool,
|
||||
@ -385,10 +385,8 @@ impl CookRecipe {
|
||||
pub fn get_build_deps_recursive(
|
||||
names: &[PackageName],
|
||||
include_dev: bool,
|
||||
mark_is_deps: bool,
|
||||
flatten_opt_package: bool,
|
||||
) -> Result<Vec<Self>, PackageError> {
|
||||
let mut packages = Self::new_recursive(
|
||||
let packages = Self::new_recursive(
|
||||
names,
|
||||
true,
|
||||
include_dev,
|
||||
@ -399,30 +397,6 @@ impl CookRecipe {
|
||||
WALK_DEPTH,
|
||||
)?;
|
||||
|
||||
if mark_is_deps {
|
||||
for package in packages.iter_mut() {
|
||||
package.is_deps = !names.contains(&package.name);
|
||||
}
|
||||
}
|
||||
|
||||
if flatten_opt_package {
|
||||
let old_packages = packages;
|
||||
packages = Vec::new();
|
||||
let mut packages_set = BTreeSet::new();
|
||||
for mut package in old_packages {
|
||||
let is_host = package.name.is_host();
|
||||
let mut name = package.name.with_suffix(None);
|
||||
if is_host {
|
||||
name = name.with_host();
|
||||
}
|
||||
if !packages_set.contains(name.as_str()) {
|
||||
packages_set.insert(name.to_string());
|
||||
package.name = name;
|
||||
packages.push(package);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(packages)
|
||||
}
|
||||
|
||||
@ -497,6 +471,32 @@ impl CookRecipe {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Wrap these vectors in a struct
|
||||
|
||||
pub fn recipes_mark_as_deps(names: &[PackageName], packages: &mut Vec<CookRecipe>) {
|
||||
for package in packages.iter_mut() {
|
||||
package.is_deps = !names.contains(&package.name);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn recipes_flatten_package_names(packages: Vec<CookRecipe>) -> Vec<CookRecipe> {
|
||||
let mut new_packages = Vec::new();
|
||||
let mut packages_set = BTreeSet::new();
|
||||
for mut package in packages {
|
||||
let is_host = package.name.is_host();
|
||||
let mut name = package.name.with_suffix(None);
|
||||
if is_host {
|
||||
name = name.with_host();
|
||||
}
|
||||
if !packages_set.contains(name.as_str()) {
|
||||
packages_set.insert(name.to_string());
|
||||
package.name = name;
|
||||
new_packages.push(package);
|
||||
}
|
||||
}
|
||||
new_packages
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct AutoDeps {
|
||||
pub packages: BTreeSet<PackageName>,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user