summaryrefslogtreecommitdiff
path: root/subplot.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2022-03-29 20:11:40 +0300
committerLars Wirzenius <liw@liw.fi>2022-03-29 20:11:40 +0300
commit4402c3a02e15a7d1538bad6df616bbef2983a600 (patch)
treea53cf1ab3570c0e6e109fd258a88915d1ceaadf6 /subplot.rs
parenta9e9c7db2195f571904307165b98317b48a5534c (diff)
downloadcachedir-rs-4402c3a02e15a7d1538bad6df616bbef2983a600.tar.gz
setup subplot running
Sponsored-by: author
Diffstat (limited to 'subplot.rs')
-rw-r--r--subplot.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/subplot.rs b/subplot.rs
new file mode 100644
index 0000000..e70ea83
--- /dev/null
+++ b/subplot.rs
@@ -0,0 +1,34 @@
+// Rust support for running sq-subplot.md scenarios.
+
+use subplotlib::steplibrary::runcmd::Runcmd;
+
+use std::path::Path;
+
+#[step]
+#[context(Runcmd)]
+fn install_cachedir(context: &ScenarioContext) {
+ // The CACHEDIR_DIR variable can be set to test an installed
+ // cachedir rather than the one built from the source tree.
+ if let Some(bindir) = std::env::var_os("CACHEDIR_DIR") {
+ println!("Found CACHEDIR_DIR environment variable, using that");
+ context.with_mut(
+ |rc: &mut Runcmd| {
+ rc.prepend_to_path(bindir);
+ Ok(())
+ },
+ false,
+ )?;
+ } else {
+ let target_exe = env!("CARGO_BIN_EXE_cachedir");
+ let target_path = Path::new(target_exe);
+ let target_path = target_path.parent().ok_or("No parent?")?;
+
+ context.with_mut(
+ |context: &mut Runcmd| {
+ context.prepend_to_path(target_path);
+ Ok(())
+ },
+ false,
+ )?;
+ }
+}