-
Notifications
You must be signed in to change notification settings - Fork 912
xtask: add coverage command #2067
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [alias] | ||
| xtask = "run --package xtask --" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| [package] | ||
| name = "xtask" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
|
|
||
| [dependencies] | ||
| anyhow = "1.0.51" | ||
| clap = { version = "3.0.0-rc.7", features = ["derive"] } | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| use anyhow::Result; | ||
| use clap::Parser; | ||
| use std::{collections::HashMap, process::Command}; | ||
|
|
||
| #[derive(Parser)] | ||
| enum Subcommand { | ||
| Coverage, | ||
| } | ||
|
|
||
| fn main() -> Result<()> { | ||
| match Subcommand::parse() { | ||
| Subcommand::Coverage => { | ||
| run(&mut llvm_cov_command(&["clean", "--workspace"]))?; | ||
| // FIXME: run (including with various feature combinations) | ||
| // run(&mut llvm_cov_command(&["--no-report"]))?; | ||
| let env = get_coverage_env()?; | ||
| for entry in std::fs::read_dir("pytests")? { | ||
| let path = entry?.path(); | ||
| if path.is_dir() { | ||
| run(Command::new("tox").arg("-c").arg(path).envs(&env))?; | ||
| } | ||
| } | ||
| // FIXME: also run for examples | ||
| // FIXME: make it possible to generate lcov report too | ||
| run(&mut llvm_cov_command(&["--no-run", "--summary-only"]))?; | ||
| } | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn run(command: &mut Command) -> Result<()> { | ||
| command.spawn()?.wait()?; | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn llvm_cov_command(args: &[&str]) -> Command { | ||
| let mut command = Command::new("cargo"); | ||
| command.args(["llvm-cov", "--package=pyo3"]).args(args); | ||
| command | ||
| } | ||
|
|
||
| fn get_coverage_env() -> Result<HashMap<String, String>> { | ||
| let mut env = HashMap::new(); | ||
|
|
||
| let output = String::from_utf8(llvm_cov_command(&["show-env"]).output()?.stdout)?; | ||
|
|
||
| for line in output.trim().split('\n') { | ||
| // TODO use split_once on MSRV 1.52 | ||
| let mut iter = line.splitn(2, '='); | ||
| env.insert(iter.next().unwrap().into(), iter.next().unwrap().trim_matches('"').into()); | ||
| } | ||
|
|
||
| env.insert("TOX_TESTENV_PASSENV".to_owned(), "*".to_owned()); | ||
| env.insert("RUSTUP_TOOLCHAIN".to_owned(), "nightly".to_owned()); | ||
|
|
||
| Ok(env) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't necessarily need to name this "xtask". I don't have a motivation for changing it. But we could.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I don't personally love the name xtask but I do like that it's a documented "approach" (https://github.com/matklad/cargo-xtask), so without good motivation I don't feel a need to change it.
For example I'd personally enjoy the alias being called
cargo run-script. There's nothing stopping us adding a couple extra aliases that all do the same later, if we wanted ;)