From eccb45b085a5b0e930b29efbd74deaeb4e2b5b73 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 15 Sep 2021 08:25:56 +0300 Subject: test: handle user-chosen cargo target directory Sponsored-by: author --- check | 63 ++++++++++++++++++++++++++------------------------------- subplot/ewww.py | 14 +++++-------- 2 files changed, 34 insertions(+), 43 deletions(-) diff --git a/check b/check index 272ee63..ceffb0e 100755 --- a/check +++ b/check @@ -4,63 +4,58 @@ set -eu verbose=false moar=true -while [ "$#" -gt 0 ] && $moar -do - case "$1" in +while [ "$#" -gt 0 ] && $moar; do + case "$1" in verbose | -v | --verbose) - verbose=true - shift 1 - ;; - esac + verbose=true + shift 1 + ;; + esac done hideok= -if command -v chronic > /dev/null -then - hideok=chronic +if command -v chronic >/dev/null; then + hideok=chronic fi quiet=-q -if $verbose -then - quiet= - hideok= +if $verbose; then + quiet= + hideok= fi - codegen() { - $hideok subplot codegen "$1" --output "$2" - rm -f test.log - $hideok python3 test.py --log test.log + target="$(cargo metadata --format-version=1 | + python3 -c 'import sys, json; o = json.load(sys.stdin); print(o["target_directory"])')" + $hideok subplot codegen "$1" --output "$2" + rm -f test.log + $hideok python3 test.py --log test.log --env "CARGO_TARGET_DIR=$target" } docgen() { - subplot docgen "$1" --output "$2" + subplot docgen "$1" --output "$2" } $hideok cargo build --all-targets -if cargo --list | awk '{ print $1 }' | grep 'clippy$' > /dev/null -then - # shellcheck disable=SC2086 - cargo clippy $quiet +if cargo --list | awk '{ print $1 }' | grep 'clippy$' >/dev/null; then + # shellcheck disable=SC2086 + cargo clippy $quiet fi # shellcheck disable=SC2086 $hideok cargo test $quiet -if cargo fmt --help > /dev/null 2> /dev/null -then - $hideok cargo fmt -- --check +if cargo fmt --help >/dev/null 2>/dev/null; then + $hideok cargo fmt -- --check fi -$hideok ./mktestcert test.key test.pem hunter2 +$hideok ./mktestcert test.key test.pem hunter2 -for md in [^R]*.md -do - $hideok echo "$md =====================================" - codegen "$md" test.py - docgen "$md" "$(basename "$md" .md).pdf" - docgen "$md" "$(basename "$md" .md).html" - $hideok echo +for md in [^R]*.md; do + $hideok echo "$md =====================================" + codegen "$md" test.py + docgen "$md" "$(basename "$md" .md).pdf" + docgen "$md" "$(basename "$md" .md).html" + $hideok echo done echo "Everything seems to be in order." diff --git a/subplot/ewww.py b/subplot/ewww.py index a6c4c4f..11915ae 100644 --- a/subplot/ewww.py +++ b/subplot/ewww.py @@ -10,12 +10,6 @@ import urllib.parse import yaml -# Name of Rust binary, debug-build. -def _binary(name): - srcdir = globals()["srcdir"] - return os.path.abspath(os.path.join(srcdir, "target", "debug", name)) - - # Write a file with given content. def _write(filename, content): open(filename, "w").write(content) @@ -59,6 +53,7 @@ def copy_test_certificate(ctx, cert=None, key=None): # Start server using named configuration file. def start_server(ctx, filename=None): get_file = globals()["get_file"] + srcdir = globals()["srcdir"] daemon_start_on_port = globals()["daemon_start_on_port"] logging.debug(f"Starting ewww with config file {filename}") @@ -72,9 +67,10 @@ def start_server(ctx, filename=None): config = yaml.safe_dump(config) _write(filename, config) - daemon_start_on_port( - ctx, path=_binary("ewww"), args=filename, name="ewww", port=port - ) + target = os.environ.get("CARGO_TARGET_DIR", os.path.join(srcdir, "target")) + logging.debug(f"Cargo target directory: {target}") + binary = os.path.join(target, "debug", "ewww") + daemon_start_on_port(ctx, binary, args=filename, name="ewww", port=port) # Stop previously started server. -- cgit v1.2.1