deb: cross-compilation, ephemeral contexts, local builds
All checks were successful
CI / build (push) Successful in 7m18s

Multiple changes:
- New contexts (schroot, unshare)
- Cross-building quirks, with ephemeral contexts and repositories management
- Contexts with parents, global context manager, better lifetime handling
- Local building of binary packages
- Pull: pulling dsc files by default
- Many small bugfixes and changes

Co-authored-by: Valentin Haudiquet <valentin.haudiquet@canonical.com>
Co-committed-by: Valentin Haudiquet <valentin.haudiquet@canonical.com>
This commit was merged in pull request #1.
This commit is contained in:
2025-12-25 17:10:44 +00:00
committed by Valentin Haudiquet
parent 88313b0c51
commit 1538e9ee19
19 changed files with 1784 additions and 301 deletions

View File

@@ -3,6 +3,7 @@ use std::io::Write;
extern crate clap;
use clap::{Command, arg, command};
use pkh::context::ContextConfig;
extern crate flate2;
@@ -53,7 +54,11 @@ fn main() {
Command::new("deb")
.about("Build the binary package")
.arg(arg!(-s --series <series> "Target distribution series").required(false))
.arg(arg!(-a --arch <arch> "Target architecture").required(false)),
.arg(arg!(-a --arch <arch> "Target architecture").required(false))
.arg(arg!(--cross "Cross-compile for target architecture (instead of qemu-binfmt)")
.long_help("Cross-compile for target architecture (instead of using qemu-binfmt)\nNote that most packages cannot be cross-compiled").required(false))
.arg(arg!(--mode <mode> "Change build mode [sbuild, local]").required(false)
.long_help("Change build mode [sbuild, local]\nDefault will chose depending on other parameters, don't provide if unsure")),
)
.subcommand(
Command::new("context")
@@ -71,7 +76,10 @@ fn main() {
.about("Remove a context")
.arg(arg!(<name> "Context name"))
)
.subcommand(Command::new("ls").about("List contexts"))
.subcommand(
Command::new("ls")
.about("List contexts")
)
.subcommand(Command::new("show").about("Show current context"))
.subcommand(
Command::new("use")
@@ -142,22 +150,23 @@ fn main() {
let cwd = std::env::current_dir().unwrap();
let series = sub_matches.get_one::<String>("series").map(|s| s.as_str());
let arch = sub_matches.get_one::<String>("arch").map(|s| s.as_str());
let cross = sub_matches.get_one::<bool>("cross").unwrap_or(&false);
let mode: Option<&str> = sub_matches.get_one::<String>("mode").map(|s| s.as_str());
let mode: Option<pkh::deb::BuildMode> = match mode {
Some("sbuild") => Some(pkh::deb::BuildMode::Sbuild),
Some("local") => Some(pkh::deb::BuildMode::Local),
_ => None,
};
if let Err(e) = pkh::deb::build_binary_package(arch, series, Some(cwd.as_path())) {
if let Err(e) =
pkh::deb::build_binary_package(arch, series, Some(cwd.as_path()), *cross, mode)
{
error!("{}", e);
std::process::exit(1);
}
}
Some(("context", sub_matches)) => {
use pkh::context::{Context, ContextManager};
let mut mgr = match ContextManager::new() {
Ok(mgr) => mgr,
Err(e) => {
error!("Failed to initialize context manager: {}", e);
std::process::exit(1);
}
};
let mgr = pkh::context::manager();
match sub_matches.subcommand() {
Some(("create", args)) => {
@@ -168,7 +177,7 @@ fn main() {
.unwrap_or("local");
let context = match type_str {
"local" => Context::Local,
"local" => ContextConfig::Local,
"ssh" => {
let endpoint = args
.get_one::<String>("endpoint")
@@ -191,7 +200,7 @@ fn main() {
})
});
Context::Ssh { host, user, port }
ContextConfig::Ssh { host, user, port }
}
_ => {
error!("Unknown context type: {}", type_str);
@@ -217,20 +226,14 @@ fn main() {
let contexts = mgr.list_contexts();
let current = mgr.current_name();
for ctx in contexts {
if Some(&ctx) == current.as_ref() {
if ctx == current {
println!("* {}", ctx);
} else {
println!(" {}", ctx);
}
}
}
Some(("show", _)) => {
if let Some(name) = mgr.current_name() {
println!("{}", name);
} else {
println!("No context set (defaulting to local)");
}
}
Some(("show", _)) => {}
Some(("use", args)) => {
let name = args.get_one::<String>("name").unwrap();
if let Err(e) = mgr.set_current(name) {