Skip to content

Commit

Permalink
feat: add rpm target flag
Browse files Browse the repository at this point in the history
  • Loading branch information
lleyton committed Nov 14, 2024
1 parent 6935b1a commit 9913926
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub async fn build_rpm(
debug!("No repodata found, skipping");
}

opts.set_target(rpmb_opts.rpm_target.clone());

for repo in &rpmb_opts.extra_repos {
if opts.extra_repos.is_none() {
opts.extra_repos = Some(vec![repo.clone()]);
Expand Down
4 changes: 4 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ pub struct RpmOpts {
#[clap(short = 'D', long)]
pub rpm_macro: Vec<String>,

/// RPM: A target to pass to rpmbuild/mock, useful for cross compilation
#[clap(long)]
pub rpm_target: Option<String>,

/// RPM: Mock configuration
#[clap(long, short = 'c')]
pub mock_config: Option<String>,
Expand Down
37 changes: 36 additions & 1 deletion src/rpm_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub struct RPMOptions {
pub with: Vec<String>,
/// Without flags
pub without: Vec<String>,
/// Build target, used for cross-compile
pub target: Option<String>,
/// Path to sources
pub sources: PathBuf,
/// Output directory
Expand Down Expand Up @@ -52,6 +54,7 @@ impl RPMOptions {
mock_config,
with: Vec::new(),
without: Vec::new(),
target: None,
sources,
resultdir,
extra_repos: None,
Expand Down Expand Up @@ -95,6 +98,9 @@ impl RPMExtraOptions for RPMOptions {
fn macros_mut(&mut self) -> &mut BTreeMap<String, String> {
&mut self.macros
}
fn set_target(&mut self, target: Option<String>) {
self.target = target;
}
}

#[derive(ValueEnum, Debug, Clone, Copy)]
Expand Down Expand Up @@ -144,6 +150,7 @@ impl RPMBuilder {
options.macros.iter().for_each(|(k, v)| {
mock.def_macro(k, v);
});
mock.target(take(&mut options.target));
mock.with_flags_mut().extend(take(&mut options.with));
mock.without_flags_mut().extend(take(&mut options.without));
mock.extend_config_opts(take(&mut options.config_opts));
Expand All @@ -161,6 +168,7 @@ impl RPMBuilder {
rpmbuild.def_macro(k, v);
});

rpmbuild.set_target(take(&mut options.target));
rpmbuild.with_flags_mut().extend(take(&mut options.with));
rpmbuild.without_flags_mut().extend(take(&mut options.without));

Expand All @@ -186,6 +194,9 @@ pub trait RPMExtraOptions {
/// This is useful for advanced macro manipulation
fn macros_mut(&mut self) -> &mut BTreeMap<String, String>;

/// Set target, used for cross-compile
fn set_target(&mut self, target: Option<String>);

/// Adds a list of macros from an iterator
fn macros_iter<I>(&mut self, iter: I)
where
Expand Down Expand Up @@ -249,6 +260,7 @@ pub struct MockBackend {
scm_enable: bool,
scm_opts: Vec<String>,
plugin_opts: Vec<String>,
target: Option<String>,
}

impl RPMExtraOptions for MockBackend {
Expand All @@ -270,6 +282,9 @@ impl RPMExtraOptions for MockBackend {
fn macros_mut(&mut self) -> &mut BTreeMap<String, String> {
&mut self.macros
}
fn set_target(&mut self, target: Option<String>) {
self.target = target;
}
}

impl MockBackend {
Expand All @@ -287,6 +302,7 @@ impl MockBackend {
scm_enable: false,
scm_opts: Vec::new(),
plugin_opts: Vec::new(),
target: None,
}
}

Expand Down Expand Up @@ -321,6 +337,10 @@ impl MockBackend {
self.plugin_opts.extend(opts);
}

pub fn target(&mut self, target: Option<String>) {
self.target = target;
}

pub fn mock(&self) -> Command {
let mut cmd = Command::new("mock");

Expand All @@ -330,6 +350,10 @@ impl MockBackend {

// cmd.arg("--verbose");

if let Some(target) = &self.target {
cmd.arg("--target").arg(target);
}

self.extra_repos.iter().for_each(|repo| {
cmd.arg("-a").arg(repo);
});
Expand Down Expand Up @@ -457,6 +481,7 @@ pub struct RPMBuildBackend {
resultdir: PathBuf,
with: Vec<String>,
without: Vec<String>,
target: Option<String>,
macros: BTreeMap<String, String>,
}

Expand All @@ -479,11 +504,21 @@ impl RPMExtraOptions for RPMBuildBackend {
fn macros_mut(&mut self) -> &mut BTreeMap<String, String> {
&mut self.macros
}
fn set_target(&mut self, target: Option<String>) {
self.target = target;
}
}

impl RPMBuildBackend {
pub const fn new(sources: PathBuf, resultdir: PathBuf) -> Self {
Self { sources, resultdir, with: Vec::new(), without: Vec::new(), macros: BTreeMap::new() }
Self {
sources,
resultdir,
with: Vec::new(),
without: Vec::new(),
macros: BTreeMap::new(),
target: None,
}
}

pub fn rpmbuild(&self) -> Command {
Expand Down

0 comments on commit 9913926

Please sign in to comment.