From be227040f15ec4c4534024c0c0b96048e7588d92 Mon Sep 17 00:00:00 2001 From: Roman Stingler Date: Sat, 28 Dec 2024 12:08:01 +0100 Subject: [PATCH] add PostBuildCommand closes #1300 --- src/command_line.rs | 4 ++++ src/config.rs | 2 ++ src/install.rs | 31 ++++++++++++++++++++++--------- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/command_line.rs b/src/command_line.rs index d3d93d34..755689f5 100644 --- a/src/command_line.rs +++ b/src/command_line.rs @@ -366,6 +366,9 @@ impl Config { } Arg::Long("nosign") => self.sign = Sign::No, Arg::Long("nosigndb") => self.sign_db = Sign::No, + Arg::Long("post-build-command") => { + self.post_build_command = Some(value?.to_string()); + } Arg::Long(a) if !arg.is_pacman_arg() && !arg.is_pacman_global() => { bail!(tr!("unknown option --{}", a)) } @@ -448,6 +451,7 @@ fn takes_value(arg: Arg) -> TakesValue { Arg::Long("sign") => TakesValue::Optional, Arg::Long("signdb") => TakesValue::Optional, Arg::Long("mode") => TakesValue::Required, + Arg::Long("post-build-command") => TakesValue::Required, _ => TakesValue::No, } } diff --git a/src/config.rs b/src/config.rs index b4a2a629..e84721dc 100644 --- a/src/config.rs +++ b/src/config.rs @@ -471,6 +471,7 @@ pub struct Config { pub sign_db: Sign, pub pre_build_command: Option, + pub post_build_command: Option, #[default = "makepkg"] pub makepkg_bin: String, @@ -1023,6 +1024,7 @@ then initialise it with: "FileManagerFlags" => self.fm_flags.extend(split), "ChrootFlags" => self.chroot_flags.extend(split), "PreBuildCommand" => self.pre_build_command = Some(value), + "PostBuildCommand" => self.post_build_command = Some(value), _ => eprintln!( "{}", tr!("error: unknown option '{}' in section [bin]", key) diff --git a/src/install.rs b/src/install.rs index be601f28..4ff75d5d 100644 --- a/src/install.rs +++ b/src/install.rs @@ -613,7 +613,9 @@ impl Installer { let debug_paths = self.debug_paths(config, base, &pkgdests)?; self.add_pkg(config, base, repo, &pkgdests, &debug_paths)?; + post_build_command(config, dir, base.package_base(), &version)?; self.queue_install(base, &pkgdests, &debug_paths); + Ok((pkgdests, version)) } @@ -1257,7 +1259,6 @@ fn print_warnings(config: &Config, cache: &Cache, actions: Option<&Actions>) { if !config.mode.aur() && !config.mode.pkgbuild() { return; } - if config.args.has_arg("u", "sysupgrade") && config.mode.aur() { let (_, mut pkgs) = repo_aur_pkgs(config); pkgs.retain(|pkg| config.pkgbuild_repos.pkg(config, pkg.name()).is_none()); @@ -1539,15 +1540,27 @@ fn set_install_reason>(config: &Config, reason: &str, pkgs: &[S]) Ok(()) } +fn build_command(command: &str, dir: &Path, base: &str, version: &str) -> Result<()> { + let mut cmd = Command::new("sh"); + cmd.env("PKGBASE", base) + .env("VERSION", version) + .current_dir(dir) + .arg("-c") + .arg(command); + exec::command(&mut cmd)?; + Ok(()) +} + fn pre_build_command(config: &Config, dir: &Path, base: &str, version: &str) -> Result<()> { - if let Some(ref pb_cmd) = config.pre_build_command { - let mut cmd = Command::new("sh"); - cmd.env("PKGBASE", base) - .env("VERSION", version) - .current_dir(dir) - .arg("-c") - .arg(pb_cmd); - exec::command(&mut cmd)?; + if let Some(ref cmd) = config.pre_build_command { + build_command(cmd, dir, base, version)?; + } + Ok(()) +} + +fn post_build_command(config: &Config, dir: &Path, base: &str, version: &str) -> Result<()> { + if let Some(ref cmd) = config.post_build_command { + build_command(cmd, dir, base, version)?; } Ok(()) }