Skip to content

Commit

Permalink
build all files if none specified
Browse files Browse the repository at this point in the history
I'm ambivalent about this behavior, but it's come up twice so I think
people depend on it.

Fixes #88 and #53.
  • Loading branch information
evmar committed Nov 5, 2023
1 parent 90041c1 commit dc8e3c9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ impl GraphFiles {
id
})
}

pub fn all_ids(&self) -> impl Iterator<Item = FileId> {
(0..self.by_id.next_id().0).map(|id| FileId(id))
}
}

/// MTime info gathered for a file. This also models "file is absent".
Expand Down
4 changes: 3 additions & 1 deletion src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ fn build(
work.want_file(target)?;
}
} else {
anyhow::bail!("no path specified and no default");
work.progress
.log("no path specified and no default target; building everything");
work.want_every_file(build_file_target)?;
}

let tasks = trace::scope("work.run", || work.run())?;
Expand Down
18 changes: 15 additions & 3 deletions src/work.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,11 @@ impl BuildStates {
anyhow::bail!(err);
}

stack.push(id);
if let Some(bid) = graph.file(id).input {
stack.push(id);
self.want_build(graph, stack, bid)?;
stack.pop();
}
stack.pop();
Ok(())
}

Expand Down Expand Up @@ -309,7 +309,7 @@ pub struct Options {
pub struct Work<'a> {
graph: Graph,
db: db::Writer,
progress: &'a mut dyn Progress,
pub progress: &'a mut dyn Progress,
options: Options,
file_state: FileState,
last_hashes: Hashes,
Expand Down Expand Up @@ -347,6 +347,18 @@ impl<'a> Work<'a> {
self.build_states.want_file(&self.graph, &mut stack, id)
}

pub fn want_every_file(&mut self, exclude: Option<FileId>) -> anyhow::Result<()> {
for id in self.graph.files.all_ids() {
if let Some(exclude) = exclude {
if id == exclude {
continue;
}
}
self.want_file(id)?;
}
Ok(())
}

/// Check whether a given build is ready, generally after one of its inputs
/// has been updated.
fn recheck_ready(&self, id: BuildId) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn empty_file() -> anyhow::Result<()> {
let out = space.run(&mut n2_command(vec![]))?;
assert_eq!(
std::str::from_utf8(&out.stdout)?,
"n2: error: no path specified and no default\n"
"no path specified and no default target; building everything\n"
);
Ok(())
}
Expand Down

0 comments on commit dc8e3c9

Please sign in to comment.