Include prettyplease version in --version

This commit is contained in:
David Tolnay 2022-06-16 15:47:19 -07:00
parent c92f07e606
commit c5b8828563
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82
4 changed files with 25 additions and 5 deletions

4
Cargo.lock generated
View file

@ -515,9 +515,9 @@ dependencies = [
[[package]] [[package]]
name = "prettyplease" name = "prettyplease"
version = "0.1.11" version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f28f53e8b192565862cf99343194579a022eb9c7dd3a8d03134734803c7b3125" checksum = "e5355b9d4fc0cc607db0c2e93c7a035a32226bfa770e0c6fec504f0018015bad"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"syn", "syn",

View file

@ -16,7 +16,7 @@ autotests = false
atty = "0.2" atty = "0.2"
cargo-subcommand-metadata = "0.1" cargo-subcommand-metadata = "0.1"
clap = { version = "3.2.5", default-features = false, features = ["deprecated", "derive", "std", "suggestions"] } clap = { version = "3.2.5", default-features = false, features = ["deprecated", "derive", "std", "suggestions"] }
prettyplease = { version = "0.1", optional = true } prettyplease = { version = "0.1.12", optional = true }
proc-macro2 = "1.0" proc-macro2 = "1.0"
quote = { version = "1.0", default-features = false } quote = { version = "1.0", default-features = false }
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }

18
build.rs Normal file
View file

@ -0,0 +1,18 @@
use std::env;
use std::fs;
use std::path::PathBuf;
fn main() {
let mut version = env!("CARGO_PKG_VERSION").to_owned();
if cfg!(feature = "prettyplease") {
if let Ok(prettyplease_version) = env::var("DEP_PRETTYPLEASE01_VERSION") {
// TODO: Make this appear only if `--version --verbose` is used.
version.push_str(" + prettyplease ");
version.push_str(&prettyplease_version);
}
}
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let version_file = out_dir.join("version");
fs::write(version_file, version).unwrap();
}

View file

@ -4,13 +4,15 @@ use std::path::PathBuf;
use std::str::FromStr; use std::str::FromStr;
use syn_select::Selector; use syn_select::Selector;
const VERSION: &str = include_str!(concat!(env!("OUT_DIR"), "/version"));
#[derive(Parser)] #[derive(Parser)]
#[clap(bin_name = "cargo", version, author)] #[clap(bin_name = "cargo", version = VERSION, author)]
pub enum Opts { pub enum Opts {
/// Show the result of macro expansion. /// Show the result of macro expansion.
#[clap( #[clap(
name = "expand", name = "expand",
version, version = VERSION,
author, author,
setting = AppSettings::DeriveDisplayOrder, setting = AppSettings::DeriveDisplayOrder,
dont_collapse_args_in_usage = true dont_collapse_args_in_usage = true