summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRust大闸蟹 <liaoymxsdl@sina.com>2021-01-23 03:14:51 +0800
committerGitHub <noreply@github.com>2021-01-22 20:14:51 +0100
commitbcaf83532117c49e0f51864f59352630be1d0f90 (patch)
treec2b420a064836ff788cc4914700f2b45b1a9ab2e
parent5471007db928e5ad5bdaa24df54360451c9b4f18 (diff)
build: Add additional build information to version and bug report (#2124)
* fix https://github.com/starship/starship/issues * cargo fmt * upgrade shadow-rs 0.5.6 * upgrade shadow-rs * update * complet bug_report infomation * cargo fmt * upgrade shadow-rs 0.5.11 * upgrade shadow-rs 0.5.14 * fixed:https://github.com/starship/starship/pull/2124#discussion_r559076634 fixed:https://github.com/starship/starship/pull/2124#discussion_r559076918 * add long_version * upgrade shadow-rs 0.5.19; adaptate clap version() use by shadow-rs clap_version() * fix unit test error * fix test error * upgrade shadow-rs 0.5.22 * upgrade shadow-rs 0.5.23
-rw-r--r--Cargo.lock11
-rw-r--r--Cargo.toml6
-rw-r--r--build.rs3
-rw-r--r--src/bug_report.rs33
-rw-r--r--src/lib.rs5
-rw-r--r--src/main.rs16
6 files changed, 59 insertions, 15 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 13138bfcf..6a60ff1d3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1263,6 +1263,16 @@ dependencies = [
]
[[package]]
+name = "shadow-rs"
+version = "0.5.23"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bb054640a4d209cbfcc56fa1d9f4a229d4aef3f9da130e7f5698aba36db1c6ce"
+dependencies = [
+ "chrono",
+ "git2",
+]
+
+[[package]]
name = "shell-words"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1301,6 +1311,7 @@ dependencies = [
"semver",
"serde",
"serde_json",
+ "shadow-rs",
"shell-words",
"starship_module_config_derive",
"sys-info",
diff --git a/Cargo.toml b/Cargo.toml
index d8fac6f1c..a4018b59f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -10,6 +10,7 @@ readme = "README.md"
license = "ISC"
keywords = ["prompt", "shell", "bash", "fish", "zsh"]
categories = ["command-line-utilities"]
+build = "build.rs"
description = """
The minimal, blazing-fast, and infinitely customizable prompt for any shell! ☄🌌️
"""
@@ -64,6 +65,8 @@ indexmap = "1.6.1"
notify-rust = { version = "4.2.2", optional = true }
semver = "0.11.0"
which = "4.0.2"
+shadow-rs = "0.5.23"
+
process_control = { version = "3.0.0", features = ["crossbeam-channel"] }
# Optional/http:
@@ -83,6 +86,9 @@ winapi = { version = "0.3.9", features = [
[target.'cfg(not(windows))'.dependencies]
nix = "0.19.1"
+[build-dependencies]
+shadow-rs = "0.5.23"
+
[dev-dependencies]
tempfile = "3.2.0"
diff --git a/build.rs b/build.rs
new file mode 100644
index 000000000..4a0dfc459
--- /dev/null
+++ b/build.rs
@@ -0,0 +1,3 @@
+fn main() -> shadow_rs::SdResult<()> {
+ shadow_rs::new()
+}
diff --git a/src/bug_report.rs b/src/bug_report.rs
index 7dc1f9779..983e4319c 100644
--- a/src/bug_report.rs
+++ b/src/bug_report.rs
@@ -1,6 +1,6 @@
+use crate::shadow;
use crate::utils::exec_cmd;
-use clap::crate_version;
use std::fs;
use std::path::PathBuf;
@@ -8,6 +8,7 @@ use std::path::PathBuf;
const GIT_IO_BASE_URL: &str = "https://git.io/";
pub fn create() {
+ println!("{}\n", shadow::version().trim());
let os_info = os_info::get();
let environment = Environment {
@@ -18,7 +19,7 @@ pub fn create() {
starship_config: get_starship_config(),
};
- let link = make_github_issue_link(crate_version!(), environment);
+ let link = make_github_issue_link(environment);
let short_link = shorten_link(&link);
if open::that(&link)
@@ -63,7 +64,14 @@ struct Environment {
starship_config: String,
}
-fn make_github_issue_link(starship_version: &str, environment: Environment) -> String {
+fn get_pkg_branch_tag() -> &'static str {
+ if !shadow::TAG.is_empty() {
+ return shadow::TAG;
+ }
+ shadow::BRANCH
+}
+
+fn make_github_issue_link(environment: Environment) -> String {
let body = urlencoding::encode(&format!("#### Current Behavior
<!-- A clear and concise description of the behavior. -->
@@ -81,7 +89,11 @@ fn make_github_issue_link(starship_version: &str, environment: Environment) -> S
- {shell_name} version: {shell_version}
- Operating system: {os_name} {os_version}
- Terminal emulator: {terminal_name} {terminal_version}
-
+- Git Commit Hash: {git_commit_hash}
+- Branch/Tag: {pkg_branch_tag}
+- Rust Version: {rust_version}
+- Rust channel: {rust_channel} {build_rust_channel}
+- Build Time: {build_time}
#### Relevant Shell Configuration
```bash
@@ -93,7 +105,7 @@ fn make_github_issue_link(starship_version: &str, environment: Environment) -> S
```toml
{starship_config}
```",
- starship_version = starship_version,
+ starship_version = shadow::PKG_VERSION,
shell_name = environment.shell_info.name,
shell_version = environment.shell_info.version,
terminal_name = environment.terminal_info.name,
@@ -102,6 +114,12 @@ fn make_github_issue_link(starship_version: &str, environment: Environment) -> S
os_version = environment.os_version,
shell_config = environment.shell_info.config,
starship_config = environment.starship_config,
+ git_commit_hash = shadow::SHORT_COMMIT,
+ pkg_branch_tag = get_pkg_branch_tag(),
+ rust_version = shadow::RUST_VERSION,
+ rust_channel = shadow::RUST_CHANNEL,
+ build_rust_channel = shadow::BUILD_RUST_CHANNEL,
+ build_time = shadow::BUILD_TIME,
))
.replace("%20", "+");
@@ -212,7 +230,6 @@ mod tests {
#[test]
fn test_make_github_link() {
- let starship_version = "0.1.2";
let environment = Environment {
os_type: os_info::Type::Linux,
os_version: os_info::Version::Semantic(1, 2, 3),
@@ -228,9 +245,9 @@ mod tests {
starship_config: "No Starship config".to_string(),
};
- let link = make_github_issue_link(starship_version, environment);
+ let link = make_github_issue_link(environment);
- assert!(link.contains(starship_version));
+ assert!(link.contains(clap::crate_version!()));
assert!(link.contains("Linux"));
assert!(link.contains("1.2.3"));
assert!(link.contains("test_shell"));
diff --git a/src/lib.rs b/src/lib.rs
index fb2361b86..09beaceac 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,3 +1,8 @@
+#[macro_use]
+extern crate shadow_rs;
+
+shadow!(shadow);
+
// Lib is present to allow for benchmarking
pub mod bug_report;
pub mod config;
diff --git a/src/main.rs b/src/main.rs
index 1224e08a2..bbaa20fb4 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,4 +1,4 @@
-use clap::{crate_authors, crate_version};
+use clap::crate_authors;
use std::io;
use std::time::SystemTime;
@@ -29,11 +29,11 @@ fn main() {
.takes_value(true);
let shell_arg = Arg::with_name("shell")
- .value_name("SHELL")
- .help(
- "The name of the currently running shell\nCurrently supported options: bash, zsh, fish, powershell, ion",
- )
- .required(true);
+ .value_name("SHELL")
+ .help(
+ "The name of the currently running shell\nCurrently supported options: bash, zsh, fish, powershell, ion",
+ )
+ .required(true);
let cmd_duration_arg = Arg::with_name("cmd_duration")
.short("d")
@@ -61,10 +61,12 @@ fn main() {
.long("print-full-init")
.help("Print the main initialization script (as opposed to the init stub)");
+ let long_version = crate::shadow::clap_version();
let mut app = App::new("starship")
.about("The cross-shell prompt for astronauts. ☄🌌️")
// pull the version number from Cargo.toml
- .version(crate_version!())
+ .version(shadow::PKG_VERSION)
+ .long_version(long_version.as_str())
// pull the authors from Cargo.toml
.author(crate_authors!())
.after_help("https://github.com/starship/starship")