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
This commit is contained in:
Rust大闸蟹 2021-01-23 03:14:51 +08:00 committed by GitHub
parent 5471007db9
commit bcaf835321
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 59 additions and 15 deletions

11
Cargo.lock generated
View File

@ -1262,6 +1262,16 @@ dependencies = [
"opaque-debug",
]
[[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"
@ -1301,6 +1311,7 @@ dependencies = [
"semver",
"serde",
"serde_json",
"shadow-rs",
"shell-words",
"starship_module_config_derive",
"sys-info",

View File

@ -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"

3
build.rs Normal file
View File

@ -0,0 +1,3 @@
fn main() -> shadow_rs::SdResult<()> {
shadow_rs::new()
}

View File

@ -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"));

View File

@ -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;

View File

@ -1,4 +1,4 @@
use clap::{crate_authors, crate_version};
use clap::crate_authors;
use std::io;
use std::time::SystemTime;
@ -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")