diff --git a/Makefile b/Makefile index 2d37aa0e..4595f61f 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,25 @@ -TESTS = +# The "install_test" target installs the subplot binary so that +# $(SUBPLOT) refers to it. This lets us run Subplot without invoking +# "cargo run" every time. This means we invoke in a way that's more +# natural and have to jump through fewer hoops. Also the binary can be +# run from Python tests directly. + +SUBPLOT_DIR = $(abspath inst) + +# Individual tests run by `test` or `fast-test` targets. +TESTS = + +# Set this to "--offline --locked" to build offline. +OFFLINE = + +# Cargo target architecture. +TARGET = + +ifdef TARGET +TARGET_ARG = --target $(TARGET) +else +TARGET_ARG = +endif all: check build test doc shear @@ -11,11 +32,17 @@ build: cargo build --all-targets --workspace subplot docgen ci-broker.subplot -o ci-broker.html -fast-test: build - timeout 60 cargo test --workspace -- --skip upgrades $(TESTS) +install_test_binary: + rm -rf "$(SUBPLOT_DIR)" + cargo install $(TARGET_ARG) --locked $(OFFLINE) --path=. --root="$(SUBPLOT_DIR)" --debug + mv "$(SUBPLOT_DIR)"/bin/* "$(SUBPLOT_DIR)" + rm -rf "$(SUBPLOT_DIR)"/.crate* "$(SUBPLOT_DIR)"/bin + +fast-test: install_test_binary build + env SUBPLOT_DIR="$(SUBPLOT_DIR)" timeout 60 cargo test --workspace -- --skip upgrades $(TESTS) test: fast-test - timeout 300 cargo test --workspace -- $(TESTS) + env SUBPLOT_DIR="$(SUBPLOT_DIR)" timeout 300 cargo test --workspace -- $(TESTS) .PHONY: doc doc: diff --git a/src/subplot.rs b/src/subplot.rs index a3834423..9a9f1367 100644 --- a/src/subplot.rs +++ b/src/subplot.rs @@ -383,11 +383,8 @@ fn head(rad_home: &Path, repo: &Path) -> Result> } fn bindir() -> PathBuf { - let path = if let Ok(target) = std::env::var("CARGO_TARGET_DIR") { - Path::new(&target).join("debug") - } else { - PathBuf::from("target/debug") - }; + let path = std::env::var("SUBPLOT_DIR").expect("SUBPLOT_DIR must be set"); + let path = Path::new(&path); path.canonicalize().unwrap() }