mirror of
https://gitlab.redox-os.org/redox-os/redox.git
synced 2026-06-24 05:44:17 +08:00
Merge branch 'recurse-sysroot' into 'master'
Recurse build deps in sysroot See merge request redox-os/cookbook!681
This commit is contained in:
commit
38bc9ae66f
@ -4,16 +4,7 @@ dependencies = [
|
||||
"sdl2-image",
|
||||
"sdl2-mixer",
|
||||
"sdl2-ttf",
|
||||
"sdl2",
|
||||
"liborbital",
|
||||
"llvm18",
|
||||
"mesa",
|
||||
"freetype2",
|
||||
"libjpeg",
|
||||
"libpng",
|
||||
"libogg",
|
||||
"libvorbis",
|
||||
"zlib"
|
||||
]
|
||||
script = """
|
||||
DYNAMIC_INIT
|
||||
|
||||
@ -6,7 +6,6 @@ branch = "master"
|
||||
template = "custom"
|
||||
dependencies = [
|
||||
"gettext",
|
||||
"libiconv",
|
||||
"libxkbcommon",
|
||||
]
|
||||
script = """
|
||||
|
||||
@ -89,20 +89,21 @@ fn main() {
|
||||
};
|
||||
}
|
||||
|
||||
let recipes = match CookRecipe::get_build_deps_recursive(&recipe_names, !with_package_deps) {
|
||||
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::get_build_deps_recursive(&recipe_names, true, !with_package_deps) {
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
for recipe in recipes {
|
||||
if !quiet {
|
||||
|
||||
@ -9,7 +9,7 @@ use cookbook::cook::pty::{PtyOut, UnixSlavePty, flush_pty, setup_pty};
|
||||
use cookbook::cook::script::KILL_ALL_PID;
|
||||
use cookbook::cook::tree::{display_tree_entry, format_size};
|
||||
use cookbook::log_to_pty;
|
||||
use cookbook::recipe::{BuildKind, CookRecipe};
|
||||
use cookbook::recipe::CookRecipe;
|
||||
use pkg::PackageName;
|
||||
use pkg::package::PackageError;
|
||||
use ratatui::Terminal;
|
||||
@ -418,6 +418,7 @@ fn parse_args(args: Vec<String>) -> anyhow::Result<(CliConfig, CliCommand, Vec<C
|
||||
if command.is_building() {
|
||||
CookRecipe::get_build_deps_recursive(
|
||||
&recipe_names,
|
||||
true,
|
||||
// In CliCommand::Cook, is_deps==true will make it skip checking source
|
||||
command == CliCommand::Tree || !config.with_package_deps,
|
||||
)?
|
||||
@ -441,10 +442,7 @@ fn parse_args(args: Vec<String>) -> anyhow::Result<(CliConfig, CliCommand, Vec<C
|
||||
// should not gone here, but if it does, then some deps need it
|
||||
PackageConfig::Build(rule) if rule == "binary" || rule == "ignore" => {
|
||||
recipe.recipe.source = None;
|
||||
recipe.recipe.build = cookbook::recipe::BuildRecipe {
|
||||
kind: BuildKind::Remote,
|
||||
dependencies: Vec::new(),
|
||||
};
|
||||
recipe.recipe.build.set_as_remote();
|
||||
}
|
||||
PackageConfig::Build(rule) => {
|
||||
return Err(anyhow!(
|
||||
@ -458,10 +456,7 @@ fn parse_args(args: Vec<String>) -> anyhow::Result<(CliConfig, CliCommand, Vec<C
|
||||
if conf.general.repo_binary == Some(true) {
|
||||
// same reason as Build("binary")
|
||||
recipe.recipe.source = None;
|
||||
recipe.recipe.build = cookbook::recipe::BuildRecipe {
|
||||
kind: BuildKind::Remote,
|
||||
dependencies: Vec::new(),
|
||||
};
|
||||
recipe.recipe.build.set_as_remote();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
use pkg::package::PackageError;
|
||||
use pkg::recipes;
|
||||
use pkg::{Package, PackageName};
|
||||
use redoxer::target;
|
||||
|
||||
@ -178,15 +177,13 @@ pub fn build(
|
||||
}
|
||||
|
||||
let mut dep_pkgars = BTreeSet::new();
|
||||
for dependency in recipe.build.dependencies.iter() {
|
||||
let dependency_dir = recipes::find(dependency.as_str());
|
||||
if dependency_dir.is_none() {
|
||||
return Err(format!("failed to find recipe directory '{}'", dependency));
|
||||
}
|
||||
let build_deps = CookRecipe::get_build_deps_recursive(&recipe.build.dependencies, false, false)
|
||||
.map_err(|e| format!("{:?}", e))?;
|
||||
for dependency in build_deps.iter() {
|
||||
dep_pkgars.insert((
|
||||
dependency.clone(),
|
||||
dependency_dir
|
||||
.unwrap()
|
||||
dependency.name.clone(),
|
||||
dependency
|
||||
.dir
|
||||
.join("target")
|
||||
.join(redoxer::target())
|
||||
.join("stage.pkgar"),
|
||||
@ -194,7 +191,7 @@ pub fn build(
|
||||
}
|
||||
|
||||
if stage_dir.exists() && !check_source {
|
||||
let auto_deps = build_auto_deps(target_dir, &stage_dir, dep_pkgars, logger)?;
|
||||
let auto_deps = build_auto_deps(recipe, target_dir, &stage_dir, dep_pkgars, logger)?;
|
||||
return Ok((stage_dir, auto_deps));
|
||||
}
|
||||
|
||||
@ -370,16 +367,17 @@ pub fn build(
|
||||
rename(&stage_dir_tmp, &stage_dir)?;
|
||||
}
|
||||
|
||||
let auto_deps = build_auto_deps(target_dir, &stage_dir, dep_pkgars, logger)?;
|
||||
let auto_deps = build_auto_deps(recipe, target_dir, &stage_dir, dep_pkgars, logger)?;
|
||||
|
||||
Ok((stage_dir, auto_deps))
|
||||
}
|
||||
|
||||
/// Calculate automatic dependencies
|
||||
fn build_auto_deps(
|
||||
recipe: &Recipe,
|
||||
target_dir: &Path,
|
||||
stage_dir: &PathBuf,
|
||||
dep_pkgars: BTreeSet<(PackageName, PathBuf)>,
|
||||
mut dep_pkgars: BTreeSet<(PackageName, PathBuf)>,
|
||||
logger: &PtyOut,
|
||||
) -> Result<BTreeSet<PackageName>, String> {
|
||||
let auto_deps_path = target_dir.join("auto_deps.toml");
|
||||
@ -394,12 +392,14 @@ fn build_auto_deps(
|
||||
toml::from_str(&toml_content).map_err(|_| "failed to deserialize cached auto_deps")?;
|
||||
wrapper.packages
|
||||
} else {
|
||||
let mut packages1 = auto_deps_from_dynamic_linking(stage_dir, &dep_pkgars, logger);
|
||||
let packages2 =
|
||||
auto_deps_from_static_package_deps(&dep_pkgars, &packages1).unwrap_or_default();
|
||||
packages1.extend(packages2);
|
||||
let mut dynamic_deps = auto_deps_from_dynamic_linking(stage_dir, &dep_pkgars, logger);
|
||||
dep_pkgars.retain(|x| recipe.build.dependencies.contains(&x.0));
|
||||
let package_deps =
|
||||
auto_deps_from_static_package_deps(&dep_pkgars, &dynamic_deps).unwrap_or_default();
|
||||
dynamic_deps.extend(package_deps);
|
||||
|
||||
let wrapper = AutoDeps {
|
||||
packages: packages1,
|
||||
packages: dynamic_deps,
|
||||
};
|
||||
serialize_and_write(&auto_deps_path, &wrapper)?;
|
||||
wrapper.packages
|
||||
|
||||
@ -20,10 +20,9 @@ macro_rules! log_to_pty {
|
||||
($logger:expr, $($arg:tt)+) => {
|
||||
if $logger.is_some() {
|
||||
use std::io::Write;
|
||||
let _ = $logger.as_ref().unwrap().1.try_clone().unwrap().write(
|
||||
format!($($arg)+)
|
||||
.as_bytes(),
|
||||
);
|
||||
let mut logfd = $logger.as_ref().unwrap().1.try_clone().unwrap();
|
||||
let _ = logfd.write(format!($($arg)+).as_bytes());
|
||||
let _ = logfd.write(&[b'\n']);
|
||||
} else {
|
||||
eprintln!($($arg)+);
|
||||
}
|
||||
|
||||
107
src/recipe.rs
107
src/recipe.rs
@ -140,6 +140,8 @@ pub struct BuildRecipe {
|
||||
pub kind: BuildKind,
|
||||
#[serde(default)]
|
||||
pub dependencies: Vec<PackageName>,
|
||||
#[serde(default, rename = "dev-dependencies")]
|
||||
pub dev_dependencies: Vec<PackageName>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Deserialize, PartialEq, Serialize)]
|
||||
@ -163,6 +165,28 @@ pub struct Recipe {
|
||||
pub package: PackageRecipe,
|
||||
}
|
||||
|
||||
impl BuildRecipe {
|
||||
pub fn new(kind: BuildKind) -> Self {
|
||||
let mut build = Self::default();
|
||||
build.kind = kind;
|
||||
build
|
||||
}
|
||||
|
||||
pub fn set_as_remote(&mut self) {
|
||||
self.kind = BuildKind::Remote;
|
||||
self.dev_dependencies = Vec::new();
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct CookRecipe {
|
||||
pub name: PackageName,
|
||||
pub dir: PathBuf,
|
||||
pub recipe: Recipe,
|
||||
/// If false, it's listed on install config
|
||||
pub is_deps: bool,
|
||||
}
|
||||
|
||||
impl Recipe {
|
||||
pub fn new(file: &PathBuf) -> Result<Recipe, PackageError> {
|
||||
if !file.is_file() {
|
||||
@ -175,14 +199,6 @@ impl Recipe {
|
||||
Ok(recipe)
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct CookRecipe {
|
||||
pub name: PackageName,
|
||||
pub dir: PathBuf,
|
||||
pub recipe: Recipe,
|
||||
/// If false, it's listed on install config
|
||||
pub is_deps: bool,
|
||||
}
|
||||
|
||||
impl CookRecipe {
|
||||
pub fn new(name: PackageName, dir: PathBuf, recipe: Recipe) -> Result<Self, PackageError> {
|
||||
@ -220,6 +236,7 @@ impl CookRecipe {
|
||||
pub fn new_recursive(
|
||||
names: &[PackageName],
|
||||
recurse_build_deps: bool,
|
||||
recurse_dev_build_deps: bool,
|
||||
recurse_package_deps: bool,
|
||||
collect_build_deps: bool,
|
||||
collect_package_deps: bool,
|
||||
@ -238,6 +255,30 @@ impl CookRecipe {
|
||||
let dependencies = Self::new_recursive(
|
||||
&recipe.recipe.build.dependencies,
|
||||
recurse_build_deps,
|
||||
recurse_dev_build_deps,
|
||||
recurse_package_deps,
|
||||
collect_build_deps,
|
||||
collect_package_deps,
|
||||
collect_build_deps,
|
||||
recursion - 1,
|
||||
)
|
||||
.map_err(|mut err| {
|
||||
err.append_recursion(name);
|
||||
err
|
||||
})?;
|
||||
|
||||
for dependency in dependencies {
|
||||
if !recipes.contains(&dependency) {
|
||||
recipes.push(dependency);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if recurse_dev_build_deps {
|
||||
let dependencies = Self::new_recursive(
|
||||
&recipe.recipe.build.dev_dependencies,
|
||||
recurse_build_deps,
|
||||
recurse_dev_build_deps,
|
||||
recurse_package_deps,
|
||||
collect_build_deps,
|
||||
collect_package_deps,
|
||||
@ -260,6 +301,7 @@ impl CookRecipe {
|
||||
let dependencies = Self::new_recursive(
|
||||
&recipe.recipe.package.dependencies,
|
||||
recurse_build_deps,
|
||||
recurse_dev_build_deps,
|
||||
recurse_package_deps,
|
||||
collect_build_deps,
|
||||
collect_package_deps,
|
||||
@ -288,9 +330,19 @@ impl CookRecipe {
|
||||
|
||||
pub fn get_build_deps_recursive(
|
||||
names: &[PackageName],
|
||||
include_dev: bool,
|
||||
mark_is_deps: bool,
|
||||
) -> Result<Vec<Self>, PackageError> {
|
||||
let mut packages = Self::new_recursive(names, true, false, true, false, true, WALK_DEPTH)?;
|
||||
let mut packages = Self::new_recursive(
|
||||
names,
|
||||
true,
|
||||
include_dev,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
WALK_DEPTH,
|
||||
)?;
|
||||
|
||||
if mark_is_deps {
|
||||
for package in packages.iter_mut() {
|
||||
@ -306,8 +358,16 @@ impl CookRecipe {
|
||||
include_names: bool,
|
||||
) -> Result<Vec<PackageName>, PackageError> {
|
||||
// recurse_build_deps == true here as libraries (build deps) can have runtime files (package deps)
|
||||
let packages =
|
||||
Self::new_recursive(names, true, true, false, true, include_names, WALK_DEPTH)?;
|
||||
let packages = Self::new_recursive(
|
||||
names,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
include_names,
|
||||
WALK_DEPTH,
|
||||
)?;
|
||||
|
||||
Ok(packages.into_iter().map(|p| p.name).collect())
|
||||
}
|
||||
@ -351,13 +411,10 @@ mod tests {
|
||||
script: None,
|
||||
shallow_clone: None,
|
||||
}),
|
||||
build: BuildRecipe {
|
||||
kind: BuildKind::Cargo {
|
||||
package_path: None,
|
||||
cargoflags: String::new(),
|
||||
},
|
||||
dependencies: Vec::new(),
|
||||
},
|
||||
build: BuildRecipe::new(BuildKind::Cargo {
|
||||
package_path: None,
|
||||
cargoflags: String::new(),
|
||||
}),
|
||||
package: PackageRecipe::default(),
|
||||
}
|
||||
);
|
||||
@ -392,12 +449,9 @@ mod tests {
|
||||
patches: Vec::new(),
|
||||
script: None,
|
||||
}),
|
||||
build: BuildRecipe {
|
||||
kind: BuildKind::Custom {
|
||||
script: "make".to_string()
|
||||
},
|
||||
dependencies: Vec::new(),
|
||||
},
|
||||
build: BuildRecipe::new(BuildKind::Custom {
|
||||
script: "make".to_string()
|
||||
}),
|
||||
package: PackageRecipe::default(),
|
||||
}
|
||||
);
|
||||
@ -424,10 +478,7 @@ mod tests {
|
||||
recipe,
|
||||
Recipe {
|
||||
source: None,
|
||||
build: BuildRecipe {
|
||||
kind: BuildKind::None,
|
||||
dependencies: Vec::new(),
|
||||
},
|
||||
build: BuildRecipe::new(BuildKind::None),
|
||||
package: PackageRecipe {
|
||||
dependencies: vec![PackageName::new("gcc13").unwrap()],
|
||||
version: None,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user