nextest icon indicating copy to clipboard operation
nextest copied to clipboard

Bug: default store directory does not respect `CARGO_TARGET_DIR`

Open tgross35 opened this issue 11 months ago • 6 comments

Description of the issue

Description:

Nextest always tries to create the store directory at the workspace root, which fails if the workspace is read-only.

Steps to reproduce:

  1. Go to any existing project, ensure the target directory is clean (or at least target/nextest does not exist)
  2. Launch a Docker container that mounts the current workspace as read only, and sets CARGO_TARGET_DIR. : docker run --rm -e CARGO_TARGET_DIR=/target -v "$(pwd):/checkout:ro" -it rust bash
  3. Install nextest: cargo install cargo-nextest
  4. cd /checkout
  5. Try running tests normally: cargo test. This should work
  6. Try running tests via nextest: cargo nextest run. This fails with something like:
error: failed to create store dir at `/checkout/target/nextest/default`

Caused by:
  Read-only file system (os error 30)

Expected outcome

By default, rather than using a path relative to the workspace root, nextest should create its store directory within CARGO_TARGET_DIR if it is set.

Actual result

Unable to create the file (see above)

Nextest version

cargo-nextest 0.9.87 (fee71ad7b 2024-12-17)
release: 0.9.87
commit-hash: fee71ad7ba08be06519cf9eeb495c6fce0a2e888
commit-date: 2024-12-17
host: aarch64-unknown-linux-gnu

Additional context

No response

tgross35 avatar Jan 14 '25 01:01 tgross35

Thanks -- yeah, this has been a problem for a while. I'd definitely like to change the default at some point, but that would have to be a carefully-managed behavior change. I think for now we should let you set the target directory to be the same as CARGO_TARGET_DIR.

sunshowers avatar Jan 14 '25 19:01 sunshowers

Would some form of environment interpolation in config be possible? Maybe the default could change to be store.dir = "${CARGO_TARGET_DIR:-target}/nextest" which would probably be correct in most cases.

tgross35 avatar Jan 14 '25 19:01 tgross35

Yeah -- though in this other case we decided to let you say relative-to = "target", which we should probably be consistent with.

https://nexte.st/docs/ci-features/archiving/#adding-extra-files-to-an-archive

So you'd say

store.dir = { path = "nextest", relative-to = "target" }

and we'd eventually make this the default.

sunshowers avatar Jan 14 '25 19:01 sunshowers

I have a build container that mounts the root dir and writes all of its output to the folder target_builder by setting CARGO_TARGET_DIR. At the same time, it is possible to build locally with default settings (i.e. using target as target dir) - even in parallel - because the target folders don't conflict.

There are occasions where it is quite useful to be able to do that, so it would be nice if the store.dir setting would respect the environment variable.

To work around that, I use a wrapping bash script that checks for CARGO_TARGET_DIR and calls nextest with the according config file, but that is quite ugly.

pantos9000 avatar Feb 11 '25 10:02 pantos9000

Absolutely agreed that this is an issue -- please submit a PR!

sunshowers avatar Feb 11 '25 19:02 sunshowers

I've started on this in https://github.com/nextest-rs/nextest/pull/2154. I would love somebody's help completing this (in particular, writing tests for this). I'm also not sure how temporary target directories should be handled, and would appreciate ideas there as well.

sunshowers avatar Feb 16 '25 05:02 sunshowers