buck2 icon indicating copy to clipboard operation
buck2 copied to clipboard

Cyclic computation error with `dynamic_output`

Open avdv opened this issue 1 year ago • 0 comments

I was using dynamic_output in our code base and at one point just got an error like this:

Cyclic computation detected when computing key `(target: `root//backend/src:backend_infra (prelude//platforms:default#904931f735703749)`, id: `1234`)`, which forms a cycle in computation chain: `(target: `root//backend/src:docs (prelude//platforms:default#904931f735703749)`, id: `1`) -> (target: `root//backend/src:backend_lib (prelude//platforms:default#904931f735703749)`, id: `110`) -> (target: `root//backend/src:backend_infra (prelude//platforms:default#904931f735703749)`, id: `1234`) -> (target: `(target: `root//backend/src:backend_infra (prelude//platforms:default#904931f735703749)`, id: `1233`)`, id: `38`)`

It turned out at one place I forgot to access an output for an action inside of the dynamic_output callback using the output parameter that is passed in:

def compile(ctx, artifacts, outputs, out1):
   ...
   ctx.actions.run(
     cmd_args(
       compiler,
       outputs[out1].as_output(),
       "--odir",
       cmd_args(out1.as_output(), parent=1), # <--- here
      ),
      category  = "...",
   ) 

Would it be possible to warn about this situation when a cmd_args instance is trying bind an output artifact in an action within the context of the dynamic output that is not referenced through output? Thanks!

avdv avatar May 02 '24 11:05 avdv