From 562acedbaa94b4cb5f6a1e892c1b86bc741b5982 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 23 Dec 2020 17:01:33 +0000 Subject: [PATCH] Move "ignored script list" to Rust, drop gperf Rust has a nice crate for doing perfect hashing. Move that code into Rust and drop the dependency on `gperf`. This also helps move away from Autotools. --- Cargo.lock | 61 ++++++++++++++++++++++++ Cargo.toml | 1 + Makefile-libpriv.am | 14 ------ configure.ac | 25 ---------- packaging/rpm-ostree.spec.in | 1 - rust/src/lib.rs | 7 +++ rust/src/scripts.rs | 57 ++++++++++++++++++++++ src/libpriv/rpmostree-script-gperf.gperf | 45 ----------------- src/libpriv/rpmostree-scripts.cxx | 38 +++------------ src/libpriv/rpmostree-scripts.h | 13 ----- 10 files changed, 132 insertions(+), 130 deletions(-) create mode 100644 rust/src/scripts.rs delete mode 100644 src/libpriv/rpmostree-script-gperf.gperf diff --git a/Cargo.lock b/Cargo.lock index e977d61a..e4f50072 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -771,6 +771,50 @@ dependencies = [ "system-deps", ] +[[package]] +name = "phf" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dfb61232e34fcb633f43d12c58f83c1df82962dcdfa565a4e866ffc17dafe12" +dependencies = [ + "phf_macros", + "phf_shared", + "proc-macro-hack", +] + +[[package]] +name = "phf_generator" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17367f0cc86f2d25802b2c26ee58a7b23faeccf78a396094c13dced0d0182526" +dependencies = [ + "phf_shared", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f6fde18ff429ffc8fe78e2bf7f8b7a5a5a6e2a8b58bc5a9ac69198bbda9189c" +dependencies = [ + "phf_generator", + "phf_shared", + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c00cf8b9eafe68dde5e9eaa2cef8ee84a9336a47d566ec55ca16589633b65af7" +dependencies = [ + "siphasher", +] + [[package]] name = "pin-project" version = "0.4.27" @@ -893,6 +937,7 @@ dependencies = [ "rand_chacha", "rand_core", "rand_hc", + "rand_pcg", ] [[package]] @@ -923,6 +968,15 @@ dependencies = [ "rand_core", ] +[[package]] +name = "rand_pcg" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429" +dependencies = [ + "rand_core", +] + [[package]] name = "rayon" version = "1.5.0" @@ -1002,6 +1056,7 @@ dependencies = [ "openat-ext", "ostree", "ostree-sys", + "phf", "rand", "rayon", "serde", @@ -1076,6 +1131,12 @@ dependencies = [ "yaml-rust", ] +[[package]] +name = "siphasher" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa8f3741c7372e75519bd9346068370c9cdaabcc1f9599cbcf2a2719352286b7" + [[package]] name = "slab" version = "0.4.2" diff --git a/Cargo.toml b/Cargo.toml index cf8a0b72..eb8f91d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ curl = "0.4.34" rayon = "1.5.0" c_utf8 = "0.1.0" rand = "0.7.3" +phf = { version = "0.8", features = ["macros"] } systemd = "0.8.1" indicatif = "0.15.0" lazy_static = "1.4.0" diff --git a/Makefile-libpriv.am b/Makefile-libpriv.am index 49d5e2c9..806fcc80 100644 --- a/Makefile-libpriv.am +++ b/Makefile-libpriv.am @@ -69,20 +69,6 @@ librpmostreepriv_sources += \ $(NULL) endif -gperf_gperf_sources = src/libpriv/rpmostree-script-gperf.gperf -BUILT_SOURCES += $(gperf_gperf_sources:-gperf.gperf=-gperf.c) -CLEANFILES += $(gperf_gperf_sources:-gperf.gperf=-gperf.c) - -nodist_librpmostreepriv_sources = src/libpriv/rpmostree-script-gperf.c - -AM_V_GPERF = $(AM_V_GPERF_$(V)) -AM_V_GPERF_ = $(AM_V_GPERF_$(AM_DEFAULT_VERBOSITY)) -AM_V_GPERF_0 = @echo " GPERF " $@; - -src/%.c: src/%.gperf Makefile - $(AM_V_at)$(MKDIR_P) $(dir $@) - $(AM_V_GPERF)$(GPERF) < $< > $@.tmp && mv $@.tmp $@ - # Also we now use cxx.rs rpmostree-cxxrs.h: rust/src/lib.rs $(AM_V_GEN) cxxbridge rust/src/lib.rs --header > $@ diff --git a/configure.ac b/configure.ac index 86ade3c5..a6b8f368 100644 --- a/configure.ac +++ b/configure.ac @@ -115,31 +115,6 @@ AC_PATH_PROG([XSLTPROC], [xsltproc]) GLIB_TESTS LIBGLNX_CONFIGURE -AC_CHECK_TOOL(GPERF, gperf) -AS_IF([test -z "$GPERF"], - AC_MSG_ERROR([*** gperf not found]) -) -dnl stolen from https://github.com/systemd/systemd/commit/c9f7b4d -GPERF_TEST="$(echo foo,bar | ${GPERF} -L ANSI-C)" -AC_COMPILE_IFELSE( -[AC_LANG_PROGRAM([ -#include -const char * in_word_set(const char *, size_t); -$GPERF_TEST] -)], -[GPERF_LEN_TYPE=size_t], -[AC_COMPILE_IFELSE( -[AC_LANG_PROGRAM([ -#include -const char * in_word_set(const char *, unsigned); -$GPERF_TEST] -)], -[GPERF_LEN_TYPE=unsigned], -[AC_MSG_ERROR([** unable to determine gperf len type])] -)] -) -AC_DEFINE_UNQUOTED([GPERF_LEN_TYPE], [$GPERF_LEN_TYPE], [gperf len type]) - m4_ifdef([GOBJECT_INTROSPECTION_CHECK], [ GOBJECT_INTROSPECTION_CHECK([1.34.0]) ]) diff --git a/packaging/rpm-ostree.spec.in b/packaging/rpm-ostree.spec.in index ec134a0c..ee4df2db 100644 --- a/packaging/rpm-ostree.spec.in +++ b/packaging/rpm-ostree.spec.in @@ -41,7 +41,6 @@ BuildRequires: autoconf automake libtool git # For docs BuildRequires: chrpath BuildRequires: gtk-doc -BuildRequires: gperf BuildRequires: gnome-common BuildRequires: /usr/bin/g-ir-scanner # Core requirements diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 7732d6f6..51f8de3e 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -27,6 +27,11 @@ mod ffi { fn get_dracut_random_cpio() -> &'static [u8]; } + // scripts.rs + extern "Rust" { + fn script_is_ignored(pkg: &str, script: &str) -> bool; + } + // utils.rs extern "Rust" { fn download_to_fd(url: &str) -> Result; @@ -53,6 +58,8 @@ mod ostree_diff; mod ostree_utils; mod progress; pub use self::progress::*; +mod scripts; +pub(crate) use self::scripts::*; mod testutils; pub use self::testutils::*; mod treefile; diff --git a/rust/src/scripts.rs b/rust/src/scripts.rs new file mode 100644 index 00000000..0037e78d --- /dev/null +++ b/rust/src/scripts.rs @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2020 Red Hat, Inc. + * + * SPDX-License-Identifier: Apache-2.0 OR MIT + */ + +use phf::phf_set; + +/// Some RPM scripts we don't want to execute. A notable example is the kernel ones; +/// we want rpm-ostree to own running dracut, installing the kernel to /boot etc. +/// Ideally more of these migrate out, e.g. in the future we should change the kernel +/// package to do nothing if `/run/ostree-booted` exists. +/// +/// NOTE FOR GIT history: This list used to live in src/libpriv/rpmostree-script-gperf.gperf +static IGNORED_PKG_SCRIPTS: phf::Set<&'static str> = phf_set! { + "glibc.prein", + // We take over depmod/dracut etc. It's `kernel` in C7 and kernel-core in F25+ + "kernel.posttrans", + "kernel-core.posttrans", + // Legacy workaround + "glibc-headers.prein", + // workaround for old bug? + "coreutils.prein", + // Looks like legacy... + "ca-certificates.prein", + "libgcc.post", + "setup.post", + "pinentry.prein", + "fedora-release.posttrans", + // These add the vagrant group which IMO is really + // a libvirt-user group + "vagrant.prein", + "vagrant-libvirt.prein", + // This one is in lua; the setup package seems to be generating the value. + // Should probably be ported to a drop-in dir or a %posttrans + "bash.post", + // Seems to be another case of legacy workaround + "gdb.prein", + // Just does a daemon-reload which we don't want offline + "systemd.transfiletriggerin", + // https://bugzilla.redhat.com/show_bug.cgi?id=1473402 + "man-db.transfiletriggerin", + // https://src.fedoraproject.org/rpms/nfs-utils/pull-request/1 + "nfs-utils.post", + // There is some totally insane stuff going on here in RHEL7 + "microcode_ctl.post", + // https://bugzilla.redhat.com/show_bug.cgi?id=1199582 + "microcode_ctl.posttrans", +}; + +/// Returns true if we should simply ignore (not execute) an RPM script. +/// The format is .