summaryrefslogtreecommitdiffstats
path: root/vendor/rustc_tools_util
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--vendor/rustc_tools_util/.cargo-checksum.json1
-rw-r--r--vendor/rustc_tools_util/Cargo.toml32
-rw-r--r--vendor/rustc_tools_util/LICENSE-APACHE (renamed from vendor/xflags/LICENSE-APACHE)2
-rw-r--r--vendor/rustc_tools_util/LICENSE-MIT (renamed from vendor/matches/LICENSE)4
-rw-r--r--vendor/rustc_tools_util/README.md62
-rw-r--r--vendor/rustc_tools_util/src/lib.rs162
6 files changed, 261 insertions, 2 deletions
diff --git a/vendor/rustc_tools_util/.cargo-checksum.json b/vendor/rustc_tools_util/.cargo-checksum.json
new file mode 100644
index 000000000..fa6b5aa1b
--- /dev/null
+++ b/vendor/rustc_tools_util/.cargo-checksum.json
@@ -0,0 +1 @@
+{"files":{"Cargo.toml":"19638c267dcbea07037fae9353aafa031a81bde979a48d3333d7400cabcb0560","LICENSE-APACHE":"7ce8f5804da3116a112112a3b6ace5f58977fccf878d48dc9b108cc5e26c298c","LICENSE-MIT":"f4acf81886b4abbe3b7938d279536763774b1f061cf25881652300726ada3bda","README.md":"f90d8251e2485a4a0b3ab1b136728e429fbde3b7d6ddb222dc58fd3bae169bd1","src/lib.rs":"d2a621ad6319d586b100f796dd3d2bac9624325df4fead4edf62f6486ac8f26a"},"package":"598f48ce2a421542b3e64828aa742b687cc1b91d2f96591cfdb7ac5988cd6366"} \ No newline at end of file
diff --git a/vendor/rustc_tools_util/Cargo.toml b/vendor/rustc_tools_util/Cargo.toml
new file mode 100644
index 000000000..44a165131
--- /dev/null
+++ b/vendor/rustc_tools_util/Cargo.toml
@@ -0,0 +1,32 @@
+# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
+#
+# When uploading crates to the registry Cargo will automatically
+# "normalize" Cargo.toml files for maximal compatibility
+# with all versions of Cargo and also rewrite `path` dependencies
+# to registry (e.g., crates.io) dependencies.
+#
+# If you are reading this file be aware that the original Cargo.toml
+# will likely look very different (and much more reasonable).
+# See Cargo.toml.orig for the original contents.
+
+[package]
+edition = "2018"
+name = "rustc_tools_util"
+version = "0.2.1"
+description = "small helper to generate version information for git packages"
+readme = "README.md"
+keywords = [
+ "rustc",
+ "tool",
+ "git",
+ "version",
+ "hash",
+]
+categories = ["development-tools"]
+license = "MIT OR Apache-2.0"
+repository = "https://github.com/rust-lang/rust-clippy"
+
+[dependencies]
+
+[features]
+deny-warnings = []
diff --git a/vendor/xflags/LICENSE-APACHE b/vendor/rustc_tools_util/LICENSE-APACHE
index 16fe87b06..0d62c3727 100644
--- a/vendor/xflags/LICENSE-APACHE
+++ b/vendor/rustc_tools_util/LICENSE-APACHE
@@ -186,7 +186,7 @@ APPENDIX: How to apply the Apache License to your work.
same "printed page" as the copyright notice for easier
identification within third-party archives.
-Copyright [yyyy] [name of copyright owner]
+Copyright 2014-2022 The Rust Project Developers
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
diff --git a/vendor/matches/LICENSE b/vendor/rustc_tools_util/LICENSE-MIT
index a7b759a49..b724b24aa 100644
--- a/vendor/matches/LICENSE
+++ b/vendor/rustc_tools_util/LICENSE-MIT
@@ -1,4 +1,6 @@
-Copyright (c) 2014-2016 Simon Sapin
+MIT License
+
+Copyright (c) 2014-2022 The Rust Project Developers
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
diff --git a/vendor/rustc_tools_util/README.md b/vendor/rustc_tools_util/README.md
new file mode 100644
index 000000000..e947f9c7e
--- /dev/null
+++ b/vendor/rustc_tools_util/README.md
@@ -0,0 +1,62 @@
+# rustc_tools_util
+
+A small tool to help you generate version information
+for packages installed from a git repo
+
+## Usage
+
+Add a `build.rs` file to your repo and list it in `Cargo.toml`
+````toml
+build = "build.rs"
+````
+
+List rustc_tools_util as regular AND build dependency.
+````toml
+[dependencies]
+rustc_tools_util = "0.2.1"
+
+[build-dependencies]
+rustc_tools_util = "0.2.1"
+````
+
+In `build.rs`, generate the data in your `main()`
+````rust
+fn main() {
+ println!(
+ "cargo:rustc-env=GIT_HASH={}",
+ rustc_tools_util::get_commit_hash().unwrap_or_default()
+ );
+ println!(
+ "cargo:rustc-env=COMMIT_DATE={}",
+ rustc_tools_util::get_commit_date().unwrap_or_default()
+ );
+ println!(
+ "cargo:rustc-env=RUSTC_RELEASE_CHANNEL={}",
+ rustc_tools_util::get_channel().unwrap_or_default()
+ );
+}
+
+````
+
+Use the version information in your main.rs
+````rust
+use rustc_tools_util::*;
+
+fn show_version() {
+ let version_info = rustc_tools_util::get_version_info!();
+ println!("{}", version_info);
+}
+````
+This gives the following output in clippy:
+`clippy 0.0.212 (a416c5e 2018-12-14)`
+
+
+## License
+
+Copyright 2014-2022 The Rust Project Developers
+
+Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+<LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+option. All files in the project carrying such notice may not be
+copied, modified, or distributed except according to those terms.
diff --git a/vendor/rustc_tools_util/src/lib.rs b/vendor/rustc_tools_util/src/lib.rs
new file mode 100644
index 000000000..01d25c531
--- /dev/null
+++ b/vendor/rustc_tools_util/src/lib.rs
@@ -0,0 +1,162 @@
+#![cfg_attr(feature = "deny-warnings", deny(warnings))]
+
+use std::env;
+
+#[macro_export]
+macro_rules! get_version_info {
+ () => {{
+ let major = env!("CARGO_PKG_VERSION_MAJOR").parse::<u8>().unwrap();
+ let minor = env!("CARGO_PKG_VERSION_MINOR").parse::<u8>().unwrap();
+ let patch = env!("CARGO_PKG_VERSION_PATCH").parse::<u16>().unwrap();
+ let crate_name = String::from(env!("CARGO_PKG_NAME"));
+
+ let host_compiler = option_env!("RUSTC_RELEASE_CHANNEL").map(str::to_string);
+ let commit_hash = option_env!("GIT_HASH").map(str::to_string);
+ let commit_date = option_env!("COMMIT_DATE").map(str::to_string);
+
+ VersionInfo {
+ major,
+ minor,
+ patch,
+ host_compiler,
+ commit_hash,
+ commit_date,
+ crate_name,
+ }
+ }};
+}
+
+// some code taken and adapted from RLS and cargo
+pub struct VersionInfo {
+ pub major: u8,
+ pub minor: u8,
+ pub patch: u16,
+ pub host_compiler: Option<String>,
+ pub commit_hash: Option<String>,
+ pub commit_date: Option<String>,
+ pub crate_name: String,
+}
+
+impl std::fmt::Display for VersionInfo {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ let hash = self.commit_hash.clone().unwrap_or_default();
+ let hash_trimmed = hash.trim();
+
+ let date = self.commit_date.clone().unwrap_or_default();
+ let date_trimmed = date.trim();
+
+ if (hash_trimmed.len() + date_trimmed.len()) > 0 {
+ write!(
+ f,
+ "{} {}.{}.{} ({hash_trimmed} {date_trimmed})",
+ self.crate_name, self.major, self.minor, self.patch,
+ )?;
+ } else {
+ write!(f, "{} {}.{}.{}", self.crate_name, self.major, self.minor, self.patch)?;
+ }
+
+ Ok(())
+ }
+}
+
+impl std::fmt::Debug for VersionInfo {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(
+ f,
+ "VersionInfo {{ crate_name: \"{}\", major: {}, minor: {}, patch: {}",
+ self.crate_name, self.major, self.minor, self.patch,
+ )?;
+ if self.commit_hash.is_some() {
+ write!(
+ f,
+ ", commit_hash: \"{}\", commit_date: \"{}\" }}",
+ self.commit_hash.clone().unwrap_or_default().trim(),
+ self.commit_date.clone().unwrap_or_default().trim()
+ )?;
+ } else {
+ write!(f, " }}")?;
+ }
+
+ Ok(())
+ }
+}
+
+#[must_use]
+pub fn get_commit_hash() -> Option<String> {
+ std::process::Command::new("git")
+ .args(["rev-parse", "--short", "HEAD"])
+ .output()
+ .ok()
+ .and_then(|r| String::from_utf8(r.stdout).ok())
+}
+
+#[must_use]
+pub fn get_commit_date() -> Option<String> {
+ std::process::Command::new("git")
+ .args(["log", "-1", "--date=short", "--pretty=format:%cd"])
+ .output()
+ .ok()
+ .and_then(|r| String::from_utf8(r.stdout).ok())
+}
+
+#[must_use]
+pub fn get_channel() -> String {
+ match env::var("CFG_RELEASE_CHANNEL") {
+ Ok(channel) => channel,
+ Err(_) => {
+ // if that failed, try to ask rustc -V, do some parsing and find out
+ match std::process::Command::new("rustc")
+ .arg("-V")
+ .output()
+ .ok()
+ .and_then(|r| String::from_utf8(r.stdout).ok())
+ {
+ Some(rustc_output) => {
+ if rustc_output.contains("beta") {
+ String::from("beta")
+ } else if rustc_output.contains("stable") {
+ String::from("stable")
+ } else {
+ // default to nightly if we fail to parse
+ String::from("nightly")
+ }
+ },
+ // default to nightly
+ None => String::from("nightly"),
+ }
+ },
+ }
+}
+
+#[cfg(test)]
+mod test {
+ use super::*;
+
+ #[test]
+ fn test_struct_local() {
+ let vi = get_version_info!();
+ assert_eq!(vi.major, 0);
+ assert_eq!(vi.minor, 2);
+ assert_eq!(vi.patch, 1);
+ assert_eq!(vi.crate_name, "rustc_tools_util");
+ // hard to make positive tests for these since they will always change
+ assert!(vi.commit_hash.is_none());
+ assert!(vi.commit_date.is_none());
+ }
+
+ #[test]
+ fn test_display_local() {
+ let vi = get_version_info!();
+ assert_eq!(vi.to_string(), "rustc_tools_util 0.2.1");
+ }
+
+ #[test]
+ fn test_debug_local() {
+ let vi = get_version_info!();
+ let s = format!("{vi:?}");
+ assert_eq!(
+ s,
+ "VersionInfo { crate_name: \"rustc_tools_util\", major: 0, minor: 2, patch: 1 }"
+ );
+ }
+}