postorder traversal through initial tree and push dependencies into found packages, should be somewhat simple.