task icon indicating copy to clipboard operation
task copied to clipboard

Failing to detect dependencies correctly when defining tasks sources with passed variable

Open dstadelm opened this issue 1 year ago • 0 comments

First I want to say some words of praise: I really like the approach of task. I see a lot of potential.

I have a fairly complex problem to solve and I've hit a major deal breaker, so here we go:

  • Task version: v3.31.0 (h1:o6iyj9gPJXxvxPi/u/l8e025PmM2BqKgtLNPS2i7hV4=)
  • Operating system: Ubuntu 22.04 LTS
  • Experiments enabled: No

This is a minimal example and sub-/subsubtasks run randomly and do not detect the dependencies correctly.

Usage:

> task setup_example
> task toptask
> task toptask
> task toptask

Taskfile:

version: '3'
tasks:
  setup_example:
    cmds:
      - rm -rf foo_1 foo_2
      - mkdir foo_1
      - mkdir foo_2
      - echo 'bla' >> foo_1/foo.txt
      - echo 'blu' >> foo_2/foo.txt
  toptask:
    deps:
      - task: subtask
        vars:
          TARGET: foo_1
      - task: subtask
        vars:
          TARGET: foo_2
  subtask:
    deps:
      - task: subsubtask
        vars:
          TARGET: '{{.TARGET}}'
    sources:
      - 'bar.txt'
    cmds:
      - echo subtask '{{.TARGET}}'
      - cp 'bar.txt' 'foo_bar.txt'
    method: checksum
    dir: '{{.TARGET}}'
    generates: ['foo_bar.txt']
    silent: true
  subsubtask:
    sources:
      - 'foo.txt'
    cmds:
      - echo subsubtask '{{.TARGET}}'
      - cp 'foo.txt' 'bar.txt'
    method: checksum
    dir: '{{.TARGET}}'
    generates: ['bar.txt']
    silent: true

I'm assuming (from what I can see from the docs) that the sources and targets are relative to the 'dir' directory. I think the problem is, that in task the sources are stored as a structure for the task, so when calling the tasks as I've done, the sources for the task change whenever it called with new variables.

For me I need a way to run multiple tasks for different sources. I do not want one task with a whole list of sources and run the task on every source when only one of the sources has changed. They are independent. But I don't see a easy way to define this in a Taskfile. Am I missing something? Is there a way to solve what I'm trying to achieve?

dstadelm avatar Nov 02 '23 10:11 dstadelm