 The usual contents of this hook are either
 `straight--save-build-cache', or nothing.")
 
+(defvar straight--package-build-in-progress nil
+  "Non-nil if a package is currently being built.
+If this variable is non-nil, then loading of the build cache will
+be inhibited. This prevents changes made by the first few phases
+of building the root package (namely, writing the dependency list
+to the build cache) from being overwritten when its dependencies
+are built.")
+
 (defun straight--maybe-load-build-cache ()
   "Invoke `straight--load-build-cache' if necessary.
 During init, loading will take place only the first time this

The exception to this is if the user calls
`straight-declare-init-finished' (which see) in their init-file,
which allows for loading to again only take place once when the
user reloads their init-file."
  (cond
   ;; During initialization, we use `after-init-hook'.
   ((not after-init-time)
    (unless (member #'straight--save-build-cache after-init-hook)

                        (format "Building %s" package))))
      (straight--with-progress task
        (straight--symlink-package recipe)
        ;; The following function call causes the dependency list to
        ;; be written to the build cache. To prevent this from being
        ;; overwritten when any dependencies are built, we have to be
        ;; sure to bind `straight--package-build-in-progress' below!
        (straight--compute-dependencies package)
        ;; Before we (possibly) build the dependencies, we need to set
        ;; this flag so that we know if our progress message will need
