diff --git a/docs/tasks/task-configuration.md b/docs/tasks/task-configuration.md index a671120450..88c57ddef9 100644 --- a/docs/tasks/task-configuration.md +++ b/docs/tasks/task-configuration.md @@ -232,6 +232,7 @@ has changed since the last build. ### `outputs` - **Type**: `string | string[] | { auto = true }` +- **Default**: `{ auto = true }` The counterpart to `sources`, these are the files or directories that the task will create/modify after it executes. @@ -245,7 +246,7 @@ a file for `sources` to work. [tasks.build] run = "cargo build" sources = ["Cargo.toml", "src/**/*.rs"] -outputs = { auto = true } +outputs = { auto = true } # this is the default when sources is defined ``` ### `shell` diff --git a/e2e/tasks/test_task_run_sources b/e2e/tasks/test_task_run_sources index c710b7c396..ec64e7a1f4 100644 --- a/e2e/tasks/test_task_run_sources +++ b/e2e/tasks/test_task_run_sources @@ -34,6 +34,19 @@ assert_empty "mise -q hi" touch ../older assert "mise -q hi" "hi" +cat <mise.toml +[tasks.hi] +sources = ["{{cwd}}/input"] +run = "echo hi" +EOF + +mkdir subdir && cd subdir || exit 1 +assert "mise -q hi" "hi" +assert_empty "mise -q hi" +touch input +assert "mise -q hi" "hi" +assert_empty "mise -q hi" + cat <mise.toml [tasks.hi] sources = ["{{cwd}}/input"] diff --git a/src/cli/run.rs b/src/cli/run.rs index bb71765e85..1c63bec41f 100644 --- a/src/cli/run.rs +++ b/src/cli/run.rs @@ -1220,8 +1220,7 @@ impl Run { } async fn sources_are_fresh(&self, task: &Task, config: &Arc) -> Result { - let outputs = task.outputs.paths(task); - if task.sources.is_empty() && outputs.is_empty() { + if task.sources.is_empty() { return Ok(false); } // TODO: We should benchmark this and find out if it might be possible to do some caching around this or something @@ -1248,7 +1247,7 @@ impl Run { return Ok(false); } let sources = self.get_last_modified_from_metadatas(&source_metadatas); - let outputs = self.get_last_modified(&root, &outputs)?; + let outputs = self.get_last_modified(&root, &task.outputs.paths(task))?; file::write(&source_metadata_hash_path, &source_metadata_hash)?; trace!("sources: {sources:?}, outputs: {outputs:?}"); match (sources, outputs) { diff --git a/src/task/mod.rs b/src/task/mod.rs index 66c4ee48e3..bb9faf9d23 100644 --- a/src/task/mod.rs +++ b/src/task/mod.rs @@ -568,6 +568,9 @@ impl Task { for s in &mut self.sources { *s = tera.render_str(s, &tera_ctx)?; } + if !self.sources.is_empty() && self.outputs.is_empty() { + self.outputs = TaskOutputs::Auto; + } self.outputs.render(&mut tera, &tera_ctx)?; for d in &mut self.depends { d.render(&mut tera, &tera_ctx)?; diff --git a/src/task/task_sources.rs b/src/task/task_sources.rs index 116cd7e86a..73dc99372c 100644 --- a/src/task/task_sources.rs +++ b/src/task/task_sources.rs @@ -17,6 +17,13 @@ impl Default for TaskOutputs { } impl TaskOutputs { + pub fn is_empty(&self) -> bool { + match self { + TaskOutputs::Files(files) => files.is_empty(), + TaskOutputs::Auto => false, + } + } + pub fn paths(&self, task: &Task) -> Vec { match self { TaskOutputs::Files(files) => files.clone(),