detect cycles in rule dependencies

This fixes a stack overflow that occurred when having cycles in rule
dependencies.

Task-number: QBS-396

Change-Id: I1907ef66d74340c090b09be72d2352892baca986
Reviewed-by: Christian Kandeler <christian.kandeler@digia.com>