Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/xtask-bump-check/src/xtask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ fn global_context_configure(gctx: &mut GlobalContext, args: &ArgMatches) -> CliR
// quiet is unusual because it is redefined in some subcommands in order
// to provide custom help text.
let quiet = args.flag("quiet");
let is_manifest = false; // TODO
let color = args.get_one::<String>("color").map(String::as_str);
let frozen = args.flag("frozen");
let locked = args.flag("locked");
Expand All @@ -97,6 +98,7 @@ fn global_context_configure(gctx: &mut GlobalContext, args: &ArgMatches) -> CliR
gctx.configure(
verbose,
quiet,
is_manifest,
color,
frozen,
locked,
Expand Down
6 changes: 5 additions & 1 deletion src/bin/cargo/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,10 @@ fn configure_gctx(
let mut quiet = args.flag("quiet")
|| subcommand_args.map(|a| a.flag("quiet")).unwrap_or_default()
|| global_args.quiet;
if matches!(exec, Some(Exec::Manifest(_))) && !quiet {

let is_manifest = matches!(exec, Some(Exec::Manifest(_)));

if is_manifest && !quiet {
// Verbosity is shifted quieter for `Exec::Manifest` as it is can be used as if you ran
// `cargo install` and we especially shouldn't pollute programmatic output.
//
Expand Down Expand Up @@ -449,6 +452,7 @@ fn configure_gctx(
gctx.configure(
verbose,
quiet,
is_manifest,
color,
frozen,
locked,
Expand Down
7 changes: 7 additions & 0 deletions src/cargo/core/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ pub struct Compilation<'gctx> {

/// The total number of lint warnings emitted by the compilation.
pub lint_warning_count: usize,

/// Were all compiled units up to date? This is initialised to true
/// and then set to false if we have to actually compile anything, instead
/// of using cached artifacts. This is used by `cargo script` to suppress
/// cargo messages when the script is already built.
pub unchanged: bool,
}

impl<'gctx> Compilation<'gctx> {
Expand Down Expand Up @@ -170,6 +176,7 @@ impl<'gctx> Compilation<'gctx> {
.map(|kind| Ok((*kind, target_linker(bcx, *kind)?)))
.collect::<CargoResult<HashMap<_, _>>>()?,
lint_warning_count: 0,
unchanged: true,
})
}

Expand Down
8 changes: 7 additions & 1 deletion src/cargo/core/compiler/job_queue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,13 @@ impl<'gctx> DrainState<'gctx> {
"{profile_link}`{profile_name}` profile [{opt_type}]{profile_link:#} target(s) in {time_elapsed}",
);
// It doesn't really matter if this fails.
let _ = build_runner.bcx.gctx.shell().status("Finished", message);
let _ = build_runner
.bcx
.gctx
.shell()
.if_unchanged(build_runner.compilation.unchanged, move |shell| {
shell.status("Finished", &message)
});
future_incompat::save_and_display_report(
build_runner.bcx,
&self.per_package_future_incompat_reports,
Expand Down
3 changes: 3 additions & 0 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ fn compile<'gctx>(
let force = exec.force_rebuild(unit) || force_rebuild;
let mut job = fingerprint::prepare_target(build_runner, unit, force)?;
job.before(if job.freshness().is_dirty() {
// Mark the compilation as having done some work.
build_runner.compilation.unchanged = false;

let work = if unit.mode.is_doc() || unit.mode.is_doc_scrape() {
rustdoc(build_runner, unit)?
} else {
Expand Down
14 changes: 14 additions & 0 deletions src/cargo/core/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,18 @@ impl Shell {
}
}

// Runs the callback if unless the verbosity is `QuietIfUnchanged` and
// `unchanged` is true.
pub fn if_unchanged<F>(&mut self, unchanged: bool, mut callback: F) -> CargoResult<()>
where
F: FnMut(&mut Shell) -> CargoResult<()>,
{
match (self.verbosity, unchanged) {
(Verbosity::QuietIfUnchanged, true) => Ok(()),
_ => callback(self),
}
}

/// Prints a red 'error' message.
pub fn error<T: fmt::Display>(&mut self, message: T) -> CargoResult<()> {
if self.needs_clear {
Expand Down Expand Up @@ -558,6 +570,8 @@ impl TtyWidth {
pub enum Verbosity {
Verbose,
Normal,
/// No output if it's a no-change build with no warnings.
QuietIfUnchanged,
Quiet,
}

Expand Down
6 changes: 5 additions & 1 deletion src/cargo/ops/cargo_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ pub fn run(
process.display_env_vars();
}

gctx.shell().status("Running", process.to_string())?;
let process_string = process.to_string();

gctx.shell().if_unchanged(compile.unchanged, move |shell| {
shell.status("Running", &process_string)
})?;

process.exec_replace()
}
4 changes: 2 additions & 2 deletions src/cargo/ops/registry/info/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ fn pretty_deps(
gctx: &GlobalContext,
) -> CargoResult<()> {
match verbosity {
Verbosity::Quiet | Verbosity::Normal => {
Verbosity::Quiet | Verbosity::Normal | Verbosity::QuietIfUnchanged => {
return Ok(());
}
Verbosity::Verbose => {}
Expand Down Expand Up @@ -345,7 +345,7 @@ fn pretty_features(
.filter(|(_, s)| s.is_disabled())
.count();
let show_all = match verbosity {
Verbosity::Quiet | Verbosity::Normal => false,
Verbosity::Quiet | Verbosity::Normal | Verbosity::QuietIfUnchanged => false,
Verbosity::Verbose => true,
};
let show_activated = total_activated <= MAX_FEATURE_PRINTS || show_all;
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/sources/git/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ fn fetch_with_cli(
cmd.arg(format!("--depth={depth}"));
}
match gctx.shell().verbosity() {
Verbosity::Normal => {}
Verbosity::Normal | Verbosity::QuietIfUnchanged => {}
Verbosity::Verbose => {
cmd.arg("--verbose");
}
Expand Down
2 changes: 2 additions & 0 deletions src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1559,6 +1559,7 @@ pub fn new_gctx_for_completions() -> CargoResult<GlobalContext> {

let verbose = 0;
let quiet = true;
let is_manifest = false;
let color = None;
let frozen = false;
let locked = true;
Expand All @@ -1570,6 +1571,7 @@ pub fn new_gctx_for_completions() -> CargoResult<GlobalContext> {
gctx.configure(
verbose,
quiet,
is_manifest,
color,
frozen,
locked,
Expand Down
13 changes: 10 additions & 3 deletions src/cargo/util/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,7 @@ impl GlobalContext {
&mut self,
verbose: u32,
quiet: bool,
is_manifest: bool,
color: Option<&str>,
frozen: bool,
locked: bool,
Expand Down Expand Up @@ -1163,15 +1164,21 @@ impl GlobalContext {
let verbose = verbose != 0;
let verbosity = match (verbose, quiet) {
(true, true) => bail!("cannot set both --verbose and --quiet"),
(true, false) => Verbosity::Verbose,
(false, true) => Verbosity::Quiet,
(true, _) => Verbosity::Verbose,
(_, true) => Verbosity::Quiet,
(false, false) => match (term.verbose, term.quiet) {
(Some(true), Some(true)) => {
bail!("cannot set both `term.verbose` and `term.quiet`")
}
(Some(true), _) => Verbosity::Verbose,
(_, Some(true)) => Verbosity::Quiet,
_ => Verbosity::Normal,
_ => {
if is_manifest {
Verbosity::QuietIfUnchanged
} else {
Verbosity::Normal
}
}
},
};
self.shell().set_verbosity(verbosity);
Expand Down
5 changes: 5 additions & 0 deletions src/cargo/util/dependency_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ impl<N: Hash + Eq + Clone, E: Eq + Hash + Clone, V> DependencyQueue<N, E, V> {
self.dep_map.len()
}

/// Return an iterator over the values in the queue.
pub fn values(&self) -> impl Iterator<Item = &V> {
self.dep_map.values().map(|(_, v)| v)
}

/// Indicate that something has finished.
///
/// Calling this function indicates that the `node` has produced `edge`. All
Expand Down
Loading