summaryrefslogtreecommitdiff
path: root/subplot.py
diff options
context:
space:
mode:
Diffstat (limited to 'subplot.py')
-rw-r--r--subplot.py41
1 files changed, 27 insertions, 14 deletions
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):