taiki-e / cargo-llvm-cov

Cargo subcommand to easily use LLVM source-based code coverage (-C instrument-coverage).
Apache License 2.0
858 stars 57 forks source link

Failed to load coverage: *.rmeta The file was not recognized as a valid object file #342

Closed ktmeaton closed 5 months ago

ktmeaton commented 5 months ago

Related to #316, when using the --doc flag on WSL, the .rmeta files are executable and generate the error:

" Failed to load coverage: 'target/llvm-cov-target/debug/deps/libmagic-2321c11047278672.rmeta': The file was not recognized as a valid object file".

Re-using the minimal working example from #316:

$ git clone --branch v0.15.0 https://github.com/robo9k/rust-magic.git

$ cd rust-magic

$ cargo +nightly --version
cargo 1.77.0-nightly (84976cd69 2024-01-12)

$ cargo +nightly llvm-cov --version
cargo-llvm-cov 0.6.2

The following command finishes successfully in WSL (thanks to .d files being ignored from #317?):

$ cargo +nightly llvm-cov

test result: ok. 8 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.02s

But the --doc flag introduces errors:

$ cargo +nightly llvm-cov --doc

error: Failed to load coverage: 'target/llvm-cov-target/debug/deps/libmagic-2321c11047278672.rmeta': The file was not recognized as a valid object file
error: failed to generate report: process didn't exit successfully:

With the failing process being llvm-cov report:

/home/$USER/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-cov report \
  -instr-profile=target/llvm-cov-target/rust-magic.profdata \
  -object target/llvm-cov-target/debug/deps/libmagic-2321c11047278672.rlib \
  -object target/llvm-cov-target/debug/deps/libmagic-2321c11047278672.rmeta \
  -object target/llvm-cov-target/doctestbins/src_lib_rs_120_0/rust_out \
  -object target/llvm-cov-target/doctestbins/src_lib_rs_35_0/rust_out \
  -object target/llvm-cov-target/doctestbins/src_lib_rs_436_0/rust_out \
  -object target/llvm-cov-target/doctestbins/src_lib_rs_617_0/rust_out \
  -ignore-filename-regex '/rustc/([0-9a-f]+|[0-9]+\.[0-9]+\.[0-9]+)/|^/mnt/c/Users/$USER/Projects/rust\-magic(/.*)?/(tests|examples|benches)/|^/mnt/c/Users/$USER/Projects/rust\-magic/target/llvm\-cov\-target($|/)|^/home/$USER/\.cargo/(registry|git)/|^/home/$USER/\.rustup/toolchains($|/)'

If I remove the rmeta file as a candidate object, it works perfectly!

/home/$USER/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-cov report \
  -instr-profile=target/llvm-cov-target/rust-magic.profdata \
  -object target/llvm-cov-target/debug/deps/libmagic-2321c11047278672.rlib \
  -object target/llvm-cov-target/doctestbins/src_lib_rs_120_0/rust_out \
  -object target/llvm-cov-target/doctestbins/src_lib_rs_35_0/rust_out \
  -object target/llvm-cov-target/doctestbins/src_lib_rs_436_0/rust_out \
  -object target/llvm-cov-target/doctestbins/src_lib_rs_617_0/rust_out \
  -ignore-filename-regex '/rustc/([0-9a-f]+|[0-9]+\.[0-9]+\.[0-9]+)/|^/mnt/c/Users/$USER/Projects/rust\-magic(/.*)?/(tests|examples|benches)/|^/mnt/c/Users/$USER/Projects/rust\-magic/target/llvm\-cov\-target($|/)|^/home/$USER/\.cargo/(registry|git)/|^/home/$USER/\.rustup/toolchains($|/)'

Could the .rmeta files on WSL be ignored as objects, similar to the .d files from #317?

taiki-e commented 5 months ago

Thanks for the report!

Could the .rmeta files on WSL be ignored as objects, similar to the .d files from #317?

Yeah, .rmeta should be handled in the same way as .d.

taiki-e commented 5 months ago

Fixed in 0.6.3 (#343).

ktmeaton commented 5 months ago

Works perfectly now, thank you so much!