Circular Dependencies

Intro

There bad!

Don’t do them

But others may have

Why?

Common mesons to have Circular Dependencies:

Circular Dependancies in Build System

Many build systems just make one thing at a eg auto tools, it is your responsibility to build and install the different pieces of software in the write order

But thinks like baserock and buildstream that deal with many projects need to deal with this them selves

The way that some projects that use these tools have developed is stages, these stages seem like seperate pices of software to the build tool but in reality create the same artifacts that can

Example

This example will cover the simple case of a library (libA) that depends on a libary (libB) that depends on the orignal library (libA).

The buildstream elements will be:

  • mylib-stage1.bst will build the lib mylib. This will be the basic version that dose not have full capablity.
  • secondlib.bst will build the lib secondlib. This will need the basic version of mylib and so will depend on mylib-stage1.bst
  • mylib.bst will build the full version of mylib and so will depend on secondlib.bst

The second version of mylib.bst will have the same artifacts as mylib-stage1.bst so any bst element that depends on both must make sure that it they are loaded in the right order so that mylib.bst over writes mylib-stage1.bst’s artifacts.

mylib-stage1.bst

This lib’s only purpose is to provide a starting point for secondlib.bst

kind: cmake
description: |2

  Lets make circels
sources:
- kind: git
  url: ../circular-git
  track: master
  ref: 22a73f55dacf46e41c5edbd07b3b1acca8f8b934
depends:
- base.bst

variables:
  conf-root: cmksrc/mylib
user@host:~/circular-bst$ bst shell demo-simple.bst -- mainDemo

[--:--:--][][] START   Loading elements
[00:00:00][][] SUCCESS Loading elements
[--:--:--][][] START   Resolving elements
[00:00:00][][] SUCCESS Resolving elements
[--:--:--][][] START   Resolving cached state
[00:00:00][][] SUCCESS Resolving cached state
[--:--:--][23ddd3b8][ main:demo-simple.bst               ] START   Staging dependencies
[00:00:00][23ddd3b8][ main:demo-simple.bst               ] SUCCESS Staging dependencies
[--:--:--][23ddd3b8][ main:demo-simple.bst               ] START   Integrating sandbox
[00:00:00][23ddd3b8][ main:demo-simple.bst               ] SUCCESS Integrating sandbox
[--:--:--][23ddd3b8][ main:demo-simple.bst               ] STATUS  Running command

    mainDemo

sqrt(100)=10

secondlib.bst

This is the final version of secondlib but it is compiled against mylib-stage1.bst but it will work with mylib.bst once it exists.

kind: cmake
description: |2

  Lets make circels
sources:
- kind: git
  url: ../circular-git
  track: master
  ref: 22a73f55dacf46e41c5edbd07b3b1acca8f8b934
depends:
- base.bst

- mylib-stage1.bst

variables:
  conf-root: cmksrc/secondlib
user@host:~/circular-bst$ bst shell demo-simple-second.bst -- mainDemo

[--:--:--][][] START   Loading elements
[00:00:00][][] SUCCESS Loading elements
[--:--:--][][] START   Resolving elements
[00:00:00][][] SUCCESS Resolving elements
[--:--:--][][] START   Resolving cached state
[00:00:00][][] SUCCESS Resolving cached state
[--:--:--][147a2990][ main:demo-simple-second.bst        ] START   Staging dependencies
[00:00:00][147a2990][ main:demo-simple-second.bst        ] SUCCESS Staging dependencies
[--:--:--][147a2990][ main:demo-simple-second.bst        ] START   Integrating sandbox
[00:00:00][147a2990][ main:demo-simple-second.bst        ] SUCCESS Integrating sandbox
[--:--:--][147a2990][ main:demo-simple-second.bst        ] STATUS  Running command

    mainDemo

sqrt(100)=10

mylib.bst

kind: cmake
description: |2

  Lets make circels
sources:
- kind: git
  url: ../circular-git
  track: master
  ref: 22a73f55dacf46e41c5edbd07b3b1acca8f8b934
depends:
- base.bst
- secondlib.bst

variables:
  conf-root: cmksrc/mylib
  cmake-local: -DDEMO_CIR=TRUE

The only difference between mylib.bst and mylib-stage1.bst are the Dependancies and the build options.

Building the code in the mylib source that depends on secondlib is enabled by calling cmake the the DEMO_CIR buildflag to true.

user@host:~/circular-bst$ bst shell demo.bst -- mainDemo

[--:--:--][][] START   Loading elements
[00:00:00][][] SUCCESS Loading elements
[--:--:--][][] START   Resolving elements
[00:00:00][][] SUCCESS Resolving elements
[--:--:--][][] START   Resolving cached state
[00:00:00][][] SUCCESS Resolving cached state
[--:--:--][399725c2][ main:demo.bst                      ] START   Staging dependencies
[--:--:--][399725c2][ main:demo.bst                      ] WARNING [overlaps]: Non-whitelisted overlaps detected

    Staged files overwrite existing files in staging area:
    /usr/include/mylib.h: mylib.bst is not permitted to overlap other elements, order mylib.bst above mylib-stage1.bst 
    /usr/lib/debug/usr/lib/libmylib.so: mylib.bst is not permitted to overlap other elements, order mylib.bst above mylib-stage1.bst 
    /usr/lib/libmylib.so: mylib.bst is not permitted to overlap other elements, order mylib.bst above mylib-stage1.bst 

[00:00:00][399725c2][ main:demo.bst                      ] SUCCESS Staging dependencies
[--:--:--][399725c2][ main:demo.bst                      ] START   Integrating sandbox
[00:00:00][399725c2][ main:demo.bst                      ] SUCCESS Integrating sandbox
[--:--:--][399725c2][ main:demo.bst                      ] STATUS  Running command

    mainDemo

sqrt(100)=10
sqrt(100)=14
sqrt(100)=20