xd009642 / tarpaulin

A code coverage tool for Rust projects
https://crates.io/crates/cargo-tarpaulin
Apache License 2.0
2.5k stars 180 forks source link

[Windows] Test failure when project has a dependency on rustc_version_runtime #1123

Closed eminence closed 1 year ago

eminence commented 1 year ago

Describe the bug When testing (with tarpaulin) a project that has a dependency on rustc_version_runtime, a build error prevents tests from running. This happens only on Windows.

To Reproduce First, create a new empty library, and add the problematic dependency:

cargo new --lib foo
cd foo
cargo add rustc_version_runtime

Then try to run tarpaulin. I've reproduced with the latest 0.22.0 release, and the latest develop branch (78bdb600377e3d47ba9ecce60ada884914626b97). In the transcript below, I am running from the latest develop branch:

d:\users\lxd\devel\tarpaulin>cargo run -- tarpaulin --root d:\temp\lxd\37\foo --engine llvm
warning: `cargo-tarpaulin` (lib) generated 2 warnings
    Finished dev [unoptimized + debuginfo] target(s) in 0.29s
     Running `target\debug\cargo-tarpaulin.exe tarpaulin --root d:\temp\lxd\37\foo --engine llvm`
Oct 24 16:06:56.689  INFO cargo_tarpaulin::config: Creating config
Oct 24 16:06:57.021  INFO cargo_tarpaulin: Running Tarpaulin
Oct 24 16:06:57.022  INFO cargo_tarpaulin: Building project
Oct 24 16:06:57.026  INFO cargo_tarpaulin::cargo: Cleaning project
   Compiling semver-parser v0.7.0
   Compiling semver v0.9.0
   Compiling rustc_version v0.2.3
   Compiling rustc_version_runtime v0.2.1
error: could not compile `rustc_version_runtime` due to 2 previous errors
Oct 24 16:06:58.578 ERROR cargo_tarpaulin: Failed to compile tests!
error: couldn't read \\?\D:\temp\lxd\37\foo\target\debug\build\rustc_version_runtime-b7fa740ad9722d3b\out/version.rs: The filename, directory name, or volume label syntax is incorrect. (os error 123)
  --> C:\Users\LXD\.cargo\registry\src\github.com-1ecc6299db9ec823\rustc_version_runtime-0.2.1\src\lib.rs:26:5
   |
26 |     include!(concat!(env!("OUT_DIR"), "/version.rs"));
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in the macro `include` (in Nightly builds, run with -Z macro-backtrace for more info)

Error: "Failed to compile tests!\nerror: couldn't read \\\\?\\D:\\temp\\lxd\\37\\foo\\target\\debug\\build\\rustc_version_runtime-b7fa740ad9722d3b\\out/version.rs: The filename, directory name, or volume label syntax is incorrect. (os error 123)\n  --> C:\\Users\\LXD\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\rustc_version_runtime-0.2.1\\src\\lib.rs:26:5\n   |\n26 |     include!(concat!(env!(\"OUT_DIR\"), \"/version.rs\"));\n   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n   |\n   = note: this error originates in the macro `include` (in Nightly builds, run with -Z macro-backtrace for more info)\n\n"
error: process didn't exit successfully: `target\debug\cargo-tarpaulin.exe tarpaulin --root d:\temp\lxd\37\foo --engine llvm` (exit code: 1)

Note that the file in question (\\?\D:\temp\lxd\37\foo\target\debug\build\rustc_version_runtime-b7fa740ad9722d3b\out/version.rs) does in fact exist,

Expected behavior I expected the tests in the foo lib to be run, hopefully with coverage data generated : )

Rust version

rustc 1.64.0 (a55dd71d5 2022-09-19)
xd009642 commented 1 year ago

Huh interesting, just for completeness this runs fine on windows with just cargo test right?

eminence commented 1 year ago

Yup. That is, running cargo test from within the foo project is successful on Windows

(and cargo test --manifest-path d:\temp\lxd\37\foo\Cargo.toml is successful too, as expected)

Christiaan676 commented 1 year ago

Running into the same problem with a workspace that contains multiple sub projects

cargo tarpaulin --command test --workspace --locked --out xml
Nov 07 22:26:19.942  INFO cargo_tarpaulin::config: Creating config
Nov 07 22:26:20.051  WARN cargo_tarpaulin::config: Couldn't get project metadata `cargo metadata` exited with an error: error: failed to load manifest for workspace member `\\?\C:\<workspace root>\lib\*`

Caused by:
  failed to read `\\?\C:\<workspace root>\lib\*\Cargo.toml`

Caused by:
  The filename, directory name, or volume label syntax is incorrect. (os error 123)

Nov 07 22:26:20.083  WARN cargo_tarpaulin::config: Couldn't get project metadata `cargo metadata` exited with an error: error: failed to load manifest for workspace member `\\?\C:\<workspace root>\lib\*`

Caused by:
  failed to read `\\?\C:\<workspace root>\lib\*\Cargo.toml`

Caused by:
  The filename, directory name, or volume label syntax is incorrect. (os error 123)

Nov 07 22:26:20.083  INFO cargo_tarpaulin: Running Tarpaulin
Nov 07 22:26:20.083  INFO cargo_tarpaulin: Building project
Nov 07 22:26:20.117  WARN cargo_tarpaulin::config: Couldn't get project metadata `cargo metadata` exited with an error: error: failed to load manifest for workspace member `\\?\C:\<workspace root>\lib\*`

Caused by:
  failed to read `\\?\C:\<workspace root>\lib\*\Cargo.toml`

Caused by:
  The filename, directory name, or volume label syntax is incorrect. (os error 123)

Nov 07 22:26:20.118  INFO cargo_tarpaulin::cargo: Cleaning project
Nov 07 22:26:20.144 ERROR cargo_tarpaulin: Cargo failed to run! Error: `cargo metadata` exited with an error: error: failed to load manifest for workspace member `\\?\C:\<workspace root>\lib\*`

Caused by:
  failed to read `\\?\C:\Proj\P2000\2way-paging-core\lib\*\Cargo.toml`

Caused by:
  The filename, directory name, or volume label syntax is incorrect. (os error 123)

Error: "Cargo failed to run! Error: `cargo metadata` exited with an error: error: failed to load manifest for workspace member `\\\\?\\C:\\<workspace root>\\lib\\*`\n\nCaused by:\n  failed to read `\\\\?\\C:\\<workspace root>\\lib\\*\\Cargo.toml`\n\nCaused by:\n  The filename, directory name, or volume label syntax is incorrect. (os error 123)\n"
xd009642 commented 1 year ago

Ugh I don't really use windows so this might take a bit of work, but it seems that issue might be because https://github.com/xd009642/tarpaulin/blob/develop/src/path_utils.rs#L9-L20 needs to be applied more liberally to paths in tarpaulin. Why I need to do fix paths in this way I have no idea - maybe someone who uses windows could chip in?

I guess applying some debug printouts here https://github.com/xd009642/tarpaulin/blob/develop/src/cargo.rs#L227 and seeing if unc paths need fixing and then going from there. Kinda curious how it doesn't flag as an issue in tarpaulin's tests :thinking:

xd009642 commented 1 year ago

@eminence if you try the latest release this should hopefully now work - a lot of windows issues tackled in this one :smile:

eminence commented 1 year ago

@xd009642 thank you! I tested the above scenario with the latest develop branch (8822e5d36300f24265eb51a46bfa0b38f62aeb34) and things are now working as expected 🎉

xd009642 commented 1 year ago

Awesome, latest develop is also same as 0.24.0 release so can install from crates.io or use binstall etc as well if you prefer :smile: