Skip to content

Commit

Permalink
maint. updates rpm crate to 0.13
Browse files Browse the repository at this point in the history
feat. add additional scriptlet options
feat. add config for scriptlet flags/interpreter args
  • Loading branch information
juliusl committed Dec 12, 2023
1 parent 70ca782 commit b988098
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 21 deletions.
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ edition = "2021"

[dependencies]
glob = "0.3.0"
rpm = { version = "0.12.1", default-features = false }
rpm = { version = "0.13.1", default-features = false }
toml = "0.7"
cargo_toml = "0.15"
clap = { version = "4.3", features = ["derive"] }
Expand All @@ -29,3 +29,6 @@ assets = [
{ source = "LICENSE", dest = "/usr/share/doc/cargo-generate-rpm/LICENSE", doc = true, mode = "0644" },
{ source = "README.md", dest = "/usr/share/doc/cargo-generate-rpm/README.md", doc = true, mode = "0644" }
]

[patch.crates-io]
rpm = { git = "https://github.com/rpm-rs/rpm.git" }
21 changes: 21 additions & 0 deletions src/config/metadata.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::error::{ConfigError, FileAnnotatedError};
use crate::{Error, ExtraMetadataSource};
use cargo_toml::Manifest;
use rpm::Scriptlet;
use std::fs;
use std::path::PathBuf;
use toml::value::Table;
Expand Down Expand Up @@ -305,6 +306,26 @@ impl<'a> CompoundMetadataConfig<'a> {
}
Ok(None)
}

/// Returns a configured scriptlet,
///
pub(super) fn get_scriptlet(&self, name: &str, content: impl Into<String>) -> Result<Option<Scriptlet>, ConfigError> {
let flags_key = format!("{name}_flags");
let prog_key = format!("{name}_prog");

let mut scriptlet = Scriptlet::new(content);

if let Some(flags) = self.get_i64(flags_key.as_str())? {
scriptlet = scriptlet.flags(rpm::ScriptletFlags::from_bits_retain(flags as u32));
}

if let Some(prog) = self.get_array(prog_key.as_str())? {
let prog = prog.iter().filter_map(|p| p.as_str());
scriptlet = scriptlet.prog(prog.collect());
}

Ok(Some(scriptlet))
}
}

impl<'a> TomlValueHelper<'a> for CompoundMetadataConfig<'a> {
Expand Down
99 changes: 79 additions & 20 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,32 +186,91 @@ impl Config {
}

if let Some(pre_install_script) = metadata.get_str("pre_install_script")? {
builder = builder.pre_install_script(&load_script_if_path(
pre_install_script,
parent,
cfg.build_target,
)?);
let scriptlet = metadata.get_scriptlet(
"pre_install_script",
load_script_if_path(pre_install_script, parent, cfg.build_target)?,
)?;

if let Some(scriptlet) = scriptlet {
builder = builder.pre_install_script(scriptlet);
}
}

if let Some(pre_uninstall_script) = metadata.get_str("pre_uninstall_script")? {
builder = builder.pre_uninstall_script(&load_script_if_path(
pre_uninstall_script,
parent,
cfg.build_target,
)?);
let scriptlet = metadata.get_scriptlet(
"pre_uninstall_script",
load_script_if_path(pre_uninstall_script, parent, cfg.build_target)?,
)?;

if let Some(scriptlet) = scriptlet {
builder = builder.pre_uninstall_script(scriptlet);
}
}

if let Some(post_install_script) = metadata.get_str("post_install_script")? {
builder = builder.post_install_script(&load_script_if_path(
post_install_script,
parent,
cfg.build_target,
)?);
let scriptlet = metadata.get_scriptlet(
"post_install_script",
load_script_if_path(post_install_script, parent, cfg.build_target)?,
)?;

if let Some(scriptlet) = scriptlet {
builder = builder.post_install_script(scriptlet);
}
}

if let Some(post_uninstall_script) = metadata.get_str("post_uninstall_script")? {
builder = builder.post_uninstall_script(&load_script_if_path(
post_uninstall_script,
parent,
cfg.build_target,
)?);
let scriptlet = metadata.get_scriptlet(
"post_uninstall_script",
load_script_if_path(post_uninstall_script, parent, cfg.build_target)?,
)?;

if let Some(scriptlet) = scriptlet {
builder = builder.post_uninstall_script(scriptlet);
}
}

if let Some(pre_trans_script) = metadata.get_str("pre_trans_script")? {
let scriptlet = metadata.get_scriptlet(
"pre_trans_script",
load_script_if_path(pre_trans_script, parent, cfg.build_target)?,
)?;

if let Some(scriptlet) = scriptlet {
builder = builder.pre_trans_script(scriptlet);
}
}

if let Some(post_trans_script) = metadata.get_str("post_trans_script")? {
let scriptlet = metadata.get_scriptlet(
"post_trans_script",
load_script_if_path(post_trans_script, parent, cfg.build_target)?,
)?;

if let Some(scriptlet) = scriptlet {
builder = builder.post_trans_script(scriptlet);
}
}

if let Some(pre_untrans_script) = metadata.get_str("pre_untrans_script")? {
let scriptlet = metadata.get_scriptlet(
"pre_untrans_script",
load_script_if_path(pre_untrans_script, parent, cfg.build_target)?,
)?;

if let Some(scriptlet) = scriptlet {
builder = builder.pre_untrans_script(scriptlet);
}
}

if let Some(post_untrans_script) = metadata.get_str("post_untrans_script")? {
let scriptlet = metadata.get_scriptlet(
"post_untrans_script",
load_script_if_path(post_untrans_script, parent, cfg.build_target)?,
)?;

if let Some(scriptlet) = scriptlet {
builder = builder.post_untrans_script(scriptlet);
}
}

if let Some(url) = match (
Expand Down

0 comments on commit b988098

Please sign in to comment.