cargo/util/
mod.rs

1use std::time::Duration;
2
3pub use self::canonical_url::CanonicalUrl;
4pub use self::config::{homedir, Config, ConfigValue};
5pub use self::dependency_queue::DependencyQueue;
6pub use self::diagnostic_server::RustfixDiagnosticServer;
7pub use self::errors::{internal, process_error};
8pub use self::errors::{CargoResult, CargoResultExt, CliResult, Test};
9pub use self::errors::{CargoTestError, CliError, ProcessError};
10pub use self::flock::{FileLock, Filesystem};
11pub use self::graph::Graph;
12pub use self::hex::{hash_u64, short_hash, to_hex};
13pub use self::into_url::IntoUrl;
14pub use self::into_url_with_base::IntoUrlWithBase;
15pub use self::lev_distance::{closest, closest_msg, lev_distance};
16pub use self::lockserver::{LockServer, LockServerClient, LockServerStarted};
17pub use self::paths::{bytes2path, dylib_path, join_paths, path2bytes};
18pub use self::paths::{dylib_path_envvar, normalize_path};
19pub use self::process_builder::{process, ProcessBuilder};
20pub use self::progress::{Progress, ProgressStyle};
21pub use self::queue::Queue;
22pub use self::read2::read2;
23pub use self::restricted_names::validate_package_name;
24pub use self::rustc::Rustc;
25pub use self::sha256::Sha256;
26pub use self::to_semver::ToSemver;
27pub use self::vcs::{existing_vcs_repo, FossilRepo, GitRepo, HgRepo, PijulRepo};
28pub use self::workspace::{
29    print_available_benches, print_available_binaries, print_available_examples,
30    print_available_tests,
31};
32
33mod canonical_url;
34pub mod command_prelude;
35pub mod config;
36pub mod cpu;
37mod dependency_queue;
38pub mod diagnostic_server;
39pub mod errors;
40mod flock;
41pub mod graph;
42pub mod hex;
43pub mod important_paths;
44pub mod into_url;
45mod into_url_with_base;
46pub mod job;
47pub mod lev_distance;
48mod lockserver;
49pub mod machine_message;
50pub mod network;
51pub mod paths;
52pub mod process_builder;
53pub mod profile;
54mod progress;
55mod queue;
56mod read2;
57pub mod restricted_names;
58pub mod rustc;
59mod sha256;
60pub mod to_semver;
61pub mod toml;
62mod vcs;
63mod workspace;
64
65pub fn elapsed(duration: Duration) -> String {
66    let secs = duration.as_secs();
67
68    if secs >= 60 {
69        format!("{}m {:02}s", secs / 60, secs % 60)
70    } else {
71        format!("{}.{:02}s", secs, duration.subsec_nanos() / 10_000_000)
72    }
73}
74
75/// Whether or not this running in a Continuous Integration environment.
76pub fn is_ci() -> bool {
77    std::env::var("CI").is_ok() || std::env::var("TF_BUILD").is_ok()
78}