Skip to content

Commit de79404

Browse files
committed
Fix DEFSYSTEM printed package in system files for single-file projects.
ASDF 3 exports a symbol named "DEFSYSTEM" from ASDF, but its home package is named ASDF/DEFSYSTEM. When naively printed into a generated system file, it looks like this: (asdf/defsystem:defsystem ...) This is incompatible with older versions of ASDF. This commit overrides printing of external ASDF symbols so they always appear as "ASDF:FOO" rather than whatever their real home package is. Thanks to Stelian Ionescu for the pprint-dispatch-table approach.
1 parent 95cbc23 commit de79404

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

upstream-file.lisp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@
44

55
(defclass single-file-source (http-source) ())
66

7+
(defun asdf-external-symbol-p (thing)
8+
"Returns true if THING is a symbol exported from ASDF."
9+
(and (symbolp thing)
10+
(multiple-value-bind (symbol class)
11+
(find-symbol (symbol-name thing) :asdf)
12+
(and (eq symbol thing)
13+
(eql :external class)))))
14+
15+
(defun print-asdf-external-symbol (stream symbol)
16+
"If SYMBOL is exported from the ASDF package, print it with ASDF: as
17+
a prefix, rather than using its actual home package as a prefix. This
18+
matters for symbols like ASDF/DEFSYSTEM:DEFSYSTEM in ASDF 3."
19+
(format stream "~A:~A" :asdf (make-symbol (symbol-name symbol))))
20+
21+
(defparameter *single-file-pprint-dispatch*
22+
(let ((table (copy-pprint-dispatch)))
23+
(set-pprint-dispatch '(satisfies asdf-external-symbol-p)
24+
'print-asdf-external-symbol
25+
0
26+
table)
27+
table))
28+
729
(defgeneric single-file-name (source)
830
(:method ((source single-file-source))
931
(let ((slash (position #\/ (location source) :from-end t)))
@@ -26,11 +48,13 @@
2648

2749
(defgeneric write-single-file-asd (source file)
2850
(:method (source file)
29-
(with-open-file (stream file :direction :output)
51+
(with-open-file (stream file :direction :output
52+
:if-exists :supersede)
3053
(let ((*print-case* :downcase)
31-
(*package* (find-package :keyword)))
54+
(*package* (find-package :keyword))
55+
(*print-pprint-dispatch* *single-file-pprint-dispatch*))
3256
(format stream ";;;; ~A, automatically created by quicklisp~%~%"
33-
(project-name source))
57+
(file-namestring file))
3458
(format stream "~S~%" (single-file-asd-form source))))))
3559

3660
(defmethod make-release-tarball ((source single-file-source)

0 commit comments

Comments
 (0)