Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: Add experimental build-from-manifest #5211

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
38 changes: 38 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ xmlrpc = "0.15.1"
termcolor = "1.4.1"
shlex = "1.3.0"

[dev-dependencies]
similar-asserts = "1.6.0"

[build-dependencies]
anyhow = "1.0"
system-deps = "7.0"
Expand Down
14 changes: 14 additions & 0 deletions rpmostree-cxxrs.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1780,6 +1780,7 @@ struct Treefile final : public ::rust::Opaque
::rust::String get_gpg_key () const noexcept;
::rust::String get_automatic_version_suffix () const noexcept;
bool get_container () const noexcept;
void assert_no_repovars () const;
bool get_machineid_compat () const noexcept;
::rust::Vec< ::rust::String> get_etc_group_members () const noexcept;
bool get_boot_location_is_modules () const noexcept;
Expand Down Expand Up @@ -2626,6 +2627,9 @@ extern "C"
bool
rpmostreecxx$cxxbridge1$Treefile$get_container (::rpmostreecxx::Treefile const &self) noexcept;

::rust::repr::PtrLen rpmostreecxx$cxxbridge1$Treefile$assert_no_repovars (
::rpmostreecxx::Treefile const &self) noexcept;

bool rpmostreecxx$cxxbridge1$Treefile$get_machineid_compat (
::rpmostreecxx::Treefile const &self) noexcept;

Expand Down Expand Up @@ -5188,6 +5192,16 @@ Treefile::get_container () const noexcept
return rpmostreecxx$cxxbridge1$Treefile$get_container (*this);
}

void
Treefile::assert_no_repovars () const
{
::rust::repr::PtrLen error$ = rpmostreecxx$cxxbridge1$Treefile$assert_no_repovars (*this);
if (error$.ptr)
{
throw ::rust::impl< ::rust::Error>::error (error$);
}
}

bool
Treefile::get_machineid_compat () const noexcept
{
Expand Down
1 change: 1 addition & 0 deletions rpmostree-cxxrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1557,6 +1557,7 @@ struct Treefile final : public ::rust::Opaque
::rust::String get_gpg_key () const noexcept;
::rust::String get_automatic_version_suffix () const noexcept;
bool get_container () const noexcept;
void assert_no_repovars () const;
bool get_machineid_compat () const noexcept;
::rust::Vec< ::rust::String> get_etc_group_members () const noexcept;
bool get_boot_location_is_modules () const noexcept;
Expand Down
112 changes: 112 additions & 0 deletions rust/src/cli_experimental.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

use anyhow::Result;
use camino::Utf8PathBuf;
use clap::{Parser, ValueEnum};
use std::fmt::Display;

#[derive(Debug, Parser)]
#[clap(rename_all = "kebab-case")]
/// Main options struct
struct Experimental {
#[clap(subcommand)]
cmd: Cmd,
}

#[derive(Debug, clap::Subcommand)]
#[clap(rename_all = "kebab-case")]
/// Subcommands
enum Cmd {
/// Verbs for (container) build time operations.
Build {
#[clap(subcommand)]
cmd: BuildCmd,
},
}

/// Choice of build backend.
#[derive(Debug, Clone, Default, clap::ValueEnum)]
enum Mechanism {
/// Use rpm-ostree to construct the root.
#[default]
RpmOstree,
/// Use dnf to construct the root.
Dnf,
}

impl Display for Mechanism {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.to_possible_value().unwrap().get_name().fmt(f)
}
}

#[derive(Debug, clap::Subcommand)]
#[clap(rename_all = "kebab-case")]
/// Subcommands
enum BuildCmd {
/// Initialize a root filesystem tree from a set of packages,
/// including setting up mounts for the API filesystems.
///
/// All configuration for rpm/dnf will come from the source root.
InitRootFromManifest {
/// Path to source root used for base rpm/dnf configuration.
#[clap(long, required = true)]
source_root: Utf8PathBuf,

/// Path to rpm-ostree treefile.
#[clap(long, required = true)]
manifest: Utf8PathBuf,

/// Path to the target root, which should not exist. However, its parent
/// directory must exist.
target: Utf8PathBuf,
},
}

impl BuildCmd {
fn run(self) -> Result<()> {
match self {
BuildCmd::InitRootFromManifest {
source_root,
manifest,
target,
} => {
crate::compose::build_rootfs_from_manifest(&source_root, &manifest, &target)
}
}
}
}

/// Primary entrypoint to running our wrapped `yum`/`dnf` handling.
pub fn main(argv: &[&str]) -> Result<i32> {
let opt = Experimental::parse_from(argv.into_iter().skip(1));
match opt.cmd {
Cmd::Build { cmd } => cmd.run()?,
}
Ok(0)
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_parse() -> Result<()> {
let opt = Experimental::try_parse_from([
"experimental",
"build",
"init-root",
"--source-root=/blah",
"/rootfs",
])
.unwrap();
match opt.cmd {
Cmd::Build {
cmd: BuildCmd::InitRootFromManifest { target, .. },
} => {
assert_eq!(target, "/rootfs");
}
}
Ok(())
}
}
Loading
Loading