Cache key calculation fails to take dependency type into account in some cases

Summary

When changing the type of a dependency, the cache key for the element doesn't always change.

Steps to reproduce

For any artifact which currently has a dependency which is "type: build": Remove the "type: build" so that it's type is "runtime+build". The cache key will not change.

What is the current bug behavior?

The cache key doesn't change when switching between "build" and "build+runtime" dependency types.

What is the expected correct behavior?

The cache key should change because the behaviour of the build changes.

Relevant logs and/or screenshots

I can't post the logs due to non-disclosure, but I may attempt to create an example if it's required.

Possible fixes

Unconditionally add the dependency type to the cache key calculation.

Other relevant information

In buildstream there are 3 dependency types:

  • build which happens with "type: build"
  • runtime which happens with "type: runtime"
  • build+runtime which happens when there's no type field

It would be easy to believe that "build" and "build+runtime" would cause the element to be identical and as such the cache key wouldn't change, because you'd think that "runtime" depends have no effect at build-time, however this is not the case:

For example imagine a gcc runtime dependency, it will be included at build time by anything which builds gcc, because gcc would need that to run.

Stated clearly:

  • If A build depends on B and B build depends on C. C is not staged at build time for A.
  • If A build depends on B and B build+runtime depends on C. C is staged at build time for A because it's needed to run B.

So the difference between "build" and "build+runtime" manifests at build time, and needs to be handled by buildstream.

This error is very likely to be encountered in any situation where you're aiming for a minimal set of dependencies. As it makes sense to start out having everything as a build-depend until you know that it's needed as a build+runtime dependency.

In my case I now have to delete cache elements to force a rebuild to see the correct behaviour.

This bug has directly caused builds that should fail to succeeed on my machine.

  • BuildStream version affected: /milestone %BuildStream_v1.2.3

Edited by Tristan Van Berkom