         ;; generated for the dependencies in that situation if we
         ;; don't do it again in `straight-use-package'.
         (when-let ((dependencies (straight--get-dependencies package)))
-          (dolist (dependency dependencies)
-            ;; The implicit meaning of the first argument to
-            ;; `straight-use-package' here is that the default
-            ;; recipes (taken from one of the recipe repositories) are
-            ;; used for dependencies. (Well, maybe. See all the weird
-            ;; edge cases and exceptions in
-            ;; `straight--convert-recipe'.) Note that the second
-            ;; argument is always nil. That is, even if the user was
-            ;; supposed to be prompted about whether they wanted to
-            ;; install this package, if they say yes then all the
-            ;; dependencies are automatically installed (what else
-            ;; could the user want?).
-            (straight-use-package (intern dependency) nil task))
+          ;; This let-binding prevents the changes we already made to
+          ;; the build cache from being overwritten; see the comment
+          ;; above the `straight--compute-dependencies' call above.
+          (let ((straight--package-build-in-progress t))
+            (dolist (dependency dependencies)
+              ;; The implicit meaning of the first argument to
+              ;; `straight-use-package' here is that the default
+              ;; recipes (taken from one of the recipe repositories) are
+              ;; used for dependencies. (Well, maybe. See all the weird
+              ;; edge cases and exceptions in
+              ;; `straight--convert-recipe'.) Note that the second
+              ;; argument is always nil. That is, even if the user was
+              ;; supposed to be prompted about whether they wanted to
+              ;; install this package, if they say yes then all the
+              ;; dependencies are automatically installed (what else
+              ;; could the user want?).
+              (straight-use-package (intern dependency) nil task)))
           ;; We might need to redisplay the progress message from
           ;; `straight--with-progress' up above.
           (when straight--echo-area-dirty

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)

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
