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

Prep patches for modularity and pinned repo packages #2785

Merged
merged 5 commits into from
Apr 29, 2021
Merged
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
2 changes: 1 addition & 1 deletion rust/src/countme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn send_countme(url: &str, ua: &str) -> Result<()> {
}

/// Main entrypoint for countme
pub fn entrypoint() -> Result<()> {
pub fn entrypoint(_args: &[&str]) -> Result<()> {
// Skip if we are not run on an ostree booted system
if !path::Path::new("/run/ostree-booted").exists() {
bail!("Not running on an ostree based system");
Expand Down
21 changes: 0 additions & 21 deletions rust/src/includes.rs

This file was deleted.

19 changes: 19 additions & 0 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,25 @@ pub mod ffi {
fn print(&self);
}

// https://cxx.rs/shared.html#extern-enums
enum RpmOstreeDiffPrintFormat {
RPMOSTREE_DIFF_PRINT_FORMAT_SUMMARY,
RPMOSTREE_DIFF_PRINT_FORMAT_FULL_ALIGNED,
RPMOSTREE_DIFF_PRINT_FORMAT_FULL_MULTILINE,
}

unsafe extern "C++" {
include!("rpmostree-libbuiltin.h");
include!("rpmostree-util.h");
type RpmOstreeDiffPrintFormat;
unsafe fn print_treepkg_diff_from_sysroot_path(
sysroot_path: &str,
format: RpmOstreeDiffPrintFormat,
max_key_len: u32,
cancellable: *mut GCancellable,
);
}

unsafe extern "C++" {
include!("rpmostree-output.h");
type Progress;
Expand Down
4 changes: 2 additions & 2 deletions rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use anyhow::Result;

fn inner_main(args: &Vec<&str>) -> Result<()> {
match args.get(1).map(|s| *s) {
// Add custom Rust commands here.
Some("countme") => rpmostree_rust::countme::entrypoint(),
// Add custom Rust commands here, and also in `libmain.cxx` if user-visible.
Some("countme") => rpmostree_rust::countme::entrypoint(args),
_ => {
// Otherwise fall through to C++ main().
Ok(rpmostree_rust::ffi::rpmostree_main(&args)?)
Expand Down
2 changes: 1 addition & 1 deletion rust/src/treefile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ fn merge_map_field<T>(
}
}

/// Merge an hashet field by extending.
/// Merge an hashset field by extending.
fn merge_hashset_field<T: Eq + std::hash::Hash>(
dest: &mut Option<HashSet<T>>,
src: &mut Option<HashSet<T>>,
Expand Down
7 changes: 7 additions & 0 deletions src/app/libmain.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ static RpmOstreeCommand commands[] = {
{ "kargs", static_cast<RpmOstreeBuiltinFlags>(0),
"Query or modify kernel arguments",
rpmostree_builtin_kargs },
/* Rust-implemented commands; they're here so that they show up in `rpm-ostree
* --help` alongside the other commands, but the command itself is fully
* handled Rust side. */
/*
{ "my-rust-command", static_cast<RpmOstreeBuiltinFlags>(0),
"Cool thing my command does", NULL },
*/
/* Legacy aliases */
{ "pkg-add", static_cast<RpmOstreeBuiltinFlags>(RPM_OSTREE_BUILTIN_FLAG_HIDDEN),
NULL, rpmostree_builtin_install },
Expand Down
5 changes: 2 additions & 3 deletions src/app/rpmostree-builtin-deploy.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,8 @@ rpmostree_builtin_deploy (int argc,

/* do diff without dbus: https://github.com/projectatomic/rpm-ostree/pull/116 */
const char *sysroot_path = rpmostree_sysroot_get_path (sysroot_proxy);
if (!rpmostree_print_treepkg_diff_from_sysroot_path (sysroot_path,
RPMOSTREE_DIFF_PRINT_FORMAT_FULL_MULTILINE, 0, cancellable, error))
return FALSE;
rpmostreecxx::print_treepkg_diff_from_sysroot_path (rust::Str(sysroot_path),
RPMOSTREE_DIFF_PRINT_FORMAT_FULL_MULTILINE, 0, cancellable);

g_print ("Run \"systemctl reboot\" to start a reboot\n");
}
Expand Down
5 changes: 2 additions & 3 deletions src/app/rpmostree-builtin-status.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -824,9 +824,8 @@ print_one_deployment (RPMOSTreeSysroot *sysroot_proxy,
{
/* No cached update, but we can still print a diff summary */
const char *sysroot_path = rpmostree_sysroot_get_path (sysroot_proxy);
if (!rpmostree_print_treepkg_diff_from_sysroot_path (sysroot_path, diff_format,
max_key_len, NULL, error))
return FALSE;
rpmostreecxx::print_treepkg_diff_from_sysroot_path (rust::Str(sysroot_path), diff_format,
max_key_len, NULL);
}

/* print base overrides before overlays */
Expand Down
5 changes: 2 additions & 3 deletions src/app/rpmostree-builtin-upgrade.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,8 @@ rpmostree_builtin_upgrade (int argc,

/* do diff without dbus: https://github.com/projectatomic/rpm-ostree/pull/116 */
const char *sysroot_path = rpmostree_sysroot_get_path (sysroot_proxy);
if (!rpmostree_print_treepkg_diff_from_sysroot_path (sysroot_path,
RPMOSTREE_DIFF_PRINT_FORMAT_FULL_MULTILINE, 0, cancellable, error))
return FALSE;
rpmostreecxx::print_treepkg_diff_from_sysroot_path (rust::Str(sysroot_path),
RPMOSTREE_DIFF_PRINT_FORMAT_FULL_MULTILINE, 0, cancellable);

g_print ("Run \"systemctl reboot\" to start a reboot\n");
}
Expand Down
5 changes: 2 additions & 3 deletions src/app/rpmostree-clientlib.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -939,9 +939,8 @@ rpmostree_transaction_client_run (RpmOstreeCommandInvocation *invocation,
{
/* do diff without dbus: https://github.com/projectatomic/rpm-ostree/pull/116 */
const char *sysroot_path = rpmostree_sysroot_get_path (sysroot_proxy);
if (!rpmostree_print_treepkg_diff_from_sysroot_path (sysroot_path,
RPMOSTREE_DIFF_PRINT_FORMAT_FULL_MULTILINE, 0, cancellable, error))
return FALSE;
rpmostreecxx::print_treepkg_diff_from_sysroot_path (rust::Str(sysroot_path),
RPMOSTREE_DIFF_PRINT_FORMAT_FULL_MULTILINE, 0, cancellable);
}

g_print ("Run \"systemctl reboot\" to start a reboot\n");
Expand Down
34 changes: 19 additions & 15 deletions src/app/rpmostree-libbuiltin.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,21 @@ rpmostree_has_new_default_deployment (RPMOSTreeOS *os_proxy,
return !g_str_equal (previous_id, new_id);
}

namespace rpmostreecxx {

/* Print the diff between the booted and pending deployments */
gboolean
rpmostree_print_treepkg_diff_from_sysroot_path (const gchar *sysroot_path,
RpmOstreeDiffPrintFormat format,
guint max_key_len,
GCancellable *cancellable,
GError **error)
void
print_treepkg_diff_from_sysroot_path (rust::Str sysroot_path,
RpmOstreeDiffPrintFormat format,
guint32 max_key_len,
GCancellable *cancellable)
{
g_autoptr(GFile) sysroot_file = g_file_new_for_path (sysroot_path);
g_autoptr(GError) local_error = NULL;
g_autofree char *sysroot_cpath = g_strndup (sysroot_path.data(), sysroot_path.length());
g_autoptr(GFile) sysroot_file = g_file_new_for_path (sysroot_cpath);
g_autoptr(OstreeSysroot) sysroot = ostree_sysroot_new (sysroot_file);
if (!ostree_sysroot_load (sysroot, cancellable, error))
return FALSE;
if (!ostree_sysroot_load (sysroot, cancellable, &local_error))
util::throw_gerror(local_error);

g_autoptr(GPtrArray) deployments = ostree_sysroot_get_deployments (sysroot);
g_assert_cmpuint (deployments->len, >, 1);
Expand All @@ -103,11 +106,11 @@ rpmostree_print_treepkg_diff_from_sysroot_path (const gchar *sysroot_path,
OstreeDeployment *booted_deployment = ostree_sysroot_get_booted_deployment (sysroot);

if (!booted_deployment || ostree_deployment_equal (booted_deployment, new_deployment))
return TRUE;
return;

g_autoptr(OstreeRepo) repo = NULL;
if (!ostree_sysroot_get_repo (sysroot, &repo, cancellable, error))
return FALSE;
if (!ostree_sysroot_get_repo (sysroot, &repo, cancellable, &local_error))
util::throw_gerror(local_error);

const char *from_rev = ostree_deployment_get_csum (booted_deployment);
const char *to_rev = ostree_deployment_get_csum (new_deployment);
Expand All @@ -118,14 +121,15 @@ rpmostree_print_treepkg_diff_from_sysroot_path (const gchar *sysroot_path,
g_autoptr(GPtrArray) modified_new = NULL;
if (!rpm_ostree_db_diff (repo, from_rev, to_rev,
&removed, &added, &modified_old, &modified_new,
cancellable, error))
return FALSE;
cancellable, &local_error))
util::throw_gerror(local_error);

rpmostree_diff_print_formatted (format, NULL, max_key_len,
removed, added, modified_old, modified_new);
return TRUE;
}

} /* namespace */

void
rpmostree_print_timestamp_version (const char *version_string,
const char *timestamp_string,
Expand Down
14 changes: 8 additions & 6 deletions src/app/rpmostree-libbuiltin.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ gboolean
rpmostree_has_new_default_deployment (RPMOSTreeOS *os_proxy,
GVariant *previous_deployment);

gboolean
rpmostree_print_treepkg_diff_from_sysroot_path (const gchar *sysroot_path,
RpmOstreeDiffPrintFormat format,
guint max_key_len,
GCancellable *cancellable,
GError **error);
namespace rpmostreecxx {

void
print_treepkg_diff_from_sysroot_path (rust::Str sysroot_path,
RpmOstreeDiffPrintFormat format,
guint32 max_key_len,
GCancellable *cancellable);
}

void
rpmostree_print_timestamp_version (const char *version_string,
Expand Down
5 changes: 2 additions & 3 deletions src/app/rpmostree-override-builtins.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,8 @@ handle_override (RPMOSTreeSysroot *sysroot_proxy,
return TRUE;

const char *sysroot_path = rpmostree_sysroot_get_path (sysroot_proxy);
if (!rpmostree_print_treepkg_diff_from_sysroot_path (sysroot_path,
RPMOSTREE_DIFF_PRINT_FORMAT_FULL_MULTILINE, 0, cancellable, error))
return FALSE;
rpmostreecxx::print_treepkg_diff_from_sysroot_path (rust::Str(sysroot_path),
RPMOSTREE_DIFF_PRINT_FORMAT_FULL_MULTILINE, 0, cancellable);

if (override_replace || override_remove)
g_print ("Use \"rpm-ostree override reset\" to undo overrides\n");
Expand Down
2 changes: 2 additions & 0 deletions src/libpriv/rpmostree-core.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4752,6 +4752,8 @@ rpmostree_context_commit (RpmOstreeContext *self,
}
else if (assemble_type == RPMOSTREE_ASSEMBLE_TYPE_SERVER_BASE)
{
/* Note this branch isn't actually used today; the compose side commit
* code is in impl_commit_tree(). */
g_autoptr(GVariant) spec_v =
g_variant_ref_sink (rpmostree_treespec_to_variant (self->spec));

Expand Down
7 changes: 6 additions & 1 deletion src/libpriv/rpmostree-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ rpmostree_generate_diff_summary (guint upgraded,
guint removed,
guint added);

typedef enum {
// note this enum is shared with Rust via the cxxbridge
typedef enum : std::uint8_t {
RPMOSTREE_DIFF_PRINT_FORMAT_SUMMARY, /* Diff: 1 upgraded, 2 downgraded, 3 removed, 4 added */
RPMOSTREE_DIFF_PRINT_FORMAT_FULL_ALIGNED, /* Upgraded: ...
...
Expand All @@ -188,6 +189,10 @@ typedef enum {
... */
} RpmOstreeDiffPrintFormat;

namespace rpmostreecxx {
using RpmOstreeDiffPrintFormat = ::RpmOstreeDiffPrintFormat;
}

void
rpmostree_diff_print_formatted (RpmOstreeDiffPrintFormat format,
const char *prefix,
Expand Down