Skip to content

Commit f9cd5a5

Browse files
committed
Calculate package dependencies for publish again
1 parent cc0947d commit f9cd5a5

File tree

5 files changed

+110
-16
lines changed

5 files changed

+110
-16
lines changed

repo.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ mkdir -p "$REPO"
9393

9494
declare -A APPSTREAM_SOURCES
9595

96+
# Currently, we only support runtime dependencies for recipes in the new TOML
97+
# format. Runtime dependencies include both `[package.dependencies]` and
98+
# [`package.shared_deps`].
99+
#
100+
# The following adds the package dependencies of the recipes to the repo as
101+
# well.
102+
#
103+
# TODO(?): All of this script can be moved into `cook.rs`.
104+
recipes="$recipes $(target/release/pkg_deps $toml_recipes)"
105+
96106
for recipe in $recipes
97107
do
98108
recipe_path=`target/release/find_recipe $recipe`
@@ -107,9 +117,6 @@ do
107117
cp -v "${COOKBOOK_STAGE}.toml" "$REPO/$recipe.toml"
108118
fi
109119

110-
#TODO: PUBLISH DEPENDENCIES (RECURSIVELY)
111-
#grep '^depends = ' "$REPO/$recipe.toml | cut -d '[' -f2 | cut -d ']' -f1 | tr -d ','
112-
113120
if [ -e "${COOKBOOK_STAGE}/usr/share/metainfo" ]
114121
then
115122
APPSTREAM_SOURCES["$recipe"]="${COOKBOOK_STAGE}"

src/bin/cook.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use cookbook::blake3::blake3_progress;
2+
use cookbook::package::StageToml;
23
use cookbook::recipe::{BuildKind, CookRecipe, PackageRecipe, Recipe, SourceRecipe};
34
use cookbook::recipe_find::recipe_find;
45
use std::{
@@ -552,11 +553,7 @@ fn auto_deps(stage_dir: &Path, dep_pkgars: &BTreeSet<(String, PathBuf)>) -> BTre
552553

553554
let mut missing = needed.clone();
554555
// relibc and friends will always be installed
555-
for preinstalled in &[
556-
"libc.so.6",
557-
"libgcc_s.so.1",
558-
"libstdc++.so.6",
559-
] {
556+
for preinstalled in &["libc.so.6", "libgcc_s.so.1", "libstdc++.so.6"] {
560557
missing.remove(*preinstalled);
561558
}
562559

@@ -979,14 +976,6 @@ fn package(
979976
)
980977
.map_err(|err| format!("failed to create pkgar archive: {:?}", err))?;
981978

982-
//TODO: share struct with pkgutils?
983-
#[derive(serde::Serialize)]
984-
struct StageToml {
985-
name: String,
986-
version: String,
987-
target: String,
988-
depends: Vec<String>,
989-
}
990979
let mut depends = package.dependencies.clone();
991980
for dep in auto_deps.iter() {
992981
if !depends.contains(dep) {

src/bin/pkg_deps.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use cookbook::package::StageToml;
2+
use std::{env::args, process::ExitCode};
3+
4+
/// Same as `cookbook/src/bin/cook.rs`.
5+
const DEP_DEPTH: usize = 16;
6+
7+
fn usage() {
8+
eprintln!("Usage: pkg_deps [package1 package2 ...]");
9+
}
10+
11+
fn main() -> ExitCode {
12+
let names = args().skip(1).collect::<Vec<String>>();
13+
let packages = StageToml::new_recursive(&names, DEP_DEPTH).expect("package not found");
14+
15+
for package in packages {
16+
println!("{}", package.name);
17+
}
18+
19+
ExitCode::SUCCESS
20+
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub mod blake3;
2+
pub mod package;
23
pub mod recipe;
34
pub mod recipe_find;
45

src/package.rs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
use std::{env, fs, path::Path};
2+
3+
use crate::recipe_find::recipe_find;
4+
5+
//TODO: share struct with pkgutils?
6+
#[derive(PartialEq, serde::Deserialize, serde::Serialize)]
7+
pub struct StageToml {
8+
pub name: String,
9+
pub version: String,
10+
pub target: String,
11+
pub depends: Vec<String>,
12+
}
13+
14+
impl StageToml {
15+
pub fn new(name: String) -> Result<Self, String> {
16+
//TODO: sanitize recipe name?
17+
let dir = recipe_find(&name, Path::new("recipes"))?;
18+
if dir.is_none() {
19+
return Err(format!("failed to find recipe directory '{}'", name));
20+
}
21+
let dir = dir.unwrap();
22+
let target =
23+
env::var("TARGET").map_err(|err| format!("failed to read TARGET: {:?}", err))?;
24+
25+
let file = dir.join("target").join(target).join("stage.toml");
26+
if !file.is_file() {
27+
return Err(format!("failed to find package file '{}'", file.display()));
28+
}
29+
30+
let toml = fs::read_to_string(&file).map_err(|err| {
31+
format!(
32+
"failed to read package file '{}': {}\n{:#?}",
33+
file.display(),
34+
err,
35+
err
36+
)
37+
})?;
38+
39+
toml::from_str(&toml).map_err(|err| {
40+
format!(
41+
"failed to parse package file '{}': {}\n{:#?}",
42+
file.display(),
43+
err,
44+
err
45+
)
46+
})
47+
}
48+
49+
pub fn new_recursive(names: &[String], recursion: usize) -> Result<Vec<Self>, String> {
50+
if recursion == 0 {
51+
return Err(format!(
52+
"recursion limit while processing build dependencies: {:#?}",
53+
names
54+
));
55+
}
56+
57+
let mut packages = Vec::new();
58+
for name in names {
59+
let package = Self::new(name.clone())?;
60+
61+
let dependencies = Self::new_recursive(&package.depends, recursion - 1)
62+
.map_err(|err| format!("{}: failed on loading dependencies:\n{}", name, err))?;
63+
64+
for dependency in dependencies {
65+
if !packages.contains(&dependency) {
66+
packages.push(dependency);
67+
}
68+
}
69+
70+
if !packages.contains(&package) {
71+
packages.push(package);
72+
}
73+
}
74+
75+
Ok(packages)
76+
}
77+
}

0 commit comments

Comments
 (0)