Given basePackagesToBuild
(Here they will be called from
), and buildUpto
(here they will be
called upto
), this algorithm calculates which packages to build.
Note that if upto
=== undefined, then by definition we set upto
to be from
.
Each of the packages will have the additional info:
dependencies
: the list of packages it depends on directly. From this, a "dependency graph" (a DAG) can be built.lastBuildTime
: a unix timestamp of the last successful build time of the package.isDirty
: the package was changed since it was last built.
- A package will be built if and only if it is in the graph subset that links all the uptos to the froms in the dependency graph. In other words, one of its predecessors (recursive) MUST be one of the uptos, and one of its descendants (recursive) MUST be one of the froms.
- A package will be built if it is dirty.
- A package will be built if its last build is smaller than one of the last builds of its dependencies or if one of its packages is dirty.
- A package will be built if a package that it depends will be built.
The steps of the algorithm:
First, we build the "linked graph subset", which is a subset of the dependency graph that includes all packages that can be built, given the froms and the uptos.
This takes care of the 1st invariant.
- Using Djikstra, calculate the length of the path from each node to each other node
- For each node N:
- If one of the from nodes has some finite length from N, and...
- one of the to nodes has some finite length to N...
- keep N
- Otherwise remove N
This takes care of the 2nd and 3rd invariant.
- For each package in the linked graph subset:
- Mark it if it's dirty
- Mark it if one of its dependency's
isDirty
or the dependency'slastBuildTime
> itslastBuildTime
This takes care of the 4th invariant.
- Using Djikstra, calculate the length of the path from each node to each other node
- If a node has marked nodes that lead from it, mark it
Return all marked nodes.