Skip to content

Commit

Permalink
add PostBuildCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Stingler committed Dec 17, 2024
1 parent c15f83c commit a328a8f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/command_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,12 @@ impl Config {
}
Arg::Long("nosign") => self.sign = Sign::No,
Arg::Long("nosigndb") => self.sign_db = Sign::No,
Arg::Long("post-build-command") => match value {
Ok(v) => {
self.post_build_command = Some(v.to_string());
}
Err(_) => bail!(tr!("argument --post-build-command requires a value")),
},
Arg::Long(a) if !arg.is_pacman_arg() && !arg.is_pacman_global() => {
bail!(tr!("unknown option --{}", a))
}
Expand Down Expand Up @@ -448,6 +454,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,
}
}
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ pub struct Config {
pub sign_db: Sign,

pub pre_build_command: Option<String>,
pub post_build_command: Option<String>,

#[default = "makepkg"]
pub makepkg_bin: String,
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 16 additions & 1 deletion src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,9 @@ impl Installer {

self.add_pkg(config, base, repo, &pkgdests, &debug_paths)?;
self.queue_install(base, &pkgdests, &debug_paths);

post_build_command(config, dir, base.package_base(), &version)?;

Ok((pkgdests, version))
}

Expand Down Expand Up @@ -1260,7 +1263,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());
Expand Down Expand Up @@ -1558,6 +1560,19 @@ fn pre_build_command(config: &Config, dir: &Path, base: &str, version: &str) ->
Ok(())
}

fn post_build_command(config: &Config, dir: &Path, base: &str, version: &str) -> Result<()> {
if let Some(ref pb_cmd) = config.post_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)?;
}
Ok(())
}

fn file_manager(
config: &Config,
fetch: &aur_fetch::Fetch,
Expand Down

0 comments on commit a328a8f

Please sign in to comment.