Skip to content

Commit

Permalink
add --nocapture message change, modify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stupendoussuperpowers committed Aug 9, 2023
1 parent de57e60 commit 67a0402
Show file tree
Hide file tree
Showing 144 changed files with 1,572 additions and 1,098 deletions.
276 changes: 160 additions & 116 deletions Cargo.lock

Large diffs are not rendered by default.

13 changes: 5 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ crates-io = { version = "0.38.0", path = "crates/crates-io" }
criterion = { version = "0.5.1", features = ["html_reports"] }
curl = "0.4.44"
curl-sys = "0.4.65"
env_logger = "0.10.0"
filetime = "0.2.21"
flate2 = { version = "1.0.26", default-features = false, features = ["zlib"] }
fwdansi = "1.1.0"
Expand All @@ -58,9 +57,8 @@ lazy_static = "1.4.0"
lazycell = "1.3.0"
libc = "0.2.147"
libgit2-sys = "0.15.2"
log = "0.4.19"
memchr = "2.5.0"
miow = "0.5.0"
miow = "0.6.0"
opener = "0.6.1"
openssl ="0.10.55"
os_info = "3.7.0"
Expand All @@ -69,7 +67,6 @@ pathdiff = "0.2"
percent-encoding = "2.3"
pkg-config = "0.3.27"
pretty_assertions = "1.4.0"
pretty_env_logger = "0.5.0"
proptest = "1.2.0"
pulldown-cmark = { version = "0.9.3", default-features = false }
rand = "0.8.5"
Expand All @@ -94,6 +91,8 @@ thiserror = "1.0.44"
time = { version = "0.3", features = ["parsing", "formatting", "serde"] }
toml = "0.7.6"
toml_edit = "0.19.14"
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
unicase = "2.6.0"
unicode-width = "0.1.10"
unicode-xid = "0.2.4"
Expand Down Expand Up @@ -132,7 +131,6 @@ clap = { workspace = true, features = ["wrap_help"] }
crates-io.workspace = true
curl = { workspace = true, features = ["http2"] }
curl-sys.workspace = true
env_logger.workspace = true
filetime.workspace = true
flate2.workspace = true
git2.workspace = true
Expand All @@ -153,13 +151,11 @@ jobserver.workspace = true
lazycell.workspace = true
libc.workspace = true
libgit2-sys.workspace = true
log.workspace = true
memchr.workspace = true
opener.workspace = true
os_info.workspace = true
pasetors.workspace = true
pathdiff.workspace = true
pretty_env_logger = { workspace = true, optional = true }
pulldown-cmark.workspace = true
rand.workspace = true
rustfix.workspace = true
Expand All @@ -178,6 +174,8 @@ termcolor.workspace = true
time.workspace = true
toml.workspace = true
toml_edit.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
unicase.workspace = true
unicode-width.workspace = true
unicode-xid.workspace = true
Expand Down Expand Up @@ -218,6 +216,5 @@ doc = false
[features]
vendored-openssl = ["openssl/vendored"]
vendored-libgit2 = ["libgit2-sys/vendored"]
pretty-env-logger = ["pretty_env_logger"]
# This is primarily used by rust-lang/rust distributing cargo the executable.
all-static = ['vendored-openssl', 'curl/static-curl', 'curl/force-system-lib-on-osx']
2 changes: 1 addition & 1 deletion crates/cargo-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ filetime.workspace = true
hex.workspace = true
jobserver.workspace = true
libc.workspace = true
log.workspace = true
same-file.workspace = true
shell-escape.workspace = true
tempfile.workspace = true
tracing.workspace = true
walkdir.workspace = true

[target.'cfg(target_os = "macos")'.dependencies]
Expand Down
20 changes: 10 additions & 10 deletions crates/cargo-util/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ pub fn mtime_recursive(path: &Path) -> Result<FileTime> {
Err(e) => {
// Ignore errors while walking. If Cargo can't access it, the
// build script probably can't access it, either.
log::debug!("failed to determine mtime while walking directory: {}", e);
tracing::debug!("failed to determine mtime while walking directory: {}", e);
None
}
})
Expand All @@ -252,7 +252,7 @@ pub fn mtime_recursive(path: &Path) -> Result<FileTime> {
// I'm not sure when this is really possible (maybe a
// race with unlinking?). Regardless, if Cargo can't
// read it, the build script probably can't either.
log::debug!(
tracing::debug!(
"failed to determine mtime while fetching symlink metadata of {}: {}",
e.path().display(),
err
Expand All @@ -271,7 +271,7 @@ pub fn mtime_recursive(path: &Path) -> Result<FileTime> {
// Can't access the symlink target. If Cargo can't
// access it, the build script probably can't access
// it either.
log::debug!(
tracing::debug!(
"failed to determine mtime of symlink target for {}: {}",
e.path().display(),
err
Expand All @@ -286,7 +286,7 @@ pub fn mtime_recursive(path: &Path) -> Result<FileTime> {
// I'm not sure when this is really possible (maybe a
// race with unlinking?). Regardless, if Cargo can't
// read it, the build script probably can't either.
log::debug!(
tracing::debug!(
"failed to determine mtime while fetching metadata of {}: {}",
e.path().display(),
err
Expand Down Expand Up @@ -314,7 +314,7 @@ pub fn set_invocation_time(path: &Path) -> Result<FileTime> {
"This file has an mtime of when this was started.",
)?;
let ft = mtime(&timestamp)?;
log::debug!("invocation time for {:?} is {}", path, ft);
tracing::debug!("invocation time for {:?} is {}", path, ft);
Ok(ft)
}

Expand Down Expand Up @@ -508,7 +508,7 @@ pub fn link_or_copy(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> Result<()>
}

fn _link_or_copy(src: &Path, dst: &Path) -> Result<()> {
log::debug!("linking {} to {}", src.display(), dst.display());
tracing::debug!("linking {} to {}", src.display(), dst.display());
if same_file::is_same_file(src, dst).unwrap_or(false) {
return Ok(());
}
Expand Down Expand Up @@ -567,7 +567,7 @@ fn _link_or_copy(src: &Path, dst: &Path) -> Result<()> {
};
link_result
.or_else(|err| {
log::debug!("link failed {}. falling back to fs::copy", err);
tracing::debug!("link failed {}. falling back to fs::copy", err);
fs::copy(src, dst).map(|_| ())
})
.with_context(|| {
Expand Down Expand Up @@ -598,8 +598,8 @@ pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> Result<u64> {
pub fn set_file_time_no_err<P: AsRef<Path>>(path: P, time: FileTime) {
let path = path.as_ref();
match filetime::set_file_times(path, time, time) {
Ok(()) => log::debug!("set file mtime {} to {}", path.display(), time),
Err(e) => log::warn!(
Ok(()) => tracing::debug!("set file mtime {} to {}", path.display(), time),
Err(e) => tracing::warn!(
"could not set mtime of {} to {}: {:?}",
path.display(),
time,
Expand All @@ -621,7 +621,7 @@ pub fn strip_prefix_canonical<P: AsRef<Path>>(
let safe_canonicalize = |path: &Path| match path.canonicalize() {
Ok(p) => p,
Err(e) => {
log::warn!("cannot canonicalize {:?}: {:?}", path, e);
tracing::warn!("cannot canonicalize {:?}: {:?}", path, e);
path.to_path_buf()
}
};
Expand Down
4 changes: 2 additions & 2 deletions crates/cargo-util/src/process_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ impl ProcessBuilder {
arg.push(tmp.path());
let mut cmd = self.build_command_without_args();
cmd.arg(arg);
log::debug!("created argfile at {} for {self}", tmp.path().display());
tracing::debug!("created argfile at {} for {self}", tmp.path().display());

let cap = self.get_args().map(|arg| arg.len() + 1).sum::<usize>();
let mut buf = Vec::with_capacity(cap);
Expand Down Expand Up @@ -558,7 +558,7 @@ fn piped(cmd: &mut Command, pipe_stdin: bool) -> &mut Command {

fn close_tempfile_and_log_error(file: NamedTempFile) {
file.close().unwrap_or_else(|e| {
log::warn!("failed to close temporary file: {e}");
tracing::warn!("failed to close temporary file: {e}");
});
}

Expand Down
4 changes: 2 additions & 2 deletions crates/xtask-bump-check/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ anyhow.workspace = true
cargo.workspace = true
cargo-util.workspace = true
clap.workspace = true
env_logger.workspace = true
git2.workspace = true
log.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
13 changes: 12 additions & 1 deletion crates/xtask-bump-check/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
mod xtask;

fn main() {
env_logger::init_from_env("CARGO_LOG");
setup_logger();

let cli = xtask::cli();
let matches = cli.get_matches();

Expand All @@ -13,3 +14,13 @@ fn main() {
cargo::exit_with_error(e, &mut config.shell())
}
}

// In sync with `src/bin/cargo/main.rs@setup_logger`.
fn setup_logger() {
let env = tracing_subscriber::EnvFilter::from_env("CARGO_LOG");

tracing_subscriber::fmt()
.with_writer(std::io::stderr)
.with_env_filter(env)
.init();
}
12 changes: 6 additions & 6 deletions crates/xtask-bump-check/src/xtask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fn bump_check(args: &clap::ArgMatches, config: &mut cargo::util::Config) -> Carg
for referenced_member in checkout_ws(&ws, &repo, referenced_commit)?.members() {
let Some(changed_member) = changed_members.get(referenced_member) else {
let name = referenced_member.name().as_str();
log::trace!("skipping {name}, may be removed or not published");
tracing::trace!("skipping {name}, may be removed or not published");
continue;
};

Expand Down Expand Up @@ -264,10 +264,10 @@ fn get_referenced_commit<'a>(
let referenced_commit = if rev_id == stable_commit.id() {
None
} else if rev_id == beta_commit.id() {
log::trace!("stable branch from `{}`", stable.name().unwrap().unwrap());
tracing::trace!("stable branch from `{}`", stable.name().unwrap().unwrap());
Some(stable_commit)
} else {
log::trace!("beta branch from `{}`", beta.name().unwrap().unwrap());
tracing::trace!("beta branch from `{}`", beta.name().unwrap().unwrap());
Some(beta_commit)
};

Expand All @@ -287,11 +287,11 @@ fn beta_and_stable_branch(repo: &git2::Repository) -> CargoResult<[git2::Branch<
let (branch, _) = branch?;
let name = branch.name()?.unwrap();
let Some((_, version)) = name.split_once("/rust-") else {
log::trace!("branch `{name}` is not in the format of `<remote>/rust-<semver>`");
tracing::trace!("branch `{name}` is not in the format of `<remote>/rust-<semver>`");
continue;
};
let Ok(version) = version.to_semver() else {
log::trace!("branch `{name}` is not a valid semver: `{version}`");
tracing::trace!("branch `{name}` is not a valid semver: `{version}`");
continue;
};
release_branches.push((version, branch));
Expand Down Expand Up @@ -380,7 +380,7 @@ fn check_crates_io<'a>(
}
};
if possibilities.is_empty() {
log::trace!("dep `{name}` has no version greater than or equal to `{current}`");
tracing::trace!("dep `{name}` has no version greater than or equal to `{current}`");
} else {
needs_bump.push(member);
}
Expand Down
3 changes: 3 additions & 0 deletions credential/cargo-credential/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
thiserror.workspace = true
time.workspace = true

[dev-dependencies]
snapbox = { workspace = true, features = ["examples"] }
30 changes: 29 additions & 1 deletion credential/cargo-credential/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Helper library for writing Cargo credential processes.
//! Helper library for writing Cargo credential providers.
//!
//! A credential process should have a `struct` that implements the `Credential` trait.
//! The `main` function should be called with an instance of that struct, such as:
Expand All @@ -8,6 +8,34 @@
//! cargo_credential::main(MyCredential);
//! }
//! ```
//!
//! While in the `perform` function, stdin and stdout will be re-attached to the
//! active console. This allows credential providers to be interactive if necessary.
//!
//! ## Error handling
//! ### [`Error::UrlNotSupported`]
//! A credential provider may only support some registry URLs. If this is the case
//! and an unsupported index URL is passed to the provider, it should respond with
//! [`Error::UrlNotSupported`]. Other credential providers may be attempted by Cargo.
//!
//! ### [`Error::NotFound`]
//! When attempting an [`Action::Get`] or [`Action::Logout`], if a credential can not
//! be found, the provider should respond with [`Error::NotFound`]. Other credential
//! providers may be attempted by Cargo.
//!
//! ### [`Error::OperationNotSupported`]
//! A credential provider might not support all operations. For example if the provider
//! only supports [`Action::Get`], [`Error::OperationNotSupported`] should be returned
//! for all other requests.
//!
//! ### [`Error::Other`]
//! All other errors go here. The error will be shown to the user in Cargo, including
//! the full error chain using [`std::error::Error::source`].
//!
//! ## Example
//! ```rust,ignore
#![doc = include_str!("../examples/file-provider.rs")]
//! ```
use serde::{Deserialize, Serialize};
use std::{
Expand Down
22 changes: 18 additions & 4 deletions src/bin/cargo/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,9 @@ pub fn cli() -> Command {
Command::new("cargo")
// Subcommands all count their args' display order independently (from 0),
// which makes their args interspersed with global args. This puts global args last.
.next_display_order(1000)
//
// We also want these to come before auto-generated `--help`
.next_display_order(800)
.allow_external_subcommands(true)
// Doesn't mix well with our list of common cargo commands. See clap-rs/clap#3108 for
// opening clap up to allow us to style our help template
Expand Down Expand Up @@ -586,9 +588,21 @@ See 'cargo help <command>' for more information on a specific command.\n",
.value_hint(clap::ValueHint::DirPath)
.value_parser(clap::builder::ValueParser::path_buf()),
)
.arg(flag("frozen", "Require Cargo.lock and cache are up to date").global(true))
.arg(flag("locked", "Require Cargo.lock is up to date").global(true))
.arg(flag("offline", "Run without accessing the network").global(true))
.arg(
flag("frozen", "Require Cargo.lock and cache are up to date")
.help_heading(heading::MANIFEST_OPTIONS)
.global(true),
)
.arg(
flag("locked", "Require Cargo.lock is up to date")
.help_heading(heading::MANIFEST_OPTIONS)
.global(true),
)
.arg(
flag("offline", "Run without accessing the network")
.help_heading(heading::MANIFEST_OPTIONS)
.global(true),
)
.arg(multi_opt("config", "KEY=VALUE", "Override a configuration value").global(true))
.arg(
Arg::new("unstable-features")
Expand Down
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ Example uses:
])
.arg_manifest_path()
.arg_package("Package to modify")
.arg_quiet()
.arg_dry_run("Don't actually write the manifest")
.arg_quiet()
.next_help_heading("Source")
.args([
clap::Arg::new("path")
Expand Down
Loading

0 comments on commit 67a0402

Please sign in to comment.