testutils: Port to cxx-rs

Another easy port like cliwrap.
This commit is contained in:
Colin Walters 2021-01-12 20:34:30 +00:00 committed by OpenShift Merge Robot
parent bdf8269dfa
commit 241cce1ec4
3 changed files with 13 additions and 25 deletions

View File

@ -72,6 +72,11 @@ mod ffi {
fn script_is_ignored(pkg: &str, script: &str) -> bool;
}
// testutils.rs
extern "Rust" {
fn testutils_entrypoint(argv: Vec<String>) -> Result<()>;
}
/// Currently cxx-rs doesn't support mappings; like probably most projects,
/// by far our most common case is a mapping from string -> string and since
/// our data sizes aren't large, we serialize this as a vector of strings pairs.
@ -158,7 +163,7 @@ pub use self::progress::*;
mod scripts;
pub(crate) use self::scripts::*;
mod testutils;
pub use self::testutils::*;
pub(crate) use self::testutils::*;
mod treefile;
pub use self::treefile::*;
mod utils;

View File

@ -208,28 +208,10 @@ fn update_os_tree(opts: &SyntheticUpgradeOpts) -> Result<()> {
Ok(())
}
fn testutils_main(args: &[String]) -> Result<()> {
pub(crate) fn testutils_entrypoint(args: Vec<String>) -> Result<()> {
let opt = Opt::from_iter(args.iter());
match opt {
Opt::GenerateSyntheticUpgrade(ref opts) => update_os_tree(opts)?,
};
Ok(())
}
mod ffi {
use super::*;
use glib_sys;
use libc;
use crate::ffiutil::*;
#[no_mangle]
pub extern "C" fn ror_testutils_entrypoint(
argv: *mut *mut libc::c_char,
gerror: *mut *mut glib_sys::GError,
) -> libc::c_int {
let v: Vec<String> = unsafe { glib::translate::FromGlibPtrContainer::from_glib_none(argv) };
int_glib_error(testutils_main(&v), gerror)
}
}
pub use self::ffi::*;

View File

@ -27,6 +27,7 @@
#include "rpmostree-builtins.h"
#include "rpmostree-rpm-util.h"
#include "rpmostree-rust.h"
#include "rpmostree-cxxrs.h"
gboolean
rpmostree_testutils_builtin_inject_pkglist (int argc, char **argv,
@ -51,11 +52,11 @@ rpmostree_builtin_testutils (int argc, char **argv,
invocation, cancellable, error);
else
{
g_autoptr(GPtrArray) args = g_ptr_array_new ();
for (int i = 0; i < argc; i++)
g_ptr_array_add (args, argv[i]);
g_ptr_array_add (args, NULL);
return ror_testutils_entrypoint ((char**)args->pdata, error);
rust::Vec<rust::String> rustargv;
for (int i = 0; i < argc; i++)
rustargv.push_back(std::string(argv[i]));
rpmostreecxx::testutils_entrypoint (rustargv);
return TRUE;
}
}