Enable -Wall by default
Pet -Wall
Update libucl to the latest version
Rework how distfiles are handled:
- Copy existing distfiles from DISTFILES_CACHE to /portdistfiles
- fetch
- checksum
- cpdup back from /portdistfiles to DISTFILES_CACHE, cpdup does not copy files which it believes to have already been synchronized (by observing that the source and destination files' sizes and mtimes match)

This should prevent races where multiple builders try to fetch to DISTFILES_CACHE

There may still be races during the copy from/to the DISTFILES_CACHE but they should not be fatal as fetch/checksum is run after
Document what ret=2 is
Fix cleaning race when skipping ports

Fix this by only removing this package from other package's dependencies
after recursively skipping packages depending on this package. This ensures
that packages depending on this package retain a >0 count of needed
packages while recursively cleaning. Otherwise another clean.sh process
for a successful package may remove itself from its dependencies and then find
that some of them are empty, despite those dependencies about to be recursively
cleaned up and skipped.

This would result in ports being built without their dependencies having been
built, showing the following error:

    ===>   USE_PACKAGE_DEPENDS_ONLY set - not building missing dependency from source

Further explanation:

  Given these deps:
     /deps/dep_a
     /deps/dep_b
     /deps/leaf_a/dep_a
     /deps/leaf_a/dep_b

  1. dep_a fails and dep_b succeeds at the same time
  2. dep_a fails and cleans its reference from /deps/leaf_a
     via find /rdeps/dep_a|realpath|rm -f
  2. At the same time, dep_b finishes building and also
     removes itself from /deps/leaf_a via find|realpath|rm
     [ This leaves /deps/leaf_a empty ]
  3. dep_a cleaning recurses into leaf_a to skip it because
     dep_a has failed and leaf_a is not buildable now.
  3. dep_b falls through and checks all of its deps for empty
     dirs as they are now eligible for building. Because
     /deps/leaf_a is now empty, it moves it to /pool/
  4. dep_a's recursive call to skip leaf_a generates (hidden)
     warnings and finally tries to remove /deps/leaf_a so it
     is skipped
  5. leaf_a resides in /pool despite having dep_a failed

MFH
Add comment in clean.sh

MFH
Avoid racing when recursively cleaning up rdeps

This prevents multiple clean.sh processes from cleaning the same
package's reverse dependencies. This was mostly harmless before.

Now have clean.sh exclusively claim the rdep dir by moving it to
/cleaning/rdeps/<pkgname>. If the atomic mv fails, ignore it and
assume another process is currently cleaning it already.

MFH
Avoid rare race leading to incorrectly not skipping ports in some cases

This could occur when deleting the /deps dir, which was non-empty. For a brief
moment the dir would become empty after removing all entries. Another clean.sh
process would see the empty dir and consider it as ready-to-build. This would
result in ports being built without their dependencies having been built
showing the following error:

    ===>   USE_PACKAGE_DEPENDS_ONLY set - not building missing dependency from source

Race details (Before recent refactoring):

    Given these deps:
       /deps/dep_a
       /deps/dep_b
       /deps/dep_c
       /deps/leaf_a/dep_a
       /deps/leaf_a/dep_b
       /deps/leaf_a/dep_c

    1. dep_a fails and dep_b succeeds at the same time
    2. dep_a fails and cleans its reference from /deps/leaf_a
       via find /rdeps/dep_a|realpath|rm -f
    2. At the same time, dep_b finishes building and also
       removes itself from /deps/leaf_a via find|realpath|rm
       [ This leaves /deps/leaf_a/dep_c - leaf_a is not
         satisfied to build ]
    3. dep_a cleaning recurses into leaf_a to skip it because
       dep_a has failed and leaf_a is not buildable now. It
       calls rm -rf /deps/leaf_a so it is skipped.
       [ This is non-atomic and leaves /deps/leaf_a empty for
         a brief moment ]
    3. dep_b falls through and checks all of its rdeps for empty
       dirs as they are now eligible for building. Because
       /deps/leaf_a is briefly empty, it moves it to /pool/
    4. dep_a's rm -rf /deps/leaf_a call to unlink leaf_a generates
       (hidden) warnings
    5. leaf_a resides in /pool despite missing dep_c and having
       dep_a failed

Race details (As of this commit):

    Given these deps:
       /deps/dep_a
       /deps/dep_b
       /deps/dep_c
       /deps/leaf_a/dep_a
       /deps/leaf_a/dep_b
       /deps/leaf_a/dep_c

    1. dep_a fails and dep_b succeeds at the same time
    2. dep_a recurses into leaf_a to skip it because
       dep_a has failed and leaf_a is not buildable now. It
       calls rm -rf /deps/leaf_a so it is skipped. [ This briefly
       leaves /deps/leaf_a empty after all entries are deleted. ]
    2. dep_b searches everything depending on it for now empty
       dirs, incorrectly finds leaf_a and moves it to /pool/.
    3. dep_a's rm -rf /deps/leaf_a call to unlink leaf_a generates
       (hidden) warnings
    4. leaf_a resides in /pool despite missing dep_c and having
       dep_a failed

This is fixed by atomically removing the /deps/<pkgname> dir and avoiding
a briefly empty dir that another process may see.

MFH
clean.sh: Now that rdeps is exclusively "locked", there is no reason to check empty dir.

/rdeps is only created when there is an actual dependency.
clean.sh: Optimize slightly by avoiding rechecking clean_rdepends many times.

For large port depdenencies, such as ports-mgmt/pkg, this can result in 24000
[] calls.
clean.sh: Only consider ready-to-build if not recursively cleaning.

This is mostly a NOP. The code is more proper now, there is no reason to
try moving ports to /unbalanced if recursively cleaning. The code
would just do an echo ""|xargs before anyhow.
Clean.sh: Remove old pkg dirs in background
Set status clean_pool when cleaning pool
Clean.sh: Only need to follow and cleanup rdeps when not recursing.
Clean.sh: No need for realpath(1)
Clean.sh: Remove redundant check on clean_rdepends
Clean.sh: Speedup skipping by avoiding redundant recusive cleanups.

This works by removing all rdep references when a pkg is removed from
/deps due to being skipped. The old code would still keep looking
at all rdeps and continually try to remove the same packages
over and over again.
compute_deps: Speedup 9% by using :> instead of touch
Use case instead of [] for checking empty dir as it is slightly faster.

$ rm -rf dir; mkdir dir; for n in $(jot 24000); do :> dir/${n}; done
$ /usr/bin/time sh -c 'for n in dir/*; do :; done;'
        0.04 real         0.03 user         0.01 sys
$ /usr/bin/time sh -c 'for n in dir/*; do [ "${n}" = "${n}/*" ] && break; :; done;'
        0.09 real         0.08 user         0.01 sys
$ /usr/bin/time sh -c 'for n in dir/*; do case "$n" in "dir/*") break ;; esac; :; done;'
        0.05 real         0.03 user         0.02 sys

Suggested by:	jilles