summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Martin <evan.martin@gmail.com>2023-11-04 17:44:24 -0700
committerEvan Martin <evan.martin@gmail.com>2023-11-04 17:46:33 -0700
commitdc8e3c917c99d49721cbf89cbbe4eaa257ce4021 (patch)
tree643ed2fa823dcbe95d33bf9c97df08c7e024e0e9
parent90041c1f010d27464e3b18e38440ed9855ea62ef (diff)
downloadn2-dc8e3c917c99d49721cbf89cbbe4eaa257ce4021.tar.gz
build all files if none specified
I'm ambivalent about this behavior, but it's come up twice so I think people depend on it. Fixes #88 and #53.
-rw-r--r--src/graph.rs4
-rw-r--r--src/run.rs4
-rw-r--r--src/work.rs18
-rw-r--r--tests/e2e/basic.rs2
4 files changed, 23 insertions, 5 deletions
diff --git a/src/graph.rs b/src/graph.rs
index 6d36753..f3577c1 100644
--- a/src/graph.rs
+++ b/src/graph.rs
@@ -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".
diff --git a/src/run.rs b/src/run.rs
index 45d7565..7814448 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -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())?;
diff --git a/src/work.rs b/src/work.rs
index cd73a70..c8d6ca0 100644
--- a/src/work.rs
+++ b/src/work.rs
@@ -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(())
}
@@ -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,
@@ -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 {
diff --git a/tests/e2e/basic.rs b/tests/e2e/basic.rs
index 79db2c5..4e9b310 100644
--- a/tests/e2e/basic.rs
+++ b/tests/e2e/basic.rs
@@ -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(())
}