diff options
author | Rust大闸蟹 <liaoymxsdl@sina.com> | 2021-01-23 03:14:51 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-22 20:14:51 +0100 |
commit | bcaf83532117c49e0f51864f59352630be1d0f90 (patch) | |
tree | c2b420a064836ff788cc4914700f2b45b1a9ab2e /src | |
parent | 5471007db928e5ad5bdaa24df54360451c9b4f18 (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
Diffstat (limited to 'src')
-rw-r--r-- | src/bug_report.rs | 33 | ||||
-rw-r--r-- | src/lib.rs | 5 | ||||
-rw-r--r-- | src/main.rs | 16 |
3 files changed, 39 insertions, 15 deletions
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") |