Skip to content

Commit c5318a1

Browse files
committed
Add some more information to verbose version.
1 parent dea587a commit c5318a1

File tree

4 files changed

+72
-3
lines changed

4 files changed

+72
-3
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ cargo-platform = { path = "crates/cargo-platform", version = "0.1.2" }
2525
cargo-util = { path = "crates/cargo-util", version = "0.1.1" }
2626
crates-io = { path = "crates/crates-io", version = "0.33.0" }
2727
crossbeam-utils = "0.8"
28-
curl = { version = "0.4.38", features = ["http2"] }
29-
curl-sys = "0.4.48"
28+
curl = { version = "0.4.39", features = ["http2"] }
29+
curl-sys = "0.4.49"
3030
env_logger = "0.9.0"
3131
pretty_env_logger = { version = "0.4", optional = true }
3232
anyhow = "1.0"

build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ use std::path::Path;
55

66
fn main() {
77
compress_man();
8+
println!(
9+
"cargo:rustc-env=RUST_HOST_TARGET={}",
10+
std::env::var("TARGET").unwrap()
11+
);
812
}
913

1014
fn compress_man() {

src/bin/cargo/cli.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use cargo::{self, drop_print, drop_println, CliResult, Config};
44
use clap::{AppSettings, Arg, ArgMatches};
55
use itertools::Itertools;
66
use std::collections::HashMap;
7+
use std::fmt::Write;
78

89
use super::commands;
910
use super::list_commands;
@@ -173,10 +174,63 @@ pub fn get_version_string(is_verbose: bool) -> String {
173174
version_string.push_str(&format!("commit-date: {}\n", ci.commit_date));
174175
}
175176
}
177+
writeln!(version_string, "host: {}", env!("RUST_HOST_TARGET")).unwrap();
178+
add_libgit2(&mut version_string);
179+
add_curl(&mut version_string);
180+
add_ssl(&mut version_string);
176181
}
177182
version_string
178183
}
179184

185+
fn add_libgit2(version_string: &mut String) {
186+
let git2_v = git2::Version::get();
187+
let lib_v = git2_v.libgit2_version();
188+
let vendored = if git2_v.vendored() {
189+
format!("vendored")
190+
} else {
191+
format!("system")
192+
};
193+
writeln!(
194+
version_string,
195+
"libgit2: {}.{}.{} (sys:{} {})",
196+
lib_v.0,
197+
lib_v.1,
198+
lib_v.2,
199+
git2_v.crate_version(),
200+
vendored
201+
)
202+
.unwrap();
203+
}
204+
205+
fn add_curl(version_string: &mut String) {
206+
let curl_v = curl::Version::get();
207+
let vendored = if curl_v.vendored() {
208+
format!("vendored")
209+
} else {
210+
format!("system")
211+
};
212+
writeln!(
213+
version_string,
214+
"libcurl: {} (sys:{} {} ssl:{})",
215+
curl_v.version(),
216+
curl_sys::rust_crate_version(),
217+
vendored,
218+
curl_v.ssl_version().unwrap_or("none")
219+
)
220+
.unwrap();
221+
}
222+
223+
fn add_ssl(version_string: &mut String) {
224+
#[cfg(feature = "openssl")]
225+
{
226+
writeln!(version_string, "ssl: {}", openssl::version::version()).unwrap();
227+
}
228+
#[cfg(not(feature = "openssl"))]
229+
{
230+
let _ = version_string; // Silence unused warning.
231+
}
232+
}
233+
180234
fn expand_aliases(
181235
config: &mut Config,
182236
args: ArgMatches<'static>,

tests/testsuite/version.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Tests for displaying the cargo version.
22
3-
use cargo_test_support::project;
3+
use cargo_test_support::{cargo_process, project};
44

55
#[cargo_test]
66
fn simple() {
@@ -41,3 +41,14 @@ fn version_works_with_bad_target_dir() {
4141
.build();
4242
p.cargo("version").run();
4343
}
44+
45+
#[cargo_test]
46+
fn verbose() {
47+
// This is mainly to check that it doesn't explode.
48+
cargo_process("-vV")
49+
.with_stdout_contains(&format!("cargo {}", cargo::version()))
50+
.with_stdout_contains("host: [..]")
51+
.with_stdout_contains("libgit2: [..]")
52+
.with_stdout_contains("libcurl: [..]")
53+
.run();
54+
}

0 commit comments

Comments
 (0)