summaryrefslogtreecommitdiff
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
parenta9e9c7db2195f571904307165b98317b48a5534c (diff)
downloadcachedir-rs-4402c3a02e15a7d1538bad6df616bbef2983a600.tar.gz
setup subplot running
Sponsored-by: author
-rw-r--r--Cargo.toml7
-rw-r--r--build.rs7
-rw-r--r--cachedir.md10
-rw-r--r--src/bin/cachedir.rs (renamed from src/main.rs)0
-rw-r--r--src/cachedir.rs3
-rw-r--r--subplot.rs34
-rw-r--r--subplot.yaml4
-rw-r--r--tests/subplot.rs1
8 files changed, 62 insertions, 4 deletions
diff --git a/Cargo.toml b/Cargo.toml
index aac776d..765dec7 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -5,4 +5,9 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
-[dependencies]
+[dev-dependencies]
+subplotlib = { path = "/home/liw/pers/subplot/git/subplotlib" }
+fehler = "1.0.0"
+
+[build-dependencies]
+subplot-build = { path = "/home/liw/pers/subplot/git/subplot-build" }
diff --git a/build.rs b/build.rs
new file mode 100644
index 0000000..04c4671
--- /dev/null
+++ b/build.rs
@@ -0,0 +1,7 @@
+use std::path::Path;
+
+fn main() {
+ println!("cargo:rerun-if-changed=build.rs");
+ subplot_build::codegen(Path::new("cachedir.md"))
+ .expect("failed to generate code with Subplot");
+}
diff --git a/cachedir.md b/cachedir.md
index b0646c0..2f2607a 100644
--- a/cachedir.md
+++ b/cachedir.md
@@ -1,10 +1,13 @@
---
title: "`cachedir`&mdash;cache directory tag management"
author: The Obnam project
-template: rust
bindings:
- lib/files.yaml
- lib/runcmd.yaml
+ - subplot.yaml
+impls:
+ rust:
+ - subplot.rs
...
# Introduction
@@ -34,7 +37,7 @@ the other isn't.
~~~{#CACHEDIR.TAG .file}
Signature: 8a477f597d28d172789f06886806bc55
~~~
-~~~{#not-a-cache .file}
+~~~{#not-a-tag .file}
This is not a cache directory tag.
~~~
@@ -46,7 +49,8 @@ tags as requested._
We should find no cache directories, if there aren't any.
-given an installed cachedir program
+
+given an installed cachedir
~~~scenario
when I run cachedir find .
diff --git a/src/main.rs b/src/bin/cachedir.rs
index e7a11a9..e7a11a9 100644
--- a/src/main.rs
+++ b/src/bin/cachedir.rs
diff --git a/src/cachedir.rs b/src/cachedir.rs
new file mode 100644
index 0000000..e7a11a9
--- /dev/null
+++ b/src/cachedir.rs
@@ -0,0 +1,3 @@
+fn main() {
+ println!("Hello, world!");
+}
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,
+ )?;
+ }
+}
diff --git a/subplot.yaml b/subplot.yaml
new file mode 100644
index 0000000..3231cc3
--- /dev/null
+++ b/subplot.yaml
@@ -0,0 +1,4 @@
+- given: "an installed cachedir"
+ impl:
+ rust:
+ function: install_cachedir
diff --git a/tests/subplot.rs b/tests/subplot.rs
new file mode 100644
index 0000000..2247dac
--- /dev/null
+++ b/tests/subplot.rs
@@ -0,0 +1 @@
+include!(concat!(env!("OUT_DIR"), "/cachedir.rs"));