bundle.lisp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. ;;;; -------------------------------------------------------------------------
  2. ;;;; ASDF-Bundle
  3. (uiop/package:define-package :asdf/bundle
  4. (:recycle :asdf/bundle :asdf)
  5. (:use :uiop/common-lisp :uiop :asdf/upgrade
  6. :asdf/component :asdf/system :asdf/find-system :asdf/find-component :asdf/operation
  7. :asdf/action :asdf/lisp-action :asdf/plan :asdf/operate :asdf/defsystem)
  8. (:export
  9. #:bundle-op #:bundle-type #:program-system
  10. #:bundle-system #:bundle-pathname-type #:direct-dependency-files
  11. #:monolithic-op #:monolithic-bundle-op #:operation-monolithic-p
  12. #:basic-compile-bundle-op #:prepare-bundle-op
  13. #:compile-bundle-op #:load-bundle-op #:monolithic-compile-bundle-op #:monolithic-load-bundle-op
  14. #:lib-op #:monolithic-lib-op
  15. #:dll-op #:monolithic-dll-op
  16. #:deliver-asd-op #:monolithic-deliver-asd-op
  17. #:program-op #:image-op #:compiled-file #:precompiled-system #:prebuilt-system
  18. #:user-system-p #:user-system #:trivial-system-p
  19. #:prologue-code #:epilogue-code #:static-library))
  20. (in-package :asdf/bundle)
  21. (with-upgradability ()
  22. (defclass bundle-op (basic-compile-op)
  23. ;; NB: use of instance-allocated slots for operations is DEPRECATED
  24. ;; and only supported in a temporary fashion for backward compatibility.
  25. ;; Supported replacement: Define slots on program-system instead.
  26. ((bundle-type :initform :no-output-file :reader bundle-type :allocation :class))
  27. (:documentation "base class for operations that bundle outputs from multiple components"))
  28. (defclass monolithic-op (operation) ()
  29. (:documentation "A MONOLITHIC operation operates on a system *and all of its
  30. dependencies*. So, for example, a monolithic concatenate operation will
  31. concatenate together a system's components and all of its dependencies, but a
  32. simple concatenate operation will concatenate only the components of the system
  33. itself."))
  34. (defclass monolithic-bundle-op (bundle-op monolithic-op)
  35. ;; Old style way of specifying prologue and epilogue on ECL: in the monolithic operation.
  36. ;; DEPRECATED. Supported replacement: Define slots on program-system instead.
  37. ((prologue-code :initform nil :accessor prologue-code)
  38. (epilogue-code :initform nil :accessor epilogue-code))
  39. (:documentation "operations that are both monolithic-op and bundle-op"))
  40. (defclass program-system (system)
  41. ;; New style (ASDF3.1) way of specifying prologue and epilogue on ECL: in the system
  42. ((prologue-code :initform nil :initarg :prologue-code :reader prologue-code)
  43. (epilogue-code :initform nil :initarg :epilogue-code :reader epilogue-code)
  44. (no-uiop :initform nil :initarg :no-uiop :reader no-uiop)
  45. (prefix-lisp-object-files :initarg :prefix-lisp-object-files
  46. :initform nil :accessor prefix-lisp-object-files)
  47. (postfix-lisp-object-files :initarg :postfix-lisp-object-files
  48. :initform nil :accessor postfix-lisp-object-files)
  49. (extra-object-files :initarg :extra-object-files
  50. :initform nil :accessor extra-object-files)
  51. (extra-build-args :initarg :extra-build-args
  52. :initform nil :accessor extra-build-args)))
  53. (defmethod prologue-code ((x system)) nil)
  54. (defmethod epilogue-code ((x system)) nil)
  55. (defmethod no-uiop ((x system)) nil)
  56. (defmethod prefix-lisp-object-files ((x system)) nil)
  57. (defmethod postfix-lisp-object-files ((x system)) nil)
  58. (defmethod extra-object-files ((x system)) nil)
  59. (defmethod extra-build-args ((x system)) nil)
  60. (defclass link-op (bundle-op) ()
  61. (:documentation "Abstract operation for linking files together"))
  62. (defclass gather-operation (bundle-op)
  63. ((gather-operation :initform nil :allocation :class :reader gather-operation)
  64. (gather-type :initform :no-output-file :allocation :class :reader gather-type))
  65. (:documentation "Abstract operation for gathering many input files from a system"))
  66. (defun operation-monolithic-p (op)
  67. (typep op 'monolithic-op))
  68. ;; Dependencies of a gather-op are the actions of the dependent operation
  69. ;; for all the (sorted) required components for loading the system.
  70. ;; Monolithic operations typically use lib-op as the dependent operation,
  71. ;; and all system-level dependencies as required components.
  72. ;; Non-monolithic operations typically use compile-op as the dependent operation,
  73. ;; and all transitive sub-components as required components (excluding other systems).
  74. (defmethod component-depends-on ((o gather-operation) (s system))
  75. (let* ((mono (operation-monolithic-p o))
  76. (go (make-operation (or (gather-operation o) 'compile-op)))
  77. (bundle-p (typep go 'bundle-op))
  78. ;; In a non-mono operation, don't recurse to other systems.
  79. ;; In a mono operation gathering bundles, don't recurse inside systems.
  80. (component-type (if mono (if bundle-p 'system t) '(not system)))
  81. ;; In the end, only keep system bundles or non-system bundles, depending.
  82. (keep-component (if bundle-p 'system '(not system)))
  83. (deps
  84. ;; Required-components only looks at the dependencies of an action, excluding the action
  85. ;; itself, so it may be safely used by an action recursing on its dependencies (which
  86. ;; may or may not be an overdesigned API, since in practice we never use it that way).
  87. ;; Therefore, if we use :goal-operation 'load-op :keep-operation 'load-op, which looks
  88. ;; cleaner, we will miss the load-op on the requested system itself, which doesn't
  89. ;; matter for a regular system, but matters, a lot, for a package-inferred-system.
  90. ;; Using load-op as the goal operation and basic-compile-op as the keep-operation works
  91. ;; for our needs of gathering all the files we want to include in a bundle.
  92. ;; Note that we use basic-compile-op rather than compile-op so it will still work on
  93. ;; systems when *load-system-operation* is load-bundle-op.
  94. (required-components
  95. s :other-systems mono :component-type component-type :keep-component keep-component
  96. :goal-operation 'load-op :keep-operation 'basic-compile-op)))
  97. `((,go ,@deps) ,@(call-next-method))))
  98. ;; Create a single fasl for the entire library
  99. (defclass basic-compile-bundle-op (bundle-op)
  100. ((gather-type :initform #-(or clasp ecl mkcl) :fasl #+(or clasp ecl mkcl) :object
  101. :allocation :class)
  102. (bundle-type :initform :fasl :allocation :class))
  103. (:documentation "Base class for compiling into a bundle"))
  104. ;; Analog to prepare-op, for load-bundle-op and compile-bundle-op
  105. (defclass prepare-bundle-op (sideway-operation)
  106. ((sideway-operation
  107. :initform #+(or clasp ecl mkcl) 'load-bundle-op #-(or clasp ecl mkcl) 'load-op
  108. :allocation :class))
  109. (:documentation "Operation class for loading the bundles of a system's dependencies"))
  110. (defclass lib-op (link-op gather-operation non-propagating-operation)
  111. ((gather-type :initform :object :allocation :class)
  112. (bundle-type :initform :lib :allocation :class))
  113. (:documentation "Compile the system and produce a linkable static library (.a/.lib)
  114. for all the linkable object files associated with the system. Compare with DLL-OP.
  115. On most implementations, these object files only include extensions to the runtime
  116. written in C or another language with a compiler producing linkable object files.
  117. On CLASP, ECL, MKCL, these object files _also_ include the contents of Lisp files
  118. themselves. In any case, this operation will produce what you need to further build
  119. a static runtime for your system, or a dynamic library to load in an existing runtime."))
  120. ;; What works: on ECL, CLASP(?), MKCL, we link the many .o files from the system into the .so;
  121. ;; on other implementations, we combine (usually concatenate) the .fasl files into one.
  122. (defclass compile-bundle-op (basic-compile-bundle-op selfward-operation gather-operation
  123. #+(or clasp ecl mkcl) link-op)
  124. ((selfward-operation :initform '(prepare-bundle-op) :allocation :class))
  125. (:documentation "This operator is an alternative to COMPILE-OP. Build a system
  126. and all of its dependencies, but build only a single (\"monolithic\") FASL, instead
  127. of one per source file, which may be more resource efficient. That monolithic
  128. FASL should be loaded with LOAD-BUNDLE-OP, rather than LOAD-OP."))
  129. (defclass load-bundle-op (basic-load-op selfward-operation)
  130. ((selfward-operation :initform '(prepare-bundle-op compile-bundle-op) :allocation :class))
  131. (:documentation "This operator is an alternative to LOAD-OP. Build a system
  132. and all of its dependencies, using COMPILE-BUNDLE-OP. The difference with
  133. respect to LOAD-OP is that it builds only a single FASL, which may be
  134. faster and more resource efficient."))
  135. ;; NB: since the monolithic-op's can't be sideway-operation's,
  136. ;; if we wanted lib-op, dll-op, deliver-asd-op to be sideway-operation's,
  137. ;; we'd have to have the monolithic-op not inherit from the main op,
  138. ;; but instead inherit from a basic-FOO-op as with basic-compile-bundle-op above.
  139. (defclass dll-op (link-op gather-operation non-propagating-operation)
  140. ((gather-type :initform :object :allocation :class)
  141. (bundle-type :initform :dll :allocation :class))
  142. (:documentation "Compile the system and produce a dynamic loadable library (.so/.dll)
  143. for all the linkable object files associated with the system. Compare with LIB-OP."))
  144. (defclass deliver-asd-op (basic-compile-op selfward-operation)
  145. ((selfward-operation
  146. ;; TODO: implement link-op on all implementations, and make that
  147. ;; '(compile-bundle-op lib-op #-(or clasp ecl mkcl) dll-op)
  148. :initform '(compile-bundle-op #+(or clasp ecl mkcl) lib-op)
  149. :allocation :class))
  150. (:documentation "produce an asd file for delivering the system as a single fasl"))
  151. (defclass monolithic-deliver-asd-op (deliver-asd-op monolithic-bundle-op)
  152. ((selfward-operation
  153. ;; TODO: implement link-op on all implementations, and make that
  154. ;; '(monolithic-compile-bundle-op monolithic-lib-op #-(or clasp ecl mkcl) monolithic-dll-op)
  155. :initform '(monolithic-compile-bundle-op #+(or clasp ecl mkcl) monolithic-lib-op)
  156. :allocation :class))
  157. (:documentation "produce fasl and asd files for combined system and dependencies."))
  158. (defclass monolithic-compile-bundle-op
  159. (basic-compile-bundle-op monolithic-bundle-op
  160. #+(or clasp ecl mkcl) link-op gather-operation non-propagating-operation)
  161. ()
  162. (:documentation "Create a single fasl for the system and its dependencies."))
  163. (defclass monolithic-load-bundle-op (load-bundle-op monolithic-bundle-op)
  164. ((selfward-operation :initform 'monolithic-compile-bundle-op :allocation :class))
  165. (:documentation "Load a single fasl for the system and its dependencies."))
  166. (defclass monolithic-lib-op (lib-op monolithic-bundle-op non-propagating-operation)
  167. ((gather-type :initform :object :allocation :class))
  168. (:documentation "Compile the system and produce a linkable static library (.a/.lib)
  169. for all the linkable object files associated with the system or its dependencies. See LIB-OP."))
  170. (defclass monolithic-dll-op (dll-op monolithic-bundle-op non-propagating-operation)
  171. ((gather-type :initform :object :allocation :class))
  172. (:documentation "Compile the system and produce a dynamic loadable library (.so/.dll)
  173. for all the linkable object files associated with the system or its dependencies. See LIB-OP"))
  174. (defclass image-op (monolithic-bundle-op selfward-operation
  175. #+(or clasp ecl mkcl) link-op #+(or clasp ecl mkcl) gather-operation)
  176. ((bundle-type :initform :image :allocation :class)
  177. (gather-operation :initform 'lib-op :allocation :class)
  178. #+(or clasp ecl mkcl) (gather-type :initform :static-library :allocation :class)
  179. (selfward-operation :initform '(#-(or clasp ecl mkcl) load-op) :allocation :class))
  180. (:documentation "create an image file from the system and its dependencies"))
  181. (defclass program-op (image-op)
  182. ((bundle-type :initform :program :allocation :class))
  183. (:documentation "create an executable file from the system and its dependencies"))
  184. ;; From the ASDF-internal bundle-type identifier, get a filesystem-usable pathname type.
  185. (defun bundle-pathname-type (bundle-type)
  186. (etypecase bundle-type
  187. ((or null string) ;; pass through nil or string literal
  188. bundle-type)
  189. ((eql :no-output-file) ;; marker for a bundle-type that has NO output file
  190. (error "No output file, therefore no pathname type"))
  191. ((eql :fasl) ;; the type of a fasl
  192. #-(or clasp ecl mkcl) (compile-file-type) ; on image-based platforms, used as input and output
  193. #+(or clasp ecl mkcl) "fasb") ; on C-linking platforms, only used as output for system bundles
  194. ((member :image)
  195. #+allegro "dxl"
  196. #+(and clisp os-windows) "exe"
  197. #-(or allegro (and clisp os-windows)) "image")
  198. ;; NB: on CLASP and ECL these implementations, we better agree with
  199. ;; (compile-file-type :type bundle-type))
  200. ((eql :object) ;; the type of a linkable object file
  201. (os-cond ((os-unix-p) "o")
  202. ((os-windows-p) (if (featurep '(:or :mingw32 :mingw64)) "o" "obj"))))
  203. ((member :lib :static-library) ;; the type of a linkable library
  204. (os-cond ((os-unix-p) "a")
  205. ((os-windows-p) (if (featurep '(:or :mingw32 :mingw64)) "a" "lib"))))
  206. ((member :dll :shared-library) ;; the type of a shared library
  207. (os-cond ((os-macosx-p) "dylib") ((os-unix-p) "so") ((os-windows-p) "dll")))
  208. ((eql :program) ;; the type of an executable program
  209. (os-cond ((os-unix-p) nil) ((os-windows-p) "exe")))))
  210. ;; Compute the output-files for a given bundle action
  211. (defun bundle-output-files (o c)
  212. (let ((bundle-type (bundle-type o)))
  213. (unless (or (eq bundle-type :no-output-file) ;; NIL already means something regarding type.
  214. (and (null (input-files o c)) (not (member bundle-type '(:image :program)))))
  215. (let ((name (or (component-build-pathname c)
  216. (let ((suffix
  217. (unless (typep o 'program-op)
  218. ;; "." is no good separator for Logical Pathnames, so we use "--"
  219. (if (operation-monolithic-p o)
  220. "--all-systems"
  221. ;; These use a different type .fasb or .a instead of .fasl
  222. #-(or clasp ecl mkcl) "--system"))))
  223. (format nil "~A~@[~A~]" (component-name c) suffix))))
  224. (type (bundle-pathname-type bundle-type)))
  225. (values (list (subpathname (component-pathname c) name :type type))
  226. (eq (class-of o) (coerce-class (component-build-operation c)
  227. :package :asdf/interface
  228. :super 'operation
  229. :error nil)))))))
  230. (defmethod output-files ((o bundle-op) (c system))
  231. (bundle-output-files o c))
  232. #-(or clasp ecl mkcl)
  233. (progn
  234. (defmethod perform ((o image-op) (c system))
  235. (dump-image (output-file o c) :executable (typep o 'program-op)))
  236. (defmethod perform :before ((o program-op) (c system))
  237. (setf *image-entry-point* (ensure-function (component-entry-point c)))))
  238. (defclass compiled-file (file-component)
  239. ((type :initform #-(or clasp ecl mkcl) (compile-file-type) #+(or clasp ecl mkcl) "fasb"))
  240. (:documentation "Class for a file that is already compiled,
  241. e.g. as part of the implementation, of an outer build system that calls into ASDF,
  242. or of opaque libraries shipped along the source code."))
  243. (defclass precompiled-system (system)
  244. ((build-pathname :initarg :fasl))
  245. (:documentation "Class For a system that is delivered as a precompiled fasl"))
  246. (defclass prebuilt-system (system)
  247. ((build-pathname :initarg :static-library :initarg :lib
  248. :accessor prebuilt-system-static-library))
  249. (:documentation "Class for a system delivered with a linkable static library (.a/.lib)")))
  250. ;;;
  251. ;;; BUNDLE-OP
  252. ;;;
  253. ;;; This operation takes all components from one or more systems and
  254. ;;; creates a single output file, which may be
  255. ;;; a FASL, a statically linked library, a shared library, etc.
  256. ;;; The different targets are defined by specialization.
  257. ;;;
  258. (when-upgrading (:version "3.2.0")
  259. ;; Cancel any previously defined method
  260. (defmethod initialize-instance :after ((instance bundle-op) &rest initargs &key &allow-other-keys)
  261. (declare (ignore initargs))))
  262. (with-upgradability ()
  263. (defgeneric trivial-system-p (component))
  264. (defun user-system-p (s)
  265. (and (typep s 'system)
  266. (not (builtin-system-p s))
  267. (not (trivial-system-p s)))))
  268. (eval-when (#-lispworks :compile-toplevel :load-toplevel :execute)
  269. (deftype user-system () '(and system (satisfies user-system-p))))
  270. ;;;
  271. ;;; First we handle monolithic bundles.
  272. ;;; These are standalone systems which contain everything,
  273. ;;; including other ASDF systems required by the current one.
  274. ;;; A PROGRAM is always monolithic.
  275. ;;;
  276. ;;; MONOLITHIC SHARED LIBRARIES, PROGRAMS, FASL
  277. ;;;
  278. (with-upgradability ()
  279. (defun direct-dependency-files (o c &key (test 'identity) (key 'output-files) &allow-other-keys)
  280. ;; This function selects output files from direct dependencies;
  281. ;; your component-depends-on method must gather the correct dependencies in the correct order.
  282. (while-collecting (collect)
  283. (map-direct-dependencies
  284. t o c #'(lambda (sub-o sub-c)
  285. (loop :for f :in (funcall key sub-o sub-c)
  286. :when (funcall test f) :do (collect f))))))
  287. (defun pathname-type-equal-function (type)
  288. #'(lambda (p) (equalp (pathname-type p) type)))
  289. (defmethod input-files ((o gather-operation) (c system))
  290. (unless (eq (bundle-type o) :no-output-file)
  291. (direct-dependency-files
  292. o c :key 'output-files
  293. :test (pathname-type-equal-function (bundle-pathname-type (gather-type o))))))
  294. ;; Find the operation that produces a given bundle-type
  295. (defun select-bundle-operation (type &optional monolithic)
  296. (ecase type
  297. ((:dll :shared-library)
  298. (if monolithic 'monolithic-dll-op 'dll-op))
  299. ((:lib :static-library)
  300. (if monolithic 'monolithic-lib-op 'lib-op))
  301. ((:fasl)
  302. (if monolithic 'monolithic-compile-bundle-op 'compile-bundle-op))
  303. ((:image)
  304. 'image-op)
  305. ((:program)
  306. 'program-op))))
  307. ;;;
  308. ;;; LOAD-BUNDLE-OP
  309. ;;;
  310. ;;; This is like ASDF's LOAD-OP, but using bundle fasl files.
  311. ;;;
  312. (with-upgradability ()
  313. (defmethod component-depends-on ((o load-bundle-op) (c system))
  314. `((,o ,@(component-sideway-dependencies c))
  315. (,(if (user-system-p c) 'compile-bundle-op 'load-op) ,c)
  316. ,@(call-next-method)))
  317. (defmethod input-files ((o load-bundle-op) (c system))
  318. (when (user-system-p c)
  319. (output-files (find-operation o 'compile-bundle-op) c)))
  320. (defmethod perform ((o load-bundle-op) (c system))
  321. (when (input-files o c)
  322. (perform-lisp-load-fasl o c)))
  323. (defmethod mark-operation-done :after ((o load-bundle-op) (c system))
  324. (mark-operation-done (find-operation o 'load-op) c)))
  325. ;;;
  326. ;;; PRECOMPILED FILES
  327. ;;;
  328. ;;; This component can be used to distribute ASDF systems in precompiled form.
  329. ;;; Only useful when the dependencies have also been precompiled.
  330. ;;;
  331. (with-upgradability ()
  332. (defmethod trivial-system-p ((s system))
  333. (every #'(lambda (c) (typep c 'compiled-file)) (component-children s)))
  334. (defmethod input-files ((o operation) (c compiled-file))
  335. (list (component-pathname c)))
  336. (defmethod perform ((o load-op) (c compiled-file))
  337. (perform-lisp-load-fasl o c))
  338. (defmethod perform ((o load-source-op) (c compiled-file))
  339. (perform (find-operation o 'load-op) c))
  340. (defmethod perform ((o operation) (c compiled-file))
  341. nil))
  342. ;;;
  343. ;;; Pre-built systems
  344. ;;;
  345. (with-upgradability ()
  346. (defmethod trivial-system-p ((s prebuilt-system))
  347. t)
  348. (defmethod perform ((o link-op) (c prebuilt-system))
  349. nil)
  350. (defmethod perform ((o basic-compile-bundle-op) (c prebuilt-system))
  351. nil)
  352. (defmethod perform ((o lib-op) (c prebuilt-system))
  353. nil)
  354. (defmethod perform ((o dll-op) (c prebuilt-system))
  355. nil)
  356. (defmethod component-depends-on ((o gather-operation) (c prebuilt-system))
  357. nil)
  358. (defmethod output-files ((o lib-op) (c prebuilt-system))
  359. (values (list (prebuilt-system-static-library c)) t)))
  360. ;;;
  361. ;;; PREBUILT SYSTEM CREATOR
  362. ;;;
  363. (with-upgradability ()
  364. (defmethod output-files ((o deliver-asd-op) (s system))
  365. (list (make-pathname :name (component-name s) :type "asd"
  366. :defaults (component-pathname s))))
  367. (defmethod perform ((o deliver-asd-op) (s system))
  368. (let* ((inputs (input-files o s))
  369. (fasl (first inputs))
  370. (library (second inputs))
  371. (asd (first (output-files o s)))
  372. (name (if (and fasl asd) (pathname-name asd) (return-from perform)))
  373. (version (component-version s))
  374. (dependencies
  375. (if (operation-monolithic-p o)
  376. ;; We want only dependencies, and we use basic-load-op rather than load-op so that
  377. ;; this will keep working on systems when *load-system-operation* is load-bundle-op
  378. (remove-if-not 'builtin-system-p
  379. (required-components s :component-type 'system
  380. :keep-operation 'basic-load-op))
  381. (while-collecting (x) ;; resolve the sideway-dependencies of s
  382. (map-direct-dependencies
  383. t 'load-op s
  384. #'(lambda (o c)
  385. (when (and (typep o 'load-op) (typep c 'system))
  386. (x c)))))))
  387. (depends-on (mapcar 'coerce-name dependencies)))
  388. (when (pathname-equal asd (system-source-file s))
  389. (cerror "overwrite the asd file"
  390. "~/asdf-action:format-action/ is going to overwrite the system definition file ~S ~
  391. which is probably not what you want; you probably need to tweak your output translations."
  392. (cons o s) asd))
  393. (with-open-file (s asd :direction :output :if-exists :supersede
  394. :if-does-not-exist :create)
  395. (format s ";;; Prebuilt~:[~; monolithic~] ASDF definition for system ~A~%"
  396. (operation-monolithic-p o) name)
  397. (format s ";;; Built for ~A ~A on a ~A/~A ~A~%"
  398. (lisp-implementation-type)
  399. (lisp-implementation-version)
  400. (software-type)
  401. (machine-type)
  402. (software-version))
  403. (let ((*package* (find-package :asdf-user)))
  404. (pprint `(defsystem ,name
  405. :class prebuilt-system
  406. :version ,version
  407. :depends-on ,depends-on
  408. :components ((:compiled-file ,(pathname-name fasl)))
  409. ,@(when library `(:lib ,(file-namestring library))))
  410. s)
  411. (terpri s)))))
  412. #-(or clasp ecl mkcl)
  413. (defmethod perform ((o basic-compile-bundle-op) (c system))
  414. (let* ((input-files (input-files o c))
  415. (fasl-files (remove (compile-file-type) input-files :key #'pathname-type :test-not #'equalp))
  416. (non-fasl-files (remove (compile-file-type) input-files :key #'pathname-type :test #'equalp))
  417. (output-files (output-files o c))
  418. (output-file (first output-files)))
  419. (assert (eq (not input-files) (not output-files)))
  420. (when input-files
  421. (when non-fasl-files
  422. (error "On ~A, asdf/bundle can only bundle FASL files, but these were also produced: ~S"
  423. (implementation-type) non-fasl-files))
  424. (when (or (prologue-code c) (epilogue-code c))
  425. (error "prologue-code and epilogue-code are not supported on ~A"
  426. (implementation-type)))
  427. (with-staging-pathname (output-file)
  428. (combine-fasls fasl-files output-file)))))
  429. (defmethod input-files ((o load-op) (s precompiled-system))
  430. (bundle-output-files (find-operation o 'compile-bundle-op) s))
  431. (defmethod perform ((o load-op) (s precompiled-system))
  432. (perform-lisp-load-fasl o s))
  433. (defmethod component-depends-on ((o load-bundle-op) (s precompiled-system))
  434. #+xcl (declare (ignorable o))
  435. `((load-op ,s) ,@(call-next-method))))
  436. #| ;; Example use:
  437. (asdf:defsystem :precompiled-asdf-utils :class asdf::precompiled-system :fasl (asdf:apply-output-translations (asdf:system-relative-pathname :asdf-utils "asdf-utils.system.fasl")))
  438. (asdf:load-system :precompiled-asdf-utils)
  439. |#
  440. #+(or clasp ecl mkcl)
  441. (with-upgradability ()
  442. #+ecl ;; doesn't work on clasp or mkcl (yet?).
  443. (unless (use-ecl-byte-compiler-p)
  444. (setf *load-system-operation* 'load-bundle-op))
  445. (defun system-module-pathname (module)
  446. (let ((name (coerce-name module)))
  447. (some
  448. 'file-exists-p
  449. (list
  450. #+clasp (compile-file-pathname (make-pathname :name name :defaults "sys:") :output-type :object)
  451. #+ecl (compile-file-pathname (make-pathname :name name :defaults "sys:") :type :lib)
  452. #+ecl (compile-file-pathname (make-pathname :name name :defaults "sys:") :type :object)
  453. #+mkcl (make-pathname :name name :type (bundle-pathname-type :lib) :defaults #p"sys:")
  454. #+mkcl (make-pathname :name name :type (bundle-pathname-type :lib) :defaults #p"sys:contrib;")))))
  455. (defun make-prebuilt-system (name &optional (pathname (system-module-pathname name)))
  456. "Creates a prebuilt-system if PATHNAME isn't NIL."
  457. (when pathname
  458. (make-instance 'prebuilt-system
  459. :name (coerce-name name)
  460. :static-library (resolve-symlinks* pathname))))
  461. (defmethod component-depends-on :around ((o image-op) (c system))
  462. (destructuring-bind ((lib-op . deps)) (call-next-method)
  463. (labels ((has-it-p (x) (find x deps :test 'equal :key 'coerce-name))
  464. (ensure-linkable-system (x)
  465. (unless (has-it-p x)
  466. (or (if-let (s (find-system x))
  467. (and (system-source-directory x)
  468. (list s)))
  469. (if-let (p (system-module-pathname x))
  470. (list (make-prebuilt-system x p)))))))
  471. `((,lib-op
  472. ,@(unless (no-uiop c)
  473. (append (ensure-linkable-system "cmp")
  474. (or (ensure-linkable-system "uiop")
  475. (ensure-linkable-system "asdf"))))
  476. ,@deps)))))
  477. (defmethod perform ((o link-op) (c system))
  478. (let* ((object-files (input-files o c))
  479. (output (output-files o c))
  480. (bundle (first output))
  481. (programp (typep o 'program-op))
  482. (kind (bundle-type o)))
  483. (when output
  484. (apply 'create-image
  485. bundle (append
  486. (when programp (prefix-lisp-object-files c))
  487. object-files
  488. (when programp (postfix-lisp-object-files c)))
  489. :kind kind
  490. :prologue-code (when programp (prologue-code c))
  491. :epilogue-code (when programp (epilogue-code c))
  492. :build-args (when programp (extra-build-args c))
  493. :extra-object-files (when programp (extra-object-files c))
  494. :no-uiop (no-uiop c)
  495. (when programp `(:entry-point ,(component-entry-point c))))))))