Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

out-of-tree "cargo check" fails #108

Closed
ijackson opened this issue Apr 23, 2020 · 4 comments
Closed

out-of-tree "cargo check" fails #108

ijackson opened this issue Apr 23, 2020 · 4 comments

Comments

@ijackson
Copy link

ijackson commented Apr 23, 2020

Hi. I like to do builds out of tree, with the actual source code not writeable by the build process. This is achieved with cargo --manifest-path=..../Cargo.toml --target-dir=target.

NB revised description follows

Unfortunately, if a parent of the source directory contains a cargo config, the cargo run by the cargo_metadata tests picks that up, rather than the one from the build directory. This is because cargo changes directory to the source directory before running the tests. rust-lang/cargo#8148

If I make a linkfarm it does work, but this is of course not particularly desirable.

See transcript below.

Regards,
Ian.

rustcargo@zealot:~/Rustup/Tau/cargo_metadata$ cargo test --manifest-path=/home/ian/Rustup/Tau/cargo_metadata/Cargo.toml --target-dir=target
   Compiling proc-macro2 v1.0.10
   Compiling serde v1.0.106
   Compiling unicode-xid v0.2.0
   Compiling syn v1.0.17
   Compiling ryu v1.0.4
   Compiling semver-parser v0.7.0
   Compiling itoa v0.4.5
   Compiling quote v1.0.3
   Compiling serde_derive v1.0.106
   Compiling serde_json v1.0.51
   Compiling semver v0.9.0
   Compiling cargo_metadata v0.9.1 (/home/ian/Rustup/Tau/cargo_metadata)
    Finished test [unoptimized + debuginfo] target(s) in 17.47s
     Running target/debug/deps/cargo_metadata-1d5f192e04387cf6

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/selftest-b294874640311415

running 6 tests
test cargo_path ... ok
test error1 ... ok
test error2 ... ok
test metadata ... ok
test metadata_deps ... FAILED
test builder_interface ... FAILED

failures:

---- metadata_deps stdout ----
thread 'metadata_deps' panicked at 'called `Result::unwrap()` on an `Err` value: CargoMetadata { stderr: "error: failed to get `semver` as a dependency of package `cargo_metadata v0.9.1 (/home/ian/Rustup/Tau/cargo_metadata)`\n\nCaused by:\n  failed to load source for dependency `semver`\n\nCaused by:\n  Unable to update registry `https://github.com/rust-lang/crates.io-index`\n\nCaused by:\n  failed to update replaced source registry `https://github.com/rust-lang/crates.io-index`\n\nCaused by:\n  failed to read root of directory source: /usr/share/cargo/registry\n\nCaused by:\n  No such file or directory (os error 2)\n" }', tests/selftest.rs:134:20
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- builder_interface stdout ----
thread 'builder_interface' panicked at 'called `Result::unwrap()` on an `Err` value: CargoMetadata { stderr: "error: failed to get `semver` as a dependency of package `cargo_metadata v0.9.1 (/home/ian/Rustup/Tau/cargo_metadata)`\n\nCaused by:\n  failed to load source for dependency `semver`\n\nCaused by:\n  Unable to update registry `https://github.com/rust-lang/crates.io-index`\n\nCaused by:\n  failed to update replaced source registry `https://github.com/rust-lang/crates.io-index`\n\nCaused by:\n  failed to read root of directory source: /usr/share/cargo/registry\n\nCaused by:\n  No such file or directory (os error 2)\n" }', tests/selftest.rs:66:13


failures:
    builder_interface
    metadata_deps

test result: FAILED. 4 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out

error: test failed, to rerun pass '--test selftest'
rustcargo@zealot:~/Rustup/Tau/cargo_metadata$ lndir /home/ian/Rustup/Tau/cargo_metadata/. .
/home/ian/Rustup/Tau/cargo_metadata/./src:
/home/ian/Rustup/Tau/cargo_metadata/./tests:
/home/ian/Rustup/Tau/cargo_metadata/./tests/all:
/home/ian/Rustup/Tau/cargo_metadata/./tests/all/bdep:
/home/ian/Rustup/Tau/cargo_metadata/./tests/all/bdep/src:
/home/ian/Rustup/Tau/cargo_metadata/./tests/all/windep:
/home/ian/Rustup/Tau/cargo_metadata/./tests/all/windep/src:
/home/ian/Rustup/Tau/cargo_metadata/./tests/all/featdep:
/home/ian/Rustup/Tau/cargo_metadata/./tests/all/featdep/src:
/home/ian/Rustup/Tau/cargo_metadata/./tests/all/namedep:
/home/ian/Rustup/Tau/cargo_metadata/./tests/all/namedep/src:
/home/ian/Rustup/Tau/cargo_metadata/./tests/all/path-dep:
/home/ian/Rustup/Tau/cargo_metadata/./tests/all/path-dep/src:
/home/ian/Rustup/Tau/cargo_metadata/./tests/all/devdep:
/home/ian/Rustup/Tau/cargo_metadata/./tests/all/devdep/src:
/home/ian/Rustup/Tau/cargo_metadata/./tests/all/benches:
/home/ian/Rustup/Tau/cargo_metadata/./tests/all/src:
/home/ian/Rustup/Tau/cargo_metadata/./tests/all/src/bin:
/home/ian/Rustup/Tau/cargo_metadata/./tests/all/tests:
/home/ian/Rustup/Tau/cargo_metadata/./tests/all/examples:
/home/ian/Rustup/Tau/cargo_metadata/./tests/all/oldname:
/home/ian/Rustup/Tau/cargo_metadata/./tests/all/oldname/src:
rustcargo@zealot:~/Rustup/Tau/cargo_metadata$ cargo test
    Finished test [unoptimized + debuginfo] target(s) in 0.10s
     Running target/debug/deps/cargo_metadata-1d5f192e04387cf6

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/selftest-b294874640311415

running 6 tests
test cargo_path ... ok
test error1 ... ok
test error2 ... ok
test metadata ... ok
test metadata_deps ... ok
test builder_interface ... ok

test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/test_samples-3e73418aed7f2793

running 4 tests
test alt_registry ... ok
test old_minimal ... ok
test current_dir ... ok
test all_the_fields ... ok

test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests cargo_metadata

running 4 tests
test src/lib.rs - Package::metadata (line 280) ... ok
test src/lib.rs -  (line 31) ... ok
test src/lib.rs -  (line 10) ... ok
test src/lib.rs -  (line 48) ... ok

test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

rustcargo@zealot:~/Rustup/Tau/cargo_metadata$ 
@ijackson
Copy link
Author

I now think that something else is going on. I will report back.

@ijackson
Copy link
Author

In addition to the problem that the cargo_metadata selftests do not pass an appropriate manifest path, there is an infelicity in cargo itself.

It changes to the directory containing this crate's manifest before running the tests.

My source code is in a different account with its own cargo configuration. The copy of cargo run by the tests picks up that other account's cargo configuration, which is not appropriate or desirable.

cargo does not seem to provide the original invocation directory at all. I think the best workaround is to spot if --manifest-path is passed, and if so chdir to /. (!)

That works for me in my ad-hoc tests. I will prepare an MR. I will also investigate requesting a cargo env var for the original invocation directory.

@ijackson
Copy link
Author

I filed this issue against cargo:
rust-lang/cargo#8148

@morr0ne
Copy link
Contributor

morr0ne commented Jul 4, 2022

2 years to late here we are regardless. Is there something cargo_metadata can do here? It feels like this is more of a cargo issue. This can probably be closed.

@oli-obk oli-obk closed this as completed Jul 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants