Skip to content
Merged
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
3 changes: 2 additions & 1 deletion cli/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
)
)]

use std::io::{self, Write};
use std::io::{self, IsTerminal, Write};
use std::path::Path;

use dx_cli::bazel_restart::{RestartingQueryRunner, RestartingRunner};
Expand Down Expand Up @@ -248,6 +248,7 @@ fn run() -> i32 {
return usage_error(code, &error.to_string(), json, command);
}
};
invocation.piped = !io::stdout().is_terminal();
// LCOV_EXCL_STOP - reason: end thin run shim, issue: 1055, policy: docs/cli/commands/build-test-coverage.md
dx_adopt::refresh_stale_pins_from_env();
dx_cli::exec::set_usage_command(invocation.command);
Expand Down
34 changes: 31 additions & 3 deletions cli/plan/src/args/invocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ pub struct Invocation {
pub bench_compare: Option<String>,
pub path_only: bool,
pub agent: bool,
/// Stdout is not a terminal.
pub piped: bool,
pub bazel_startup_options: Vec<String>,
}

Expand All @@ -352,9 +354,10 @@ impl Invocation {
self.command == Command::Update && self.targets.len() == 2 && is_version(&self.targets[1])
}

/// Bazel UI flags that silence progress output in agent JSON sessions.
/// Bazel UI flags that silence progress output in agent JSON sessions and piped runs; `-v` keeps Bazel output.
pub fn agent_quiet_flags(&self) -> Vec<String> {
if self.agent && self.output == OutputMode::Json {
let agent_json = self.agent && self.output == OutputMode::Json;
if (agent_json || self.piped) && !self.verbose {
AGENT_QUIET_FLAGS
.iter()
.map(|flag| (*flag).to_owned())
Expand All @@ -364,7 +367,7 @@ impl Invocation {
}
}

/// Bazel options for the run: agent JSON sessions get no progress output.
/// Bazel options for the run: agent JSON sessions and piped runs get no progress output.
pub fn quiet_bazel_options(&self) -> Vec<String> {
let mut options = self.agent_quiet_flags();
options.extend(self.bazel_options.iter().cloned());
Expand Down Expand Up @@ -743,6 +746,7 @@ mod tests {
bench_compare: None,
path_only: false,
agent: false,
piped: false,
bazel_startup_options: Vec::new(),
}
}
Expand Down Expand Up @@ -1117,6 +1121,16 @@ mod tests {
AGENT_QUIET_FLAGS.iter().map(ToString::to_string).collect()
}

#[test]
fn piped_runs_are_quiet_unless_verbose() {
let mut inv = parsed(&["build"]);
assert!(inv.quiet_bazel_options().is_empty());
inv.piped = true;
assert_eq!(inv.quiet_bazel_options(), quiet_flags());
inv.verbose = true;
assert!(inv.quiet_bazel_options().is_empty());
}

#[test]
fn raw_bazel_options_never_carry_agent_quiet_flags() {
let session = agent(&["build", "--output=json", "--", "--jobs=4"]);
Expand Down Expand Up @@ -1146,6 +1160,20 @@ mod tests {
);
}

#[test]
fn piped_requests_carry_quiet_flags_until_verbose() {
let mut inv = parsed(&["generate", "--", "--jobs=4"]);
inv.piped = true;
let mut want = quiet_flags();
want.push("--jobs=4".to_owned());
assert_eq!(inv.generate_request().expect("generate").bazel_options, want);
inv.verbose = true;
assert_eq!(
inv.generate_request().expect("generate").bazel_options,
vec!["--jobs=4".to_owned()]
);
}

#[test]
fn agent_quiet_generate_request_puts_quiet_flags_before_the_callers_options() {
let generate = agent(&["generate", "--output=json", "--", "--jobs=4"])
Expand Down
1 change: 1 addition & 0 deletions cli/plan/src/args/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ fn parse_inner<S: AsRef<OsStr>>(
bench_compare: compare,
path_only,
agent,
piped: false,
bazel_startup_options,
})
}
Expand Down
2 changes: 2 additions & 0 deletions docs/cli/commands/build-test-coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ dx coverage [--here] [--affected] [--timings] [--min-coverage <percent>] [--min-

`--debug` and `--release` conflict. Both change compilation only.

When stdout is not a terminal, dx passes Bazel the quiet flags `--noshow_progress`, `--noshow_loading_progress`, `--noshow_timestamps`, `--curses=no`, `--ui_event_filters=-info,-debug` and `--test_summary=none`. `-v` keeps full Bazel output.

## Scopes

No scope means `//...`. Pass labels, patterns, files, or directories. A file runs its owning targets. For `test` and `coverage`, a file runs the tests that depend on its owners. A `manual` test runs only when it owns the file.
Expand Down
Loading