tests/inst: Add xshell and use it in one place
authorColin Walters <walters@verbum.org>
Wed, 10 May 2023 13:21:45 +0000 (09:21 -0400)
committerColin Walters <walters@verbum.org>
Wed, 10 May 2023 18:02:09 +0000 (14:02 -0400)
I've deprecated sh-inline; in the end I think it is better
to minimize the amount of bash code we have.  xshell solves
the core convenience problem of taking local variables and mapping
them to command arguments.

A full port would be nontrivial; this just starts the ball
rolling.

tests/inst/Cargo.toml
tests/inst/src/treegen.rs

index 02fc3cbfce6017898fe52c8459a01f8e1302f7ba..c8773ad3ee9d14baee2f384a79424e3239e137a9 100644 (file)
@@ -37,6 +37,7 @@ strum = "0.18.0"
 strum_macros = "0.18.0"
 # See discussion in https://github.com/coreos/rpm-ostree/pull/2569#issuecomment-780569188
 rpmostree-client = { git = "https://github.com/coreos/rpm-ostree", tag = "v2021.3" }
+xshell = "0.2.3"
 
 # This one I might publish to crates.io, not sure yet
 with-procspawn-tempdir = { git = "https://github.com/cgwalters/with-procspawn-tempdir" }
index 771611400794af2cefa9030948b645547ec4c4ff..88bd0b7a9b811d816013556b182db108ef18267c 100644 (file)
@@ -4,11 +4,11 @@ use cap_std_ext::cap_std;
 use cap_std_ext::dirext::*;
 use cap_std_ext::rustix::fs::MetadataExt;
 use rand::Rng;
-use sh_inline::bash;
 use std::fs::File;
 use std::io::prelude::*;
 use std::os::unix::fs::FileExt as UnixFileExt;
 use std::path::Path;
+use xshell::cmd;
 
 use crate::test::*;
 
@@ -129,6 +129,7 @@ pub(crate) fn update_os_tree<P: AsRef<Path>>(
     ostref: &str,
     percentage: u32,
 ) -> Result<()> {
+    let sh = xshell::Shell::new()?;
     assert!(percentage > 0 && percentage <= 100);
     let repo_path = repo_path.as_ref();
     let tempdir = tempfile::tempdir_in(repo_path.join("tmp"))?;
@@ -149,9 +150,6 @@ pub(crate) fn update_os_tree<P: AsRef<Path>>(
     }
     assert!(mutated > 0);
     println!("Mutated ELF files: {}", mutated);
-    bash!("ostree --repo=${repo} commit --consume -b ${ostref} --base=${ostref} --tree=dir=${tempdir} --owner-uid 0 --owner-gid 0 --selinux-policy-from-base --link-checkout-speedup --no-bindings --no-xattrs",
-        repo = repo_path,
-        ostref = ostref,
-        tempdir = tempdir.path()).context("Failed to commit updated content")?;
-    Ok(())
+    let tempdir = tempdir.path();
+    cmd!(sh, "ostree --repo={repo_path} commit --consume -b {ostref} --base={ostref} --tree=dir={tempdir} --owner-uid 0 --owner-gid 0 --selinux-policy-from-base --link-checkout-speedup --no-bindings --no-xattrs").run().context("Failed to commit updated content")
 }