Skip to content

Commit 1b3aaed

Browse files
authored
Merge pull request #228 from kpcyrd/dbgsym-release-with-different-source
Allow SyncRelease to set different source= value
2 parents 3b5dd8e + 3313fde commit 1b3aaed

6 files changed

Lines changed: 357 additions & 78 deletions

File tree

contrib/confs/rebuilderd-sync.conf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ releases = ["sid"]
5656
pkgs = ["anarchism", "binutils-arm-none-eabi", "libglib2.0-bin", "libglib2.0-dev", "sniffglue", "librust-sniffglue-dev", "dfrs", "librust-dfrs-dev"]
5757
source = "http://deb.debian.org/debian"
5858

59+
# example with debug packages from a different source
60+
[profile."debian-telegram"]
61+
distro = "debian"
62+
components = ["main"]
63+
architectures = ["amd64"]
64+
releases = [
65+
"trixie-backports",
66+
{ name = "trixie-backports-debug", source = "http://deb.debian.org/debian-debug" }
67+
]
68+
pkgs = ["telegram-desktop*"]
69+
source = "http://deb.debian.org/debian"
70+
5971
[profile."tails"]
6072
distro = "tails"
6173
architectures = ["amd64"]

tools/src/args.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::config::SyncRelease;
12
use clap::{ArgAction, CommandFactory, Parser};
23
use clap_complete::Shell;
34
use glob::Pattern;
@@ -88,7 +89,7 @@ pub struct PkgsSync {
8889
pub maintainers: Vec<String>,
8990

9091
#[arg(long = "release")]
91-
pub releases: Vec<String>,
92+
pub releases: Vec<SyncRelease>,
9293

9394
#[arg(long = "pkg")]
9495
pub pkgs: Vec<Pattern>,

tools/src/config.rs

Lines changed: 130 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use rebuilderd_common::errors::*;
22
use serde::Deserialize;
33
use std::collections::HashMap;
4+
use std::convert::Infallible;
45
use std::fs;
56
use std::path::Path;
7+
use std::str::FromStr;
68

7-
#[derive(Debug, Deserialize)]
9+
#[derive(Debug, Deserialize, PartialEq)]
810
pub struct SyncConfigFile {
911
#[serde(rename = "profile")]
1012
pub profiles: HashMap<String, SyncProfile>,
@@ -18,7 +20,7 @@ impl SyncConfigFile {
1820
}
1921
}
2022

21-
#[derive(Debug, Deserialize)]
23+
#[derive(Debug, Deserialize, PartialEq)]
2224
pub struct SyncProfile {
2325
pub distro: String,
2426

@@ -31,7 +33,7 @@ pub struct SyncProfile {
3133
pub components: Vec<String>,
3234

3335
#[serde(default)]
34-
pub releases: Vec<String>,
36+
pub releases: Vec<SyncRelease>,
3537

3638
#[deprecated]
3739
pub architecture: Option<String>,
@@ -50,3 +52,128 @@ pub struct SyncProfile {
5052
#[serde(default)]
5153
pub excludes: Vec<String>,
5254
}
55+
56+
#[derive(Debug, Deserialize, Clone, PartialEq)]
57+
#[serde(untagged)]
58+
pub enum SyncRelease {
59+
Release(String),
60+
ReleaseWithSource {
61+
name: String,
62+
source: Option<String>,
63+
},
64+
}
65+
66+
impl SyncRelease {
67+
pub fn new<I: Into<String>>(release: I) -> SyncRelease {
68+
SyncRelease::Release(release.into())
69+
}
70+
71+
pub fn source<'a>(&'a self, default_source: &'a str) -> &'a str {
72+
match self {
73+
SyncRelease::Release(_release) => default_source,
74+
SyncRelease::ReleaseWithSource { source, .. } => {
75+
source.as_deref().unwrap_or(default_source)
76+
}
77+
}
78+
}
79+
80+
pub fn name(&self) -> &str {
81+
match self {
82+
SyncRelease::Release(release) => release,
83+
SyncRelease::ReleaseWithSource { name, .. } => name,
84+
}
85+
}
86+
}
87+
88+
impl FromStr for SyncRelease {
89+
type Err = Infallible;
90+
91+
fn from_str(s: &str) -> Result<Self, Self::Err> {
92+
Ok(SyncRelease::Release(s.to_string()))
93+
}
94+
}
95+
96+
#[cfg(test)]
97+
mod tests {
98+
use super::*;
99+
100+
#[test]
101+
fn test_parse_sync_profile() {
102+
let config = r#"
103+
[profile."debian-telegram"]
104+
distro = "debian"
105+
components = ["main"]
106+
architectures = ["amd64"]
107+
releases = ["trixie-backports"]
108+
pkgs = ["telegram-desktop*"]
109+
source = "http://deb.debian.org/debian"
110+
"#;
111+
let config = toml::from_str::<SyncConfigFile>(config).unwrap();
112+
assert_eq!(
113+
config,
114+
SyncConfigFile {
115+
profiles: [(
116+
"debian-telegram".to_string(),
117+
SyncProfile {
118+
distro: "debian".to_string(),
119+
sync_method: None,
120+
suite: None,
121+
components: vec!["main".to_string()],
122+
releases: vec![SyncRelease::new("trixie-backports")],
123+
architecture: None,
124+
architectures: vec!["amd64".to_string()],
125+
source: "http://deb.debian.org/debian".to_string(),
126+
maintainers: vec![],
127+
pkgs: vec!["telegram-desktop*".to_string()],
128+
excludes: vec![],
129+
}
130+
)]
131+
.into_iter()
132+
.collect()
133+
}
134+
);
135+
}
136+
137+
#[test]
138+
fn test_parse_sync_profile_multiple_sources() {
139+
let config = r#"
140+
[profile."debian-telegram"]
141+
distro = "debian"
142+
components = ["main"]
143+
architectures = ["amd64"]
144+
releases = ["trixie-backports", {name = "trixie-backports-debug", source = "http://deb.debian.org/debian-debug"}]
145+
pkgs = ["telegram-desktop*"]
146+
source = "http://deb.debian.org/debian"
147+
"#;
148+
let config = toml::from_str::<SyncConfigFile>(config).unwrap();
149+
assert_eq!(
150+
config,
151+
SyncConfigFile {
152+
profiles: [(
153+
"debian-telegram".to_string(),
154+
SyncProfile {
155+
distro: "debian".to_string(),
156+
sync_method: None,
157+
suite: None,
158+
components: vec!["main".to_string()],
159+
releases: vec![
160+
SyncRelease::new("trixie-backports"),
161+
SyncRelease::ReleaseWithSource {
162+
name: "trixie-backports-debug".to_string(),
163+
source: Some("http://deb.debian.org/debian-debug".to_string()),
164+
}
165+
],
166+
architecture: None,
167+
architectures: vec!["amd64".to_string()],
168+
source: "http://deb.debian.org/debian".to_string(),
169+
maintainers: vec![],
170+
pkgs: vec!["telegram-desktop*".to_string()],
171+
excludes: vec![],
172+
}
173+
)]
174+
.into_iter()
175+
.collect()
176+
}
177+
);
178+
}
179+
}

0 commit comments

Comments
 (0)