Add ability to specify categories in arbitrary order.

In order to use existing mechanics for categories building, we should
perform topological sort on categories graph, to resolve parent->child
dependencies.
Add spec for cyclical graphs