From c5318a17e74e59b90716279f0324cf362f3d3dbf Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 8 Oct 2021 12:19:24 -0700 Subject: [PATCH 1/3] Add some more information to verbose version. --- Cargo.toml | 4 +-- build.rs | 4 +++ src/bin/cargo/cli.rs | 54 ++++++++++++++++++++++++++++++++++++++ tests/testsuite/version.rs | 13 ++++++++- 4 files changed, 72 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2185d11e0e5..5a0e29f7f11 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,8 +25,8 @@ cargo-platform = { path = "crates/cargo-platform", version = "0.1.2" } cargo-util = { path = "crates/cargo-util", version = "0.1.1" } crates-io = { path = "crates/crates-io", version = "0.33.0" } crossbeam-utils = "0.8" -curl = { version = "0.4.38", features = ["http2"] } -curl-sys = "0.4.48" +curl = { version = "0.4.39", features = ["http2"] } +curl-sys = "0.4.49" env_logger = "0.9.0" pretty_env_logger = { version = "0.4", optional = true } anyhow = "1.0" diff --git a/build.rs b/build.rs index 8c33c72b098..68865b58fcf 100644 --- a/build.rs +++ b/build.rs @@ -5,6 +5,10 @@ use std::path::Path; fn main() { compress_man(); + println!( + "cargo:rustc-env=RUST_HOST_TARGET={}", + std::env::var("TARGET").unwrap() + ); } fn compress_man() { diff --git a/src/bin/cargo/cli.rs b/src/bin/cargo/cli.rs index 627d2ea0594..fdb28a9405b 100644 --- a/src/bin/cargo/cli.rs +++ b/src/bin/cargo/cli.rs @@ -4,6 +4,7 @@ use cargo::{self, drop_print, drop_println, CliResult, Config}; use clap::{AppSettings, Arg, ArgMatches}; use itertools::Itertools; use std::collections::HashMap; +use std::fmt::Write; use super::commands; use super::list_commands; @@ -173,10 +174,63 @@ pub fn get_version_string(is_verbose: bool) -> String { version_string.push_str(&format!("commit-date: {}\n", ci.commit_date)); } } + writeln!(version_string, "host: {}", env!("RUST_HOST_TARGET")).unwrap(); + add_libgit2(&mut version_string); + add_curl(&mut version_string); + add_ssl(&mut version_string); } version_string } +fn add_libgit2(version_string: &mut String) { + let git2_v = git2::Version::get(); + let lib_v = git2_v.libgit2_version(); + let vendored = if git2_v.vendored() { + format!("vendored") + } else { + format!("system") + }; + writeln!( + version_string, + "libgit2: {}.{}.{} (sys:{} {})", + lib_v.0, + lib_v.1, + lib_v.2, + git2_v.crate_version(), + vendored + ) + .unwrap(); +} + +fn add_curl(version_string: &mut String) { + let curl_v = curl::Version::get(); + let vendored = if curl_v.vendored() { + format!("vendored") + } else { + format!("system") + }; + writeln!( + version_string, + "libcurl: {} (sys:{} {} ssl:{})", + curl_v.version(), + curl_sys::rust_crate_version(), + vendored, + curl_v.ssl_version().unwrap_or("none") + ) + .unwrap(); +} + +fn add_ssl(version_string: &mut String) { + #[cfg(feature = "openssl")] + { + writeln!(version_string, "ssl: {}", openssl::version::version()).unwrap(); + } + #[cfg(not(feature = "openssl"))] + { + let _ = version_string; // Silence unused warning. + } +} + fn expand_aliases( config: &mut Config, args: ArgMatches<'static>, diff --git a/tests/testsuite/version.rs b/tests/testsuite/version.rs index 911b2360b0f..0e4632da6fd 100644 --- a/tests/testsuite/version.rs +++ b/tests/testsuite/version.rs @@ -1,6 +1,6 @@ //! Tests for displaying the cargo version. -use cargo_test_support::project; +use cargo_test_support::{cargo_process, project}; #[cargo_test] fn simple() { @@ -41,3 +41,14 @@ fn version_works_with_bad_target_dir() { .build(); p.cargo("version").run(); } + +#[cargo_test] +fn verbose() { + // This is mainly to check that it doesn't explode. + cargo_process("-vV") + .with_stdout_contains(&format!("cargo {}", cargo::version())) + .with_stdout_contains("host: [..]") + .with_stdout_contains("libgit2: [..]") + .with_stdout_contains("libcurl: [..]") + .run(); +} From 5a8be7ba213d4418801b35f6759be781a8662c77 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 11 Oct 2021 11:22:48 -0700 Subject: [PATCH 2/3] Add os to verbose version string. --- Cargo.toml | 1 + src/bin/cargo/cli.rs | 1 + tests/testsuite/version.rs | 1 + 3 files changed, 3 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 5a0e29f7f11..c9fa27f5eaf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,6 +48,7 @@ libgit2-sys = "0.12.24" memchr = "2.1.3" num_cpus = "1.0" opener = "0.5" +os_info = "3.0.7" percent-encoding = "2.0" rustfix = "0.6.0" semver = { version = "1.0.3", features = ["serde"] } diff --git a/src/bin/cargo/cli.rs b/src/bin/cargo/cli.rs index fdb28a9405b..81e9f1262ce 100644 --- a/src/bin/cargo/cli.rs +++ b/src/bin/cargo/cli.rs @@ -178,6 +178,7 @@ pub fn get_version_string(is_verbose: bool) -> String { add_libgit2(&mut version_string); add_curl(&mut version_string); add_ssl(&mut version_string); + writeln!(version_string, "os: {}", os_info::get()).unwrap(); } version_string } diff --git a/tests/testsuite/version.rs b/tests/testsuite/version.rs index 0e4632da6fd..a5e4676dd46 100644 --- a/tests/testsuite/version.rs +++ b/tests/testsuite/version.rs @@ -50,5 +50,6 @@ fn verbose() { .with_stdout_contains("host: [..]") .with_stdout_contains("libgit2: [..]") .with_stdout_contains("libcurl: [..]") + .with_stdout_contains("os: [..]") .run(); } From 9f5da7c01bf79676a15b7274f517d9ac67ba1661 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 11 Oct 2021 11:58:27 -0700 Subject: [PATCH 3/3] Add --verbose to bug report template. --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 68aeed3f77c..b7554b8f428 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -22,7 +22,7 @@ labels: C-bug **Notes** -Output of `cargo version`: +Output of `cargo version --verbose`: