Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/command_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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,
}
}
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
31 changes: 22 additions & 9 deletions src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -1539,15 +1540,27 @@ fn set_install_reason<S: AsRef<str>>(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(())
}
Expand Down
Loading