From 4ed76c32050753c8a4450c342a1592881e11d63d Mon Sep 17 00:00:00 2001
From: Francois-Rene Rideau <fare@tunes.org>
Date: Fri, 31 Mar 2017 17:09:59 -0400
Subject: [PATCH] Add test case for spurious rebuild in ddo

I noticed that some systems, e.g. fast-io, will cause UIOP, CFFI, and
everything that depends on it, to be constantly recompiled.
Interestingly, this doesn't happen with any of the systems that fast-io
directly depends on: alexandria, trivial-gray-streams, and static-vectors.
And interestingly, the test case, once reduced, is exactly isomorphic to
the test case already in test-defsystem-depends-on-phase-overlap.script:
fast-io => main-system, alexandria => overlapping-dependency,
static-vectors => intermediate-dependency, bazel => defsystem-dependency
And indeed, adding a test for it detects the failure.
---
 .../defsystem-dependency.lisp                 |  6 ++++++
 .../overlapping-dependency.lisp               |  6 ++++++
 ...-defsystem-depends-on-phase-overlap.script | 19 ++++++++++++++-----
 3 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/test/defsystem-depends-on/defsystem-dependency.lisp b/test/defsystem-depends-on/defsystem-dependency.lisp
index 0442efc70..c5f34a143 100644
--- a/test/defsystem-depends-on/defsystem-dependency.lisp
+++ b/test/defsystem-depends-on/defsystem-dependency.lisp
@@ -3,3 +3,9 @@
 (incf *dd*)
 (format t "Loaded defsystem-dependency.lisp ~d time~(~:*~p~)~%" *dd*)
 (setf (find-class 'asdf::my-cl-source-file) (find-class 'cl-source-file))
+
+(eval-when (:compile-toplevel :load-toplevel :execute)
+  (defvar *cdd* 0))
+
+(eval-when (:compile-toplevel :execute)
+  (incf *cdd*))
diff --git a/test/defsystem-depends-on/overlapping-dependency.lisp b/test/defsystem-depends-on/overlapping-dependency.lisp
index 68f718059..a923080f1 100644
--- a/test/defsystem-depends-on/overlapping-dependency.lisp
+++ b/test/defsystem-depends-on/overlapping-dependency.lisp
@@ -1,3 +1,9 @@
 (in-package :asdf-test)
 (defvar *od* 0)
 (incf *od*)
+
+(eval-when (:compile-toplevel :load-toplevel :execute)
+  (defvar *cod* 0))
+
+(eval-when (:compile-toplevel :execute)
+  (incf *cod*))
diff --git a/test/test-defsystem-depends-on-phase-overlap.script b/test/test-defsystem-depends-on-phase-overlap.script
index 1b1bae41b..8c8cb1124 100644
--- a/test/test-defsystem-depends-on-phase-overlap.script
+++ b/test/test-defsystem-depends-on-phase-overlap.script
@@ -8,14 +8,16 @@
 (defvar *dd* 0)
 (defvar *id* 0)
 (defvar *ms* 0)
+(defvar *cod* 0)
+(defvar *cdd* 0)
 (defun reset-vars (&optional (x 0))
-  (setf *od* x *dd* x *id* x *ms* x))
-(assert-equal (list *od* *dd* *id* *ms*) '(0 0 0 0))
+  (setf *od* x *dd* x *id* x *ms* x *cod* x *cdd* x))
+(assert-equal (list *od* *dd* *id* *ms* *cod* *cdd*) '(0 0 0 0 0 0))
 
 (DBG "Finding main-system doesn't load defsystem-dependency")
 (reset-vars)
 (find-system "main-system")
-(assert-equal (list *od* *dd* *id* *ms*) '(0 0 0 0))
+(assert-equal (list *od* *dd* *id* *ms* *cod* *cdd*) '(0 0 0 0 0 0))
 
 (DBG "Finding intermediate-dependency does load defsystem-dependency")
 (reset-vars)
@@ -25,12 +27,18 @@
 (DBG "Loading main-system doesn't reload defsystem-dependency or overlapping-dependency")
 (reset-vars)
 (load-system "main-system")
-(assert-equal (list *od* *dd* *id* *ms*) '(0 0 1 1))
+(assert-equal (list *od* *dd* *id* *ms* *cod* *cdd*) '(0 0 1 1 0 0))
 
 (DBG "Loading main-system a second time doesn't reload anything")
 (reset-vars)
 (load-system "main-system")
-(assert-equal (list *od* *dd* *id* *ms*) '(0 0 0 0))
+(assert-equal (list *od* *dd* *id* *ms* *cod* *cdd*) '(0 0 0 0 0 0))
+
+(DBG "Loading main-system in a different session loads but doesn't recompile")
+(reset-vars)
+(asdf::clear-registered-systems)
+(load-system "main-system")
+(assert-equal (list *od* *dd* *id* *ms* *cod* *cdd*) '(1 1 1 1 0 0))
 
 (DBG :foo
      (component-sideway-dependencies (find-system "intermediate-dependency"))
@@ -55,3 +63,4 @@
   ;; This is what causes an issue without phase escalation:
   (test-system "defsystem-dependency"))
 (assert-equal *dd* 10)
+
-- 
GitLab