That may be the case, yes. But in the way I did approach the task, this separation did not bother me. I am doing two things:
1. look at all the desired ports, make sure their options are set as desired, and gather their dependencies. Repeat doing that recursively, and write it all into a list.
2. Take that list, create a second (in-memory) list of those ports that are already present in pkg-format, and figure out what can be built next. If prereqs are needed, install them, then build the port. On success move it from the first to the second list. When the build fails, mark it as failed. (For the next port, zfs-rollback all that is not needed, then approach anew - that's my imperative, because I want reproducible builds that do not magically decide on features dependent on what is already present on the system.)
Neither 1. nor 2. can get into an infinite loop. 1. will notice that dependencies have already been gathered (which happens always when prereqs are needed for multiple ports), and 2. will just stop when nothing can be done anymore. Then somebody has to look into the matter, and that's the case anyway.
(I think there is also s report at the end, which ports have failed to build, and which had unreachable dependencies.)