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 docs/tasks/task-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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`
Expand Down
13 changes: 13 additions & 0 deletions e2e/tasks/test_task_run_sources
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ assert_empty "mise -q hi"
touch ../older
assert "mise -q hi" "hi"

cat <<EOF >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 <<EOF >mise.toml
[tasks.hi]
sources = ["{{cwd}}/input"]
Expand Down
5 changes: 2 additions & 3 deletions src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1220,8 +1220,7 @@ impl Run {
}

async fn sources_are_fresh(&self, task: &Task, config: &Arc<Config>) -> Result<bool> {
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
Expand All @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions src/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
7 changes: 7 additions & 0 deletions src/task/task_sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
match self {
TaskOutputs::Files(files) => files.clone(),
Expand Down
Loading