summaryrefslogtreecommitdiff
path: root/subplot.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-10-01 10:58:04 +0300
committerLars Wirzenius <liw@liw.fi>2020-10-01 11:12:44 +0300
commitc84bdf6e071933dcbb92d4af9e3993179889fc6b (patch)
tree4c3bf4d4aeba3fa5dbc4fb2c6cd7283838138cd4 /subplot.py
parent502e30f064b10d60683e8b11776a57b1b7f6f6a9 (diff)
downloadsubplot-c84bdf6e071933dcbb92d4af9e3993179889fc6b.tar.gz
fix: add wrapper to add -t option to sp-codegen, when run by subplot
This allows the tests to add the option to use the templates from the source tree, and don't use an installed Subplot, or require one to be installed.
Diffstat (limited to 'subplot.py')
-rw-r--r--subplot.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/subplot.py b/subplot.py
index f71fa9f..4b0ff13 100644
--- a/subplot.py
+++ b/subplot.py
@@ -1,13 +1,43 @@
import json
import os
+import shutil
+import tempfile
+
+
+# A shell script to run the sp-codegen binary from the source directory's Rust
+# build target directory, adding the -t option to use the source directory's
+# template directory.
+#
+# This is a string template where the source directory is filled in when used.
+wrapper = """\
+#!/bin/sh
+set -eu
+exec '{srcdir}/target/debug/sp-codegen' "$@" -t '{srcdir}/templates'
+"""
def install_subplot(ctx):
runcmd_prepend_to_path = globals()["runcmd_prepend_to_path"]
srcdir = globals()["srcdir"]
+
+ # Create a "bin" directory for the wrapper. Can't put this into datadir, as
+ # some of Subplot's scenarios make assumptions on what files exist there.
+ bindir = ctx["bin-dir"] = tempfile.mkdtemp()
+ filename = os.path.join(bindir, "sp-codegen")
+ with open(filename, "w") as f:
+ f.write(wrapper.format(srcdir=srcdir))
+ os.chmod(filename, 0o755)
+
+ # Add the temporary bin directory to the path, and then the source
+ # directory's Rust binary target directory.
+ runcmd_prepend_to_path(ctx, dirname=bindir)
runcmd_prepend_to_path(ctx, dirname=os.path.join(srcdir, "target", "debug"))
+def uninstall_subplot(ctx):
+ shutil.rmtree(ctx["bin-dir"])
+
+
def scenario_was_run(ctx, name=None):
runcmd_stdout_contains = globals()["runcmd_stdout_contains"]
runcmd_stdout_contains(ctx, text="\nscenario: {}\n".format(name))