From 4402c3a02e15a7d1538bad6df616bbef2983a600 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Tue, 29 Mar 2022 20:11:40 +0300 Subject: setup subplot running Sponsored-by: author --- Cargo.toml | 7 ++++++- build.rs | 7 +++++++ cachedir.md | 10 +++++++--- src/bin/cachedir.rs | 3 +++ src/cachedir.rs | 3 +++ src/main.rs | 3 --- subplot.rs | 34 ++++++++++++++++++++++++++++++++++ subplot.yaml | 4 ++++ tests/subplot.rs | 1 + 9 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 build.rs create mode 100644 src/bin/cachedir.rs create mode 100644 src/cachedir.rs delete mode 100644 src/main.rs create mode 100644 subplot.rs create mode 100644 subplot.yaml create mode 100644 tests/subplot.rs 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`—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/bin/cachedir.rs b/src/bin/cachedir.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/src/bin/cachedir.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} 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/src/main.rs b/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -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")); -- cgit v1.2.1