summaryrefslogtreecommitdiff
path: root/subplot.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-08-14 08:57:25 +0300
committerLars Wirzenius <liw@liw.fi>2021-08-14 13:13:48 +0300
commitaca2bc890c8345718724b5b73dde5968fe25c65b (patch)
tree21f7735d7431f83b1ec8c6f8066765b47e2935f5 /subplot.py
parentdf3d2db5ddfe2b0aa988a41dc6e840ebd4af6435 (diff)
downloadsubplot-aca2bc890c8345718724b5b73dde5968fe25c65b.tar.gz
test: query Cargo for its target directory
Run "cargo metadata" to get the location of the Cargo "target" directory. The location of the directory is configurable by the user, so we can't assume it's "target" in the source tree. It turned out that running "cargo metadata" in a scenario didn't work well, because cargo wants to use some files from the user's home directory, and for scenarios, that's changed (by setting $HOME). To work around this, the generated test program now requires SUBPLOT_DIR to be set when running the generated Python test programs. The "./check" script does that. Sponsored-by: author
Diffstat (limited to 'subplot.py')
-rw-r--r--subplot.py29
1 files changed, 6 insertions, 23 deletions
diff --git a/subplot.py b/subplot.py
index 568013e..8533b45 100644
--- a/subplot.py
+++ b/subplot.py
@@ -1,7 +1,6 @@
import json
import os
import shutil
-import tempfile
import time
@@ -19,31 +18,15 @@ exec '{srcdir}/target/debug/{prog}' --resources '{srcdir}/share' "$@"
def install_subplot(ctx):
runcmd_prepend_to_path = globals()["runcmd_prepend_to_path"]
- srcdir = globals()["srcdir"]
- # 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.
+ # We require the SUBPLOT_DIR environment variable to be set to the path to
+ # the directory where the Subplot binaries are installed.
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 ["subplot"]:
- 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"))
+ assert (
+ bindir is not None
+ ), "MUST set SUBPLOT_DIR to directory where Subplot binaries are installed"
+ runcmd_prepend_to_path(ctx, dirname=bindir)
def uninstall_subplot(ctx):