From 6f5c0d2e0aa7dd8904f4105727819f711282eca2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Tue, 25 Dec 2018 16:44:44 +0100 Subject: [PATCH 1/2] rustc_tool_utils: expand Cargo.toml with a few keywords in preparation for crates.io release --- rustc_tools_util/Cargo.toml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rustc_tools_util/Cargo.toml b/rustc_tools_util/Cargo.toml index 020de6c3393..b73d7ca5606 100644 --- a/rustc_tools_util/Cargo.toml +++ b/rustc_tools_util/Cargo.toml @@ -2,5 +2,11 @@ name = "rustc_tools_util" version = "0.1.0" authors = ["Matthias Krüger "] +description = "small helper to generate version information for git packages" +repository = "https://github.com/rust-lang/rust-clippy" +readme = "README.md" +license = "MIT/Apache-2.0" +keywords = ["rustc", "tool", "git", "version", "hash"] +categories = ["development-tools"] edition = "2018" [dependencies] From 345fe6d6c6f3598d008e20a80d4df982e99ccf45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Tue, 25 Dec 2018 17:03:36 +0100 Subject: [PATCH 2/2] rustc_tools_util: add readme --- rustc_tools_util/README.md | 58 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 rustc_tools_util/README.md diff --git a/rustc_tools_util/README.md b/rustc_tools_util/README.md new file mode 100644 index 00000000000..b101f55e509 --- /dev/null +++ b/rustc_tools_util/README.md @@ -0,0 +1,58 @@ +# 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` +```` +build = "build.rs" +```` + +List rustc_tools_util as regular AND build dependency. +```` +[dependencies] +rustc_tools_util = "0.1" + +[build-dependencies] +rustc_tools_util = "0.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() + ); +} + +```` + +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-2018 The Rust Project Developers + +Licensed under the Apache License, Version 2.0 or the MIT license +, at your +option. All files in the project carrying such notice may not be +copied, modified, or distributed except according to those terms.