Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hide_success and hide_progress options #135

Merged
merged 5 commits into from
Feb 18, 2025
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
9 changes: 9 additions & 0 deletions doc/comparison.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ Here are some things n2 improves over Ninja:
- `-d trace` generates a performance trace that can be visualized by Chrome's
`about:tracing` or alternatives (speedscope, perfetto).

### Extensions

Some extra build variables are available only in n2:

- `hide_progress`: build edges with this flag will not show the last
line of output in the fancy progress output.
- `hide_success`: build edges with this flag will not show the complete
command output when the command completes successfully.

## Missing

- Windows is incomplete.
Expand Down
7 changes: 7 additions & 0 deletions src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ pub struct Build {

/// Output files.
pub outs: BuildOuts,

/// True if output of command should be hidden on successful completion.
pub hide_success: bool,
/// True if last line of output should not be shown in status.
pub hide_progress: bool,
}
impl Build {
pub fn new(loc: FileLoc, ins: BuildIns, outs: BuildOuts) -> Self {
Expand All @@ -188,6 +193,8 @@ impl Build {
ins,
discovered_ins: Vec::new(),
outs,
hide_success: false,
hide_progress: false,
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,17 @@ impl Loader {
}),
_ => bail!("rspfile and rspfile_content need to be both specified"),
};
let hide_success = lookup("hide_success").is_some();
let hide_progress = lookup("hide_progress").is_some();

build.cmdline = cmdline;
build.desc = desc;
build.depfile = depfile;
build.parse_showincludes = parse_showincludes;
build.rspfile = rspfile;
build.pool = pool;
build.hide_success = hide_success;
build.hide_progress = hide_progress;

self.graph.add_build(build)
}
Expand Down
2 changes: 2 additions & 0 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ impl<'text> Parser<'text> {
| "rspfile"
| "rspfile_content"
| "msvc_deps_prefix"
| "hide_success"
| "hide_progress"
)
})?;
Ok(Rule { name, vars })
Expand Down
6 changes: 5 additions & 1 deletion src/progress_dumb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,22 @@ impl Progress for DumbConsoleProgress {
}

fn task_finished(&self, id: BuildId, build: &Build, result: &TaskResult) {
let mut hide_output = result.output.is_empty();
match result.termination {
Termination::Success => {
if result.output.is_empty() || self.last_started.get() == Some(id) {
// Output is empty, or we just printed the command, don't print it again.
} else {
self.log(build_message(build))
}
if build.hide_success {
hide_output = true;
}
}
Termination::Interrupted => self.log(&format!("interrupted: {}", build_message(build))),
Termination::Failure => self.log(&format!("failed: {}", build_message(build))),
};
if !result.output.is_empty() {
if !hide_output {
std::io::stdout().write_all(&result.output).unwrap();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/progress_fancy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl FancyState {
// Show task name, status, and output.
let buf = &mut self.pending;
match result.termination {
Termination::Success if result.output.is_empty() => {
Termination::Success if result.output.is_empty() || build.hide_success => {
// Common case: don't show anything.
return;
}
Expand Down
5 changes: 4 additions & 1 deletion src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ impl Runner {
let depfile = build.depfile.clone().map(PathBuf::from);
let rspfile = build.rspfile.clone();
let parse_showincludes = build.parse_showincludes;
let hide_progress = build.hide_progress;

let tid = self.tids.claim();
let tx = self.tx.clone();
Expand All @@ -226,7 +227,9 @@ impl Runner {
parse_showincludes,
rspfile.as_ref(),
|line| {
let _ = tx.send(Message::Output((id, line.to_owned())));
if !hide_progress {
let _ = tx.send(Message::Output((id, line.to_owned())));
}
},
)
.unwrap_or_else(|err| TaskResult {
Expand Down
Loading