             ;; in order to byte-compile properly.
             (straight--add-package-to-load-path recipe)
             (straight--maybe-load-build-cache)
-            (when (straight--package-might-be-modified-p recipe)
+            (when
+                (or
+                 (and
+                  straight--packages-to-rebuild
+                  (or (eq straight--packages-to-rebuild :all)
+                      (gethash package straight--packages-to-rebuild))
+                  (not (gethash package straight--packages-not-to-rebuild))
+                  ;; The following form returns non-nil, so it doesn't
+                  ;; affect the `and' logic.
+                  (puthash package t straight--packages-not-to-rebuild))
+                 (straight--package-might-be-modified-p recipe))
               (straight--build-package recipe cause))
             (straight--maybe-save-build-cache)
             ;; Here we are not actually trying to build the


(defvar straight--success-cache (make-hash-table :test #'equal)
  "Hash table containing successfully built packages as keys.
The values are meaningless, and all non-nil.")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; API

            ;; The package was installed successfully.
            (puthash package t straight--success-cache)
            t))))))

;;;###autoload
(defun straight-rebuild-package (package &optional recursive)
  "Rebuild a PACKAGE.
PACKAGE is a string naming a package. Interactively, select
PACKAGE from the known packages in the current Emacs session
using `completing-read'. With prefix argument RECURSIVE, rebuild
all dependencies as well."
  (interactive
   (list
    (straight--select-package "Rebuild package")
    current-prefix-arg))
  (let ((straight--packages-to-rebuild
         (if recursive
             :all
           (let ((table (make-hash-table :test #'equal)))
             (puthash package t table)
             table)))
        ;; Because we bind this here, the table will be deleted and
        ;; the variable reset to nil when we break out of the let. No
        ;; need to clear the hash explicitly.
        (straight--packages-not-to-rebuild
         (make-hash-table :test #'equal)))
    (straight-use-package (intern package))))

;;;###autoload
(defun straight-rebuild-all ()
  "Rebuild all packages."
  (interactive)
  (let ((straight--packages-to-rebuild :all)
        (straight--packages-not-to-rebuild
         (make-hash-table :test #'equal)))
    (dolist (package (hash-table-keys straight--recipe-cache))
      (straight-use-package (intern package)))))

;;;###autoload
(defun straight-update-package (package)
