xtask: support MSRV
This commit is contained in:
parent
d600a8c3a3
commit
f344c23928
|
@ -1,8 +1,11 @@
|
|||
[package]
|
||||
name = "xtask"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.51"
|
||||
clap = { version = "3.0.0-rc.7", features = ["derive"] }
|
||||
|
||||
# Clap 3 requires MSRV 1.54
|
||||
rustversion = "1.0"
|
||||
structopt = { version = "0.3", default-features = false }
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use anyhow::{Context, Result};
|
||||
use clap::Parser;
|
||||
use std::{collections::HashMap, process::Command};
|
||||
use structopt::StructOpt;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[derive(StructOpt)]
|
||||
enum Subcommand {
|
||||
/// Runs `cargo llvm-cov` for the PyO3 codebase.
|
||||
Coverage,
|
||||
|
@ -20,7 +20,7 @@ impl Subcommand {
|
|||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
Subcommand::parse().execute()
|
||||
Subcommand::from_args().execute()
|
||||
}
|
||||
|
||||
/// Runs `cargo llvm-cov` for the PyO3 codebase.
|
||||
|
@ -42,18 +42,14 @@ fn subcommand_coverage() -> Result<()> {
|
|||
}
|
||||
|
||||
fn run(command: &mut Command) -> Result<()> {
|
||||
print!("running: {}", command.get_program().to_string_lossy());
|
||||
for arg in command.get_args() {
|
||||
print!(" {}", arg.to_string_lossy());
|
||||
}
|
||||
println!();
|
||||
println!("running: {}", format_command(command));
|
||||
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.args(&["llvm-cov", "--package=pyo3"]).args(args);
|
||||
command
|
||||
}
|
||||
|
||||
|
@ -92,7 +88,32 @@ fn get_coverage_env() -> Result<HashMap<String, String>> {
|
|||
}
|
||||
|
||||
// Replacement for str.split_once() on Rust older than 1.52
|
||||
#[rustversion::before(1.52)]
|
||||
fn split_once(s: &str, pat: char) -> Option<(&str, &str)> {
|
||||
let mut iter = s.splitn(2, pat);
|
||||
Some((iter.next()?, iter.next()?))
|
||||
}
|
||||
|
||||
#[rustversion::since(1.52)]
|
||||
fn split_once(s: &str, pat: char) -> Option<(&str, &str)> {
|
||||
s.split_once(pat)
|
||||
}
|
||||
|
||||
#[rustversion::since(1.57)]
|
||||
fn format_command(command: &Command) -> String {
|
||||
let mut buf = String::new();
|
||||
buf.push('`');
|
||||
buf.push_str(&command.get_program().to_string_lossy());
|
||||
for arg in command.get_args() {
|
||||
buf.push(' ');
|
||||
buf.push_str(&arg.to_string_lossy());
|
||||
}
|
||||
buf.push('`');
|
||||
buf
|
||||
}
|
||||
|
||||
#[rustversion::before(1.57)]
|
||||
fn format_command(command: &Command) -> String {
|
||||
// Debug impl isn't as nice as the above, but will do on < 1.57
|
||||
format!("{:?}", command)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue