From eef7b40a392750d9ff86280a64fb0b64f80a4b7e Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 13 Feb 2021 09:04:20 +0200 Subject: feat: allow subplot.md to be used to test an installed Subplot --- subplot.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ subplot.py | 41 +++++++++++++++++++++++++++-------------- 2 files changed, 75 insertions(+), 14 deletions(-) diff --git a/subplot.md b/subplot.md index d701995..2db50f6 100644 --- a/subplot.md +++ b/subplot.md @@ -213,6 +213,54 @@ be good and helpful, writing it will require effort and skill. No tool can replace that. + +## Using this document to verify Subplot works + +This document ("subplot") can be used to verify Subplot itself from +its source tree or an installed Subplot. The default is to test +Subplot from the source tree, and the `./check` script does that. You +can run this in the source tree to build Subplot and then verify it +using itself: + +~~~sh +$ cargo build -q +$ cargo run --bin sp-codegen -- subplot.md -o test.py +$ python3 test.py +... much output +OK, all scenarios finished successfully +$ +~~~ + +To test an installed Subplot, generate the test program, and tell the +test program where Subplot is installed. Again, in the Subplot source +tree: + +~~~sh +$ cargo build -q +$ cargo run --bin sp-codegen -- subplot.md -o test.py +$ python3 test.py --env SUBPLOT_DIR=/usr/local/bin +... much output +OK, all scenarios finished successfully +$ +~~~ + +You can do this with an installed Subplot as well: + +~~~sh +$ cargo clean +$ /usr/local/bin/sp-codegen subplot.md -o test.py +$ python3 test.py --env SUBPLOT_DIR=/usr/local/bin +... much output +OK, all scenarios finished successfully +$ +~~~ + +The generated test program is self-standing, and can be run from +anywhere. However, to generate it you need to be in the Subplot +source tree. You can move it elsewhere after generating it, you if you +prefer. + + # Requirements This chapter lists requirements for Subplot. These requirements are diff --git a/subplot.py b/subplot.py index 7d9544b..975b579 100644 --- a/subplot.py +++ b/subplot.py @@ -20,23 +20,36 @@ 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() - for prog in ["sp-codegen", "sp-docgen"]: - filename = os.path.join(bindir, prog) - with open(filename, "w") as f: - f.write(wrapper.format(prog=prog, 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")) + # If the SUBPLOT_DIR is set, we expect the Subplot binaries to be installed + # in that directory. Otherwise, we expect them to be in the source + # directory, under target/debug, which is where Rust puts them. In the + # latter case, we create a wrapper script to add the necessary options to + # also use the resources from the source tree. + + bindir = os.environ.get("SUBPLOT_DIR") + if bindir is not None: + runcmd_prepend_to_path(ctx, dirname=bindir) + else: + # 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() + for prog in ["sp-codegen", "sp-docgen"]: + filename = os.path.join(bindir, prog) + with open(filename, "w") as f: + f.write(wrapper.format(prog=prog, 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"]) + if "bin-dir" in ctx: + bindir = ctx["bin-dir"] + if os.path.exists(bindir): + shutil.rmtree(bindir) def scenario_was_run(ctx, name=None): -- cgit v1.2.1