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

cli: add show-env subcommand #115

Merged
merged 5 commits into from Jan 1, 2022
Merged

cli: add show-env subcommand #115

merged 5 commits into from Jan 1, 2022

Conversation

davidhewitt
Copy link
Sponsor Contributor

Implements the show-env suggestion from #93 (comment)

An example output:

$ cargo llvm-cov show-env
RUSTFLAGS=" -Z instrument-coverage --remap-path-prefix /home/david/dev/pyo3/= --cfg coverage --cfg trybuild_no_target"
LLVM_PROFILE_FILE="/home/david/dev/pyo3/target/llvm-cov-target/pyo3-%m.profraw"
CARGO_INCREMENTAL="0"
CARGO_TARGET_DIR="/home/david/dev/pyo3/target/llvm-cov-target"

After exporting these vars, I had a go at building pyo3's cdylib examples and then running them with pytest.

Pleased to see that I do get profile output in the expected location:

$ ls target/llvm-cov-target/
CACHEDIR.TAG                         pyo3-6622988374613674511_0.profraw
debug                                pyo3-8390305564713967804_0.profraw
pyo3-10144924340354712083_0.profraw  pyo3-8655209440434687052_0.profraw
pyo3-12448306348928428713_0.profraw  pyo3-9115749969700858718_0.profraw
pyo3-13212718739740305352_0.profraw  pyo3-9296542518232051450_0.profraw
pyo3-17208771140764127027_0.profraw  pyo3.profdata
pyo3-40338836728015828_0.profraw     release
pyo3-5761173678925874245_0.profraw   wheels
pyo3-6135639819960792837_0.profraw

There's still some pain points:

  1. I need to unset CARGO_TARGET_DIR before attempting to run cargo llvm-cov command, or I get crashes because it tries to append llvm-cov-target for a second time:
$ cargo llvm-cov --no-run --summary-only
error: no input files specified. See llvm-profdata merge -help
error: failed to merge profile data: process didn't exit successfully: `/home/david/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-profdata merge -sparse -o /home/david/dev/pyo3/target/llvm-cov-target/llvm-cov-target/pyo3.profdata` (exit status: 1)
  1. After unsetting CARGO_TARGET_DIR, I still get a failure to generate the report. I suspect this is because cargo-llvm-cov is not finding and passing the cdylib outputs to llvm-cov report?
$ cargo llvm-cov --no-run --summary-only --verbose
   Running `/home/david/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-profdata merge -sparse /home/david/dev/pyo3/target/llvm-cov-target/pyo3-10144924340354712083_0.profraw /home/david/dev/pyo3/target/llvm-cov-target/pyo3-12448306348928428713_0.profraw /home/david/dev/pyo3/target/llvm-cov-target/pyo3-13212718739740305352_0.profraw /home/david/dev/pyo3/target/llvm-cov-target/pyo3-17208771140764127027_0.profraw /home/david/dev/pyo3/target/llvm-cov-target/pyo3-40338836728015828_0.profraw /home/david/dev/pyo3/target/llvm-cov-target/pyo3-5761173678925874245_0.profraw /home/david/dev/pyo3/target/llvm-cov-target/pyo3-6135639819960792837_0.profraw /home/david/dev/pyo3/target/llvm-cov-target/pyo3-6622988374613674511_0.profraw /home/david/dev/pyo3/target/llvm-cov-target/pyo3-8390305564713967804_0.profraw /home/david/dev/pyo3/target/llvm-cov-target/pyo3-8655209440434687052_0.profraw /home/david/dev/pyo3/target/llvm-cov-target/pyo3-9115749969700858718_0.profraw /home/david/dev/pyo3/target/llvm-cov-target/pyo3-9296542518232051450_0.profraw -o /home/david/dev/pyo3/target/llvm-cov-target/pyo3.profdata`
   Running `/home/david/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-cov report -instr-profile=/home/david/dev/pyo3/target/llvm-cov-target/pyo3.profdata -ignore-filename-regex '(^|/)(rustc/[0-9a-f]+|(\.)?cargo/(registry|git)|(\.)?rustup/toolchains|tests|examples|benches|target/llvm-cov-target)/|^/home/david/|^pyo3-macros/|^pyo3-macros-backend/|^pyo3-build-config/|^examples/|^xtask/'`
No filenames specified!
error: failed to generate report: process didn't exit successfully: `/home/david/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-cov report -instr-profile=/home/david/dev/pyo3/target/llvm-cov-target/pyo3.profdata -ignore-filename-regex '(^|/)(rustc/[0-9a-f]+|(\.)?cargo/(registry|git)|(\.)?rustup/toolchains|tests|examples|benches|target/llvm-cov-target)/|^/home/david/|^pyo3-macros/|^pyo3-macros-backend/|^pyo3-build-config/|^examples/|^xtask/'` (exit status: 1)

If you're interested, you can see the companion PyO3 at PyO3/pyo3#2067

@taiki-e
Copy link
Owner

taiki-e commented Dec 22, 2021

Thanks!

I need to unset CARGO_TARGET_DIR before attempting to run cargo llvm-cov command

We are going to remove this environment variable in #112. Perhaps that will fix this problem?

After unsetting CARGO_TARGET_DIR, I still get a failure to generate the report. I suspect this is because cargo-llvm-cov is not finding and passing the cdylib outputs to llvm-cov report?

Hmm... I'll take a look later.

src/main.rs Outdated Show resolved Hide resolved
@davidhewitt
Copy link
Sponsor Contributor Author

We are going to remove this environment variable in #112. Perhaps that will fix this problem?

Yep, rebasing has fixed that, nice 👍

It may be useful to have an option to output environment variables with the export prefix.

Added. Note you can use this one-liner even:

source <(cargo llvm-cov show-env --export-prefix)

@davidhewitt
Copy link
Sponsor Contributor Author

Pushed some tidy and test fixes, and added a short note to the README based on the comment in #93.

Copy link
Owner

@taiki-e taiki-e left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

README.md Outdated Show resolved Hide resolved
@taiki-e
Copy link
Owner

taiki-e commented Jan 1, 2022

bors r+

@bors
Copy link
Contributor

bors bot commented Jan 1, 2022

Build succeeded!

And happy new year! 🎉

@bors bors bot merged commit 6c7c9d5 into taiki-e:main Jan 1, 2022
@davidhewitt davidhewitt deleted the show-env branch January 1, 2022 13:14
@davidhewitt
Copy link
Sponsor Contributor Author

Thanks, sorry for the slow review turnaround, have been busy over the festive season!

@taiki-e
Copy link
Owner

taiki-e commented Jan 6, 2022

Published in 0.1.14.

sorry for the slow review turnaround

No problem. (The only reason I applied the changes myself was to avoid conflicts with a subsequent huge patch.)

@taiki-e
Copy link
Owner

taiki-e commented Jan 6, 2022

2. After unsetting CARGO_TARGET_DIR, I still get a failure to generate the report. I suspect this is because cargo-llvm-cov is not finding and passing the cdylib outputs to llvm-cov report?

IIUC, the problem is that cargo-llvm-cov and cargo refer to different build artists, so I guess it will work if passing --target-dir target/llvm-cov-target to cargo build.

bors bot added a commit that referenced this pull request Jan 6, 2022
121: Fix show-env subcommand bug r=taiki-e a=taiki-e

This fixes the problem that the readme example does not work.
This probably fixes the remaining problem reported in #115.

cc #93
cc `@davidhewitt` 


Co-authored-by: Taiki Endo <te316e89@gmail.com>
@davidhewitt
Copy link
Sponsor Contributor Author

IIUC, the problem is that cargo-llvm-cov and cargo refer to different build artists, so I guess it will work if passing --target-dir target/llvm-cov-target to cargo build.

Turns out it was partly this and also that for various reasons some of the build output was going into the release dir instead of debug. I have nearly got a working implementation with cargo llvm-cov show-env at PyO3/pyo3#2105

Thanks again!

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

Successfully merging this pull request may close these issues.

None yet

2 participants