deb: first implementation
This commit is contained in:
@@ -123,7 +123,7 @@ fn increment_suffix(version: &str, suffix: &str) -> String {
|
||||
/*
|
||||
* Parse a changelog file first entry header, to obtain (package, version, series)
|
||||
*/
|
||||
fn parse_changelog_header(
|
||||
pub fn parse_changelog_header(
|
||||
path: &Path,
|
||||
) -> Result<(String, String, String), Box<dyn std::error::Error>> {
|
||||
let file = File::open(path)?;
|
||||
|
||||
29
src/deb.rs
Normal file
29
src/deb.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use std::error::Error;
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
pub fn build_binary_package(cwd: Option<&Path>) -> Result<(), Box<dyn Error>> {
|
||||
let cwd = cwd.unwrap_or_else(|| Path::new("."));
|
||||
|
||||
// Parse changelog to get package name and version
|
||||
let changelog_path = cwd.join("debian/changelog");
|
||||
let (package, version, _series) = crate::changelog::parse_changelog_header(&changelog_path)?;
|
||||
|
||||
// Construct dsc file name
|
||||
let parent = cwd.parent().ok_or("Cannot find parent directory")?;
|
||||
let dsc_name = format!("{}_{}.dsc", package, version);
|
||||
let dsc_path = parent.join(&dsc_name);
|
||||
if !dsc_path.exists() {
|
||||
return Err(format!("Could not find .dsc file at {}", dsc_path.display()).into());
|
||||
}
|
||||
|
||||
println!("Building {} using sbuild...", dsc_path.display());
|
||||
|
||||
let status = Command::new("sbuild").arg(dsc_path).status()?;
|
||||
|
||||
if !status.success() {
|
||||
return Err(format!("sbuild failed with status: {}", status).into());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
pub mod build;
|
||||
pub mod changelog;
|
||||
pub mod deb;
|
||||
pub mod package_info;
|
||||
pub mod pull;
|
||||
|
||||
|
||||
11
src/main.rs
11
src/main.rs
@@ -8,8 +8,7 @@ extern crate flate2;
|
||||
|
||||
use pkh::pull::pull;
|
||||
|
||||
mod changelog;
|
||||
use changelog::generate_entry;
|
||||
use pkh::changelog::generate_entry;
|
||||
|
||||
use indicatif_log_bridge::LogWrapper;
|
||||
use log::{error, info};
|
||||
@@ -50,6 +49,7 @@ fn main() {
|
||||
.arg(arg!(-v --version <version> "Target version").required(false)),
|
||||
)
|
||||
.subcommand(Command::new("build").about("Build the source package"))
|
||||
.subcommand(Command::new("deb").about("Build the binary package"))
|
||||
.get_matches();
|
||||
|
||||
match matches.subcommand() {
|
||||
@@ -109,6 +109,13 @@ fn main() {
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
Some(("deb", _sub_matches)) => {
|
||||
let cwd = std::env::current_dir().unwrap();
|
||||
if let Err(e) = pkh::deb::build_binary_package(Some(&cwd)) {
|
||||
error!("{}", e);
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
_ => unreachable!("Exhausted list of subcommands and subcommand_required prevents `None`"),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user