Use cxx-rs instead of gresources

The way gresources work using a constructor function started
failing when I was refactoring the build system, and I couldn't
figure it out.  It's just easier to use Rust for this which
has nice toolchain-integrated functionality for this.
This commit is contained in:
Colin Walters 2020-12-21 20:41:46 +00:00 committed by OpenShift Merge Robot
parent 8ab6a1f4f0
commit 6579ab791b
7 changed files with 23 additions and 32 deletions

View File

@ -75,11 +75,6 @@ CLEANFILES += $(gperf_gperf_sources:-gperf.gperf=-gperf.c)
nodist_librpmostreepriv_sources = src/libpriv/rpmostree-script-gperf.c
rpmostree-libpriv-gresources.c: src/libpriv/gresources.xml Makefile $(shell glib-compile-resources --sourcedir=$(srcdir)/src/libpriv --generate-dependencies $(srcdir)/src/libpriv/gresources.xml)
$(AM_V_GEN) glib-compile-resources --target=$@ --sourcedir=$(srcdir)/src/libpriv --generate-source --c-name _rpmostree_ $<
BUILT_SOURCES += rpmostree-libpriv-gresources.c
librpmostreepriv_sources += rpmostree-libpriv-gresources.c
AM_V_GPERF = $(AM_V_GPERF_$(V))
AM_V_GPERF_ = $(AM_V_GPERF_$(AM_DEFAULT_VERBOSITY))
AM_V_GPERF_0 = @echo " GPERF " $@;

View File

@ -44,6 +44,10 @@ impl TempEtcGuard {
}
}
pub(crate) fn get_systemctl_wrapper() -> &'static [u8] {
include_bytes!("../../src/libpriv/systemctl-wrapper.sh")
}
#[cfg(test)]
mod test {
use super::*;

View File

@ -118,6 +118,11 @@ fn generate_initramfs_overlay_etc<P: glib::IsA<gio::Cancellable>>(
generate_initramfs_overlay(&root, files, cancellable)
}
pub(crate) fn get_dracut_random_cpio() -> &'static [u8] {
// Generated with: fakeroot /bin/sh -c 'cd dracut-urandom && find . -print0 | sort -z | (mknod dev/random c 1 8 && mknod dev/urandom c 1 9 && cpio -o --null -H newc -R 0:0 --reproducible --quiet -D . -O /tmp/dracut-urandom.cpio)'
include_bytes!("../../src/libpriv/dracut-random.cpio.gz")
}
#[cfg(test)]
mod test {
use super::*;
@ -143,7 +148,7 @@ mod test {
}
}
pub mod ffi {
mod ffi {
use super::*;
use crate::ffiutil::error_to_glib;
use glib::translate::*;
@ -177,3 +182,4 @@ pub mod ffi {
}
}
}
pub use self::ffi::*;

View File

@ -18,6 +18,13 @@ mod ffi {
fn prepare_tempetc_guard(rootfs: i32) -> Result<Box<TempEtcGuard>>;
fn undo(self: &TempEtcGuard) -> Result<()>;
fn get_systemctl_wrapper() -> &'static [u8];
}
// initramfs.rs
extern "Rust" {
fn get_dracut_random_cpio() -> &'static [u8];
}
// utils.rs
@ -37,7 +44,7 @@ pub use self::history::*;
mod journal;
pub use self::journal::*;
mod initramfs;
pub use self::initramfs::ffi::*;
pub use self::initramfs::*;
mod lockfile;
pub use self::lockfile::*;
mod livefs;

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/rpmostree">
<file>systemctl-wrapper.sh</file>
<!-- Generated with: fakeroot /bin/sh -c 'cd dracut-urandom && find . -print0 | sort -z | (mknod dev/random c 1 8 && mknod dev/urandom c 1 9 && cpio -o --null -H newc -R 0:0 --reproducible --quiet -D . -O /tmp/dracut-urandom.cpio)' -->
<file>dracut-random.cpio.gz</file>
</gresource>
</gresources>

View File

@ -4369,15 +4369,9 @@ rpmostree_context_assemble (RpmOstreeContext *self,
else
{
have_systemctl = TRUE;
g_autoptr(GBytes) systemctl_wrapper = g_resources_lookup_data ("/rpmostree/systemctl-wrapper.sh",
G_RESOURCE_LOOKUP_FLAGS_NONE,
error);
if (!systemctl_wrapper)
return FALSE;
size_t len;
auto buf = static_cast<const guint8*>(g_bytes_get_data (systemctl_wrapper, &len));
auto systemctl_wrapper = rpmostreecxx::get_systemctl_wrapper ();
if (!glnx_file_replace_contents_with_perms_at (tmprootfs_dfd, "usr/bin/systemctl",
buf, len, 0755, (uid_t) -1, (gid_t) -1,
systemctl_wrapper.data(), systemctl_wrapper.length(), 0755, (uid_t) -1, (gid_t) -1,
GLNX_FILE_REPLACE_NODATASYNC,
cancellable, error))
return FALSE;

View File

@ -525,7 +525,6 @@ rpmostree_run_dracut (int rootfs_dfd,
g_autoptr(RpmOstreeBwrap) bwrap = NULL;
g_autoptr(GPtrArray) rebuild_argv = NULL;
g_auto(GLnxTmpfile) tmpf = { 0, };
g_autoptr(GBytes) random_cpio_data = NULL;
/* We need to have /etc/passwd since dracut doesn't have altfiles
* today. Though maybe in the future we should add it, but
@ -627,16 +626,10 @@ rpmostree_run_dracut (int rootfs_dfd,
* https://bugzilla.redhat.com/show_bug.cgi?id=1401444
* https://bugzilla.redhat.com/show_bug.cgi?id=1380866
* */
random_cpio_data = g_resources_lookup_data ("/rpmostree/dracut-random.cpio.gz",
G_RESOURCE_LOOKUP_FLAGS_NONE,
error);
if (!random_cpio_data)
return FALSE;
gsize random_cpio_data_len = 0;
auto random_cpio_data_p = static_cast<const guint8*>(g_bytes_get_data (random_cpio_data, &random_cpio_data_len));
auto random_cpio_data = rpmostreecxx::get_dracut_random_cpio ();
if (lseek (tmpf.fd, 0, SEEK_END) < 0)
return glnx_throw_errno_prefix (error, "lseek");
if (glnx_loop_write (tmpf.fd, random_cpio_data_p, random_cpio_data_len) < 0)
if (glnx_loop_write (tmpf.fd, random_cpio_data.data(), random_cpio_data.length()) < 0)
return glnx_throw_errno_prefix (error, "write");
if (rebuild_from_initramfs)