This module deals with building and incrementally rebuilding a collection
of packages. It is what backs the cabal build and configure commands,
as well as being a core part of run, test, bench and others.
The primary thing is in fact rebuilding (and trying to make that quick by
not redoing unnecessary work), so building from scratch is just a special
case.
The build process and the code can be understood by breaking it down into
three major parts:
As far as possible, the "what to do" phase embodies all the policy, leaving
the "do it" phase policy free. The first phase contains more of the
complicated logic, but it is contained in code that is either pure or just
has read effects (except cache updates). Then the second phase does all the
actions to build packages, but as far as possible it just follows the
instructions and avoids any logic for deciding what to do (apart from
recompilation avoidance in executing the plan).
This division helps us keep the code under control, making it easier to
understand, test and debug. So when you are extending these modules, please
think about which parts of your change belong in which part. It is
perfectly ok to extend the description of what to do (i.e. the
ElaboratedInstallPlan) if that helps keep the policy decisions in the
first phase. Also, the second phase does not have direct access to any of
the input configuration anyway; all the information has to flow via the
ElaboratedInstallPlan.