facebook / buck2

Build system, successor to Buck
https://buck2.build/
Apache License 2.0
3.33k stars 194 forks source link

Cyclic computation error with `dynamic_output` #636

Open avdv opened 2 weeks ago

avdv commented 2 weeks ago

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!