bundle.lisp 26 KB
Newer Older
1 2 3
;;;; -------------------------------------------------------------------------
;;;; ASDF-Bundle

4
(uiop/package:define-package :asdf/bundle
5
  (:recycle :asdf/bundle :asdf)
6
  (:use :uiop/common-lisp :uiop :asdf/upgrade
7
   :asdf/component :asdf/system :asdf/find-system :asdf/find-component :asdf/operation
8
   :asdf/action :asdf/lisp-action :asdf/plan :asdf/operate :asdf/defsystem)
9
  (:export
10
   #:bundle-op #:bundle-type #:program-system
11 12
   #:bundle-system #:bundle-pathname-type #:bundlable-file-p #:direct-dependency-files
   #:monolithic-op #:monolithic-bundle-op #:operation-monolithic-p
13 14
   #:basic-compile-bundle-op #:prepare-bundle-op
   #:compile-bundle-op #:load-bundle-op #:monolithic-compile-bundle-op #:monolithic-load-bundle-op
15 16
   #:lib-op #:monolithic-lib-op
   #:dll-op #:monolithic-dll-op
17 18
   #:deliver-asd-op #:monolithic-deliver-asd-op
   #:program-op #:image-op #:compiled-file #:precompiled-system #:prebuilt-system
19
   #:user-system-p #:user-system #:trivial-system-p
20
   #:make-build
21
   #:build-args #:name-suffix #:prologue-code #:epilogue-code #:static-library))
22 23
(in-package :asdf/bundle)

24
(with-upgradability ()
25
  (defclass bundle-op (basic-compile-op)
26
    ((build-args :initarg :args :initform nil :accessor extra-build-args)
27 28
     (name-suffix :initarg :name-suffix :initform nil)
     (bundle-type :initform :no-output-file :reader bundle-type)
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
29
     #+(or clasp ecl) (lisp-files :initform nil :accessor extra-object-files)))
30

31 32 33 34 35 36 37 38 39
  (defclass monolithic-op (operation) ()
    (:documentation "A MONOLITHIC operation operates on a system *and all of its
dependencies*.  So, for example, a monolithic concatenate operation will
concatenate together a system's components and all of its dependencies, but a
simple concatenate operation will concatenate only the components of the system
itself.")) ;; operation on a system and its dependencies

  (defclass monolithic-bundle-op (monolithic-op bundle-op)
    ;; Old style way of specifying prologue and epilogue on ECL: in the monolithic operation
40 41
    ((prologue-code :initform nil :accessor prologue-code)
     (epilogue-code :initform nil :accessor epilogue-code)))
42

43
  (defclass program-system (system)
44
    ;; New style (ASDF3.1) way of specifying prologue and epilogue on ECL: in the system
45 46
    ((prologue-code :initform nil :initarg :prologue-code :reader prologue-code)
     (epilogue-code :initform nil :initarg :epilogue-code :reader epilogue-code)
47
     (no-uiop :initform nil :initarg :no-uiop :reader no-uiop)
48
     (prefix-lisp-object-files :initarg :prefix-lisp-object-files
49
                               :initform nil :accessor prefix-lisp-object-files)
50
     (postfix-lisp-object-files :initarg :postfix-lisp-object-files
51 52 53
                                :initform nil :accessor postfix-lisp-object-files)
     (extra-object-files :initarg :extra-object-files
                         :initform nil :accessor extra-object-files)
54
     (extra-build-args :initarg :extra-build-args
55
                       :initform nil :accessor extra-build-args)))
56

57 58
  (defmethod prologue-code ((x t)) nil)
  (defmethod epilogue-code ((x t)) nil)
59
  (defmethod no-uiop ((x t)) nil)
60 61 62 63
  (defmethod prefix-lisp-object-files ((x t)) nil)
  (defmethod postfix-lisp-object-files ((x t)) nil)
  (defmethod extra-object-files ((x t)) nil)
  (defmethod extra-build-args ((x t)) nil)
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85

  (defclass link-op (bundle-op) ()
    (:documentation "Abstract operation for linking files together"))

  (defclass gather-op (bundle-op)
    ((gather-op :initform nil :allocation :class :reader gather-op))
    (:documentation "Abstract operation for gathering many input files from a system"))

  (defun operation-monolithic-p (op)
    (typep op 'monolithic-op))

  (defmethod component-depends-on ((o gather-op) (s system))
    (let* ((mono (operation-monolithic-p o))
           (deps
             (required-components
              s :other-systems mono :component-type (if mono 'system '(not system))
                :goal-operation (find-operation o 'load-op)
                :keep-operation 'compile-op)))
      ;; NB: the explicit make-operation on ECL and MKCL
      ;; ensures that we drop the original-initargs and its magic flags when recursing.
      `((,(make-operation (or (gather-op o) (if mono 'lib-op 'compile-op))) ,@deps)
        ,@(call-next-method))))
86

87
  ;; create a single fasl for the entire library
88
  (defclass basic-compile-bundle-op (bundle-op)
89
    ((bundle-type :initform :fasl)))
90

91
  (defclass prepare-bundle-op (sideway-operation)
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
92 93 94
    ((sideway-operation
      :initform #+(or clasp ecl mkcl) 'load-bundle-op #-(or clasp ecl mkcl) 'load-op
      :allocation :class)))
95 96 97 98 99

  (defclass lib-op (link-op gather-op non-propagating-operation)
    ((bundle-type :initform :lib))
    (:documentation "compile the system and produce linkable (.a) library for it."))

100
  (defclass compile-bundle-op (basic-compile-bundle-op selfward-operation
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
101 102 103
                               #+(or clasp ecl mkcl) link-op #-(or clasp ecl) gather-op)
    ((selfward-operation :initform '(prepare-bundle-op #+(or clasp ecl) lib-op)
                         :allocation :class)))
104

105 106
  (defclass load-bundle-op (basic-load-op selfward-operation)
    ((selfward-operation :initform '(prepare-bundle-op compile-bundle-op) :allocation :class)))
107 108

  ;; NB: since the monolithic-op's can't be sideway-operation's,
109
  ;; if we wanted lib-op, dll-op, deliver-asd-op to be sideway-operation's,
110
  ;; we'd have to have the monolithic-op not inherit from the main op,
111
  ;; but instead inherit from a basic-FOO-op as with basic-compile-bundle-op above.
112

113
  (defclass dll-op (link-op gather-op non-propagating-operation)
114
    ((bundle-type :initform :dll))
115
    (:documentation "compile the system and produce dynamic (.so/.dll) library for it."))
116

117
  (defclass deliver-asd-op (basic-compile-op selfward-operation)
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
118
    ((selfward-operation :initform '(compile-bundle-op #+(or clasp ecl mkcl) lib-op) :allocation :class))
119
    (:documentation "produce an asd file for delivering the system as a single fasl"))
120 121


122
  (defclass monolithic-deliver-asd-op (monolithic-bundle-op deliver-asd-op)
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
123 124 125
    ((selfward-operation
      :initform '(monolithic-compile-bundle-op #+(or clasp ecl mkcl) monolithic-lib-op)
      :allocation :class))
126 127
    (:documentation "produce fasl and asd files for combined system and dependencies."))

128
  (defclass monolithic-compile-bundle-op (monolithic-bundle-op basic-compile-bundle-op
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
129 130
                                          #+(or clasp ecl mkcl) link-op gather-op non-propagating-operation)
    ((gather-op :initform #+(or clasp ecl mkcl) 'lib-op #-(or clasp ecl mkcl) 'compile-bundle-op :allocation :class))
131
    (:documentation "Create a single fasl for the system and its dependencies."))
132

133 134 135 136
  (defclass monolithic-load-bundle-op (monolithic-bundle-op load-bundle-op)
    ((selfward-operation :initform 'monolithic-compile-bundle-op :allocation :class))
    (:documentation "Load a single fasl for the system and its dependencies."))

137 138
  (defclass monolithic-lib-op (monolithic-bundle-op lib-op non-propagating-operation) ()
    (:documentation "Create a single linkable library for the system and its dependencies."))
139

140
  (defclass monolithic-dll-op (monolithic-bundle-op dll-op non-propagating-operation)
141 142
    ((bundle-type :initform :dll))
    (:documentation "Create a single dynamic (.so/.dll) library for the system and its dependencies."))
143

144
  (defclass image-op (monolithic-bundle-op selfward-operation
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
145
                      #+(or clasp ecl mkcl) link-op #+(or clasp ecl mkcl) gather-op)
146
    ((bundle-type :initform :image)
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
147
     (selfward-operation :initform '(#-(or clasp ecl mkcl) load-op) :allocation :class))
148 149 150 151
    (:documentation "create an image file from the system and its dependencies"))

  (defclass program-op (image-op)
    ((bundle-type :initform :program))
152
    (:documentation "create an executable file from the system and its dependencies"))
153 154 155

  (defun bundle-pathname-type (bundle-type)
    (etypecase bundle-type
156
      ((eql :no-output-file) nil) ;; should we error out instead?
157
      ((or null string) bundle-type)
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
158 159
      ((eql :fasl) #-(or clasp ecl mkcl) (compile-file-type) #+(or clasp ecl mkcl) "fasb")
      #+(or clasp ecl)
160
      ((member :dll :lib :shared-library :static-library :program :object :program)
161
       (compile-file-type :type bundle-type))
162
      ((member :image) #-allegro "image" #+allegro "dxl")
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
163 164 165 166
      ((member :dll :shared-library) (os-cond ((os-macosx-p) "dylib") ((os-unix-p) "so") ((os-windows-p) "dll")))
      ((member :lib :static-library) (os-cond ((os-unix-p) "a")
                                              ((os-windows-p) (if (featurep '(:or :mingw32 :mingw64)) "a" "lib"))))
      ((eql :program) (os-cond ((os-unix-p) nil) ((os-windows-p) "exe")))))
167 168

  (defun bundle-output-files (o c)
169 170 171 172 173 174 175 176
    (let ((bundle-type (bundle-type o)))
      (unless (or (eq bundle-type :no-output-file) ;; NIL already means something regarding type.
                  (and (null (input-files o c)) (not (member bundle-type '(:image :program)))))
        (let ((name (or (component-build-pathname c)
                        (format nil "~A~@[~A~]" (component-name c) (slot-value o 'name-suffix))))
              (type (bundle-pathname-type bundle-type)))
          (values (list (subpathname (component-pathname c) name :type type))
                  (eq (type-of o) (component-build-operation c)))))))
177 178 179 180

  (defmethod output-files ((o bundle-op) (c system))
    (bundle-output-files o c))

Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
181
  #-(or clasp ecl mkcl)
182 183 184 185 186
  (progn
    (defmethod perform ((o image-op) (c system))
      (dump-image (output-file o c) :executable (typep o 'program-op)))
    (defmethod perform :before ((o program-op) (c system))
      (setf *image-entry-point* (ensure-function (component-entry-point c)))))
187 188

  (defclass compiled-file (file-component)
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
189
    ((type :initform #-(or clasp ecl mkcl) (compile-file-type) #+(or clasp ecl mkcl) "fasb")))
190 191 192 193 194 195 196 197

  (defclass precompiled-system (system)
    ((build-pathname :initarg :fasl)))

  (defclass prebuilt-system (system)
    ((build-pathname :initarg :static-library :initarg :lib
                     :accessor prebuilt-system-static-library))))

198 199 200 201 202 203 204 205 206

;;;
;;; BUNDLE-OP
;;;
;;; This operation takes all components from one or more systems and
;;; creates a single output file, which may be
;;; a FASL, a statically linked library, a shared library, etc.
;;; The different targets are defined by specialization.
;;;
207 208 209 210
(with-upgradability ()
  (defmethod initialize-instance :after ((instance bundle-op) &rest initargs
                                         &key (name-suffix nil name-suffix-p)
                                         &allow-other-keys)
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
211
    (declare (ignore initargs name-suffix))
212 213 214
    (unless name-suffix-p
      (setf (slot-value instance 'name-suffix)
            (unless (typep instance 'program-op)
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
215 216
              ;; "." is no good separator for Logical Pathnames, so we use "--"
              (if (operation-monolithic-p instance) "--all-systems" #-(or clasp ecl mkcl) "--system"))))
217
    (when (typep instance 'monolithic-bundle-op)
218
      (destructuring-bind (&key lisp-files prologue-code epilogue-code
219 220
                           &allow-other-keys)
          (operation-original-initargs instance)
221 222
        (setf (prologue-code instance) prologue-code
              (epilogue-code instance) epilogue-code)
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
223 224
        #-(or clasp ecl) (assert (null (or lisp-files #-mkcl epilogue-code #-mkcl prologue-code)))
        #+(or clasp ecl) (setf (extra-object-files instance) lisp-files)))
225
    (setf (extra-build-args instance)
226
          (remove-plist-keys
227 228
           '(:type :monolithic :name-suffix :epilogue-code :prologue-code :lisp-files
             :force :force-not :plan-class) ;; TODO: refactor so we don't mix plan and operation arguments
229
           (operation-original-initargs instance))))
230 231 232 233

  (defun bundlable-file-p (pathname)
    (let ((type (pathname-type pathname)))
      (declare (ignorable type))
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
234 235
      (or #+(or clasp ecl) (or (equalp type (compile-file-type :type :object))
                               (equalp type (compile-file-type :type :static-library)))
236 237 238
          #+mkcl (or (equalp type (compile-file-type :fasl-p nil))
                     #+(or unix mingw32 mingw64) (equalp type "a") ;; valid on Unix and MinGW
                     #+(and windows (not (or mingw32 mingw64))) (equalp type "lib"))
239
          #+(or abcl allegro clisp clozure cmu lispworks sbcl scl xcl) (equalp type (compile-file-type)))))
240 241 242 243 244 245

  (defgeneric* (trivial-system-p) (component))

  (defun user-system-p (s)
    (and (typep s 'system)
         (not (builtin-system-p s))
246
         (not (trivial-system-p s)))))
247

248
(eval-when (#-lispworks :compile-toplevel :load-toplevel :execute)
249
  (deftype user-system () '(and system (satisfies user-system-p))))
250 251 252 253 254 255 256 257 258

;;;
;;; First we handle monolithic bundles.
;;; These are standalone systems which contain everything,
;;; including other ASDF systems required by the current one.
;;; A PROGRAM is always monolithic.
;;;
;;; MONOLITHIC SHARED LIBRARIES, PROGRAMS, FASL
;;;
259 260
(with-upgradability ()
  (defun direct-dependency-files (o c &key (test 'identity) (key 'output-files) &allow-other-keys)
261 262
    ;; This file selects output files from direct dependencies;
    ;; your component-depends-on method better gathered the correct dependencies in the correct order.
263 264
    (while-collecting (collect)
      (map-direct-dependencies
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
265 266 267
       t o c #'(lambda (sub-o sub-c)
                 (loop :for f :in (funcall key sub-o sub-c)
                       :when (funcall test f) :do (collect f))))))
268

269
  (defmethod input-files ((o gather-op) (c system))
270 271
    (unless (eq (bundle-type o) :no-output-file)
      (direct-dependency-files o c :test 'bundlable-file-p :key 'output-files)))
272 273 274 275 276 277 278 279

  (defun select-bundle-operation (type &optional monolithic)
    (ecase type
      ((:dll :shared-library)
       (if monolithic 'monolithic-dll-op 'dll-op))
      ((:lib :static-library)
       (if monolithic 'monolithic-lib-op 'lib-op))
      ((:fasl)
280
       (if monolithic 'monolithic-compile-bundle-op 'compile-bundle-op))
281 282
      ((:image)
       'image-op)
283 284 285
      ((:program)
       'program-op)))

286
  ;; DEPRECATED. This is originally from asdf-ecl.lisp. Does anyone use it?
287 288 289 290 291 292
  (defun make-build (system &rest args &key (monolithic nil) (type :fasl)
                             (move-here nil move-here-p)
                             &allow-other-keys)
    (let* ((operation-name (select-bundle-operation type monolithic))
           (move-here-path (if (and move-here
                                    (typep move-here '(or pathname string)))
293
                               (ensure-pathname move-here :namestring :lisp :ensure-directory t)
294 295 296 297 298 299 300
                               (system-relative-pathname system "asdf-output/")))
           (operation (apply #'operate operation-name
                             system
                             (remove-plist-keys '(:monolithic :type :move-here) args)))
           (system (find-system system))
           (files (and system (output-files operation system))))
      (if (or move-here (and (null move-here-p)
301
                             (member operation-name '(:program :image))))
302 303 304 305 306 307 308
          (loop :with dest-path = (resolve-symlinks* (ensure-directories-exist move-here-path))
                :for f :in files
                :for new-f = (make-pathname :name (pathname-name f)
                                            :type (pathname-type f)
                                            :defaults dest-path)
                :do (rename-file-overwriting-target f new-f)
                :collect new-f)
309 310 311 312 313 314
          files)))

  ;; DEPRECATED. Does anyone use this?
  (defun bundle-system (system &rest args &key force (verbose t) version &allow-other-keys)
    (declare (ignore force verbose version))
    (apply #'operate 'deliver-asd-op system args)))
315 316

;;;
317
;;; LOAD-BUNDLE-OP
318
;;;
319
;;; This is like ASDF's LOAD-OP, but using bundle fasl files.
320
;;;
321
(with-upgradability ()
322
  (defmethod component-depends-on ((o load-bundle-op) (c system))
323
    `((,o ,@(component-sideway-dependencies c))
324
      (,(if (user-system-p c) 'compile-bundle-op 'load-op) ,c)
325
      ,@(call-next-method)))
326

327
  (defmethod input-files ((o load-bundle-op) (c system))
328
    (when (user-system-p c)
329
      (output-files (find-operation o 'compile-bundle-op) c)))
330

331
  (defmethod perform ((o load-bundle-op) (c system))
332 333
    (when (input-files o c)
      (perform-lisp-load-fasl o c)))
334

335
  (defmethod mark-operation-done :after ((o load-bundle-op) (c system))
336
    (mark-operation-done (find-operation o 'load-op) c)))
337 338 339 340 341 342 343

;;;
;;; PRECOMPILED FILES
;;;
;;; This component can be used to distribute ASDF systems in precompiled form.
;;; Only useful when the dependencies have also been precompiled.
;;;
344 345 346 347
(with-upgradability ()
  (defmethod trivial-system-p ((s system))
    (every #'(lambda (c) (typep c 'compiled-file)) (component-children s)))

Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
348
  (defmethod input-files ((o operation) (c compiled-file))
349
    (list (component-pathname c)))
350 351 352 353
  (defmethod perform ((o load-op) (c compiled-file))
    (perform-lisp-load-fasl o c))
  (defmethod perform ((o load-source-op) (c compiled-file))
    (perform (find-operation o 'load-op) c))
354
  (defmethod perform ((o operation) (c compiled-file))
355
    nil))
356 357 358 359

;;;
;;; Pre-built systems
;;;
360 361 362
(with-upgradability ()
  (defmethod trivial-system-p ((s prebuilt-system))
    t)
363

364
  (defmethod perform ((o link-op) (c prebuilt-system))
365
    nil)
366

367
  (defmethod perform ((o basic-compile-bundle-op) (c prebuilt-system))
368
    nil)
369

370
  (defmethod perform ((o lib-op) (c prebuilt-system))
371 372
    nil)

373
  (defmethod perform ((o dll-op) (c prebuilt-system))
374
    nil)
375 376

  (defmethod component-depends-on ((o gather-op) (c prebuilt-system))
377 378 379
    nil)

  (defmethod output-files ((o lib-op) (c prebuilt-system))
380
    (values (list (prebuilt-system-static-library c)) t)))
381

382

383 384 385
;;;
;;; PREBUILT SYSTEM CREATOR
;;;
386
(with-upgradability ()
387
  (defmethod output-files ((o deliver-asd-op) (s system))
388 389 390
    (list (make-pathname :name (component-name s) :type "asd"
                         :defaults (component-pathname s))))

391
  (defmethod perform ((o deliver-asd-op) (s system))
392 393 394
    (let* ((inputs (input-files o s))
           (fasl (first inputs))
           (library (second inputs))
395
           (asd (first (output-files o s)))
396
           (name (if (and fasl asd) (pathname-name asd) (return-from perform)))
397
           (version (component-version s))
398 399 400 401 402 403 404
           (dependencies
             (if (operation-monolithic-p o)
                 (remove-if-not 'builtin-system-p
                                (required-components s :component-type 'system
                                                       :keep-operation 'load-op))
                 (while-collecting (x) ;; resolve the sideway-dependencies of s
                   (map-direct-dependencies
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
405
                    t 'load-op s
406 407 408 409 410 411 412 413
                    #'(lambda (o c)
                        (when (and (typep o 'load-op) (typep c 'system))
                          (x c)))))))
           (depends-on (mapcar 'coerce-name dependencies)))
      (when (pathname-equal asd (system-source-file s))
        (cerror "overwrite the asd file"
                "~/asdf-action:format-action/ is going to overwrite the system definition file ~S which is probably not what you want; you probably need to tweak your output translations."
                (cons o s) asd))
414 415
      (with-open-file (s asd :direction :output :if-exists :supersede
                             :if-does-not-exist :create)
416 417 418
        (format s ";;; Prebuilt~:[~; monolithic~] ASDF definition for system ~A~%"
                (operation-monolithic-p o) name)
        (format s ";;; Built for ~A ~A on a ~A/~A ~A~%"
419 420 421 422 423
                (lisp-implementation-type)
                (lisp-implementation-version)
                (software-type)
                (machine-type)
                (software-version))
424
        (let ((*package* (find-package :asdf-user)))
425
          (pprint `(defsystem ,name
426
                     :class prebuilt-system
427
                     :version ,version
428
                     :depends-on ,depends-on
429
                     :components ((:compiled-file ,(pathname-name fasl)))
430 431 432
                     ,@(when library `(:lib ,(file-namestring library))))
                  s)
          (terpri s)))))
433

Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
434
  #-(or clasp ecl mkcl)
435
  (defmethod perform ((o basic-compile-bundle-op) (c system))
436
    (let* ((input-files (input-files o c))
437 438
           (fasl-files (remove (compile-file-type) input-files :key #'pathname-type :test-not #'equalp))
           (non-fasl-files (remove (compile-file-type) input-files :key #'pathname-type :test #'equalp))
439 440
           (output-files (output-files o c))
           (output-file (first output-files)))
441
      (assert (eq (not input-files) (not output-files)))
442 443
      (when input-files
        (when non-fasl-files
444
          (error "On ~A, asdf/bundle can only bundle FASL files, but these were also produced: ~S"
445
                 (implementation-type) non-fasl-files))
446 447
        (when (or (prologue-code o) (epilogue-code o)
                  (prologue-code c) (epilogue-code c))
448 449 450 451 452 453
          (error "prologue-code and epilogue-code are not supported on ~A"
                 (implementation-type)))
        (with-staging-pathname (output-file)
          (combine-fasls fasl-files output-file)))))

  (defmethod input-files ((o load-op) (s precompiled-system))
454
    (bundle-output-files (find-operation o 'compile-bundle-op) s))
455

456 457 458
  (defmethod perform ((o load-op) (s precompiled-system))
    (perform-lisp-load-fasl o s))

459
  (defmethod component-depends-on ((o load-bundle-op) (s precompiled-system))
460
    #+xcl (declare (ignorable o))
461 462
    `((load-op ,s) ,@(call-next-method))))

463
#| ;; Example use:
464 465 466 467
(asdf:defsystem :precompiled-asdf-utils :class asdf::precompiled-system :fasl (asdf:apply-output-translations (asdf:system-relative-pathname :asdf-utils "asdf-utils.system.fasl")))
(asdf:load-system :precompiled-asdf-utils)
|#

Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
468
#+(or clasp ecl mkcl)
469
(with-upgradability ()
470 471 472 473
  ;; I think that Juanjo intended for this to be,
  ;; but beware the weird bug in test-xach-update-bug.script,
  ;; and also it makes mkcl fail test-logical-pathname.script,
  ;; and ecl fail test-bundle.script.
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
474
  ;;(unless (or #+(or clasp ecl) (use-ecl-byte-compiler-p))
475
  ;;  (setf *load-system-operation* 'load-bundle-op))
476

477
  (defun uiop-library-pathname ()
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
478
    #+clasp (probe-file* (compile-file-pathname "sys:uiop" :output-type :object))
479 480 481 482
    #+ecl (or (probe-file* (compile-file-pathname "sys:uiop" :type :lib)) ;; new style
              (probe-file* (compile-file-pathname "sys:uiop" :type :object))) ;; old style
    #+mkcl (make-pathname :type (bundle-pathname-type :lib) :defaults #p"sys:contrib;uiop"))

483
  (defun asdf-library-pathname ()
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
484
    #+clasp (probe-file* (compile-file-pathname "sys:asdf" :output-type :object))
485 486
    #+ecl (or (probe-file* (compile-file-pathname "sys:asdf" :type :lib)) ;; new style
              (probe-file* (compile-file-pathname "sys:asdf" :type :object))) ;; old style
487 488
    #+mkcl (make-pathname :type (bundle-pathname-type :lib) :defaults #p"sys:contrib;asdf"))

489
  (defun compiler-library-pathname ()
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
490
    #+clasp (compile-file-pathname "sys:cmp" :output-type :lib)
491 492 493
    #+ecl (compile-file-pathname "sys:cmp" :type :lib)
    #+mkcl (make-pathname :type (bundle-pathname-type :lib) :defaults #p"sys:cmp"))

494
  (defun make-library-system (name pathname)
495 496
    (make-instance 'prebuilt-system
                   :name (coerce-name name) :static-library (resolve-symlinks* pathname)))
497 498 499 500 501

  (defmethod component-depends-on :around ((o image-op) (c system))
    (destructuring-bind ((lib-op . deps)) (call-next-method)
      (flet ((has-it-p (x) (find x deps :test 'equal :key 'coerce-name)))
        `((,lib-op
502 503 504 505
           ,@(unless (or (no-uiop c) (has-it-p "cmp"))
               `(,(make-library-system
                   "cmp" (compiler-library-pathname))))
           ,@(unless (or (no-uiop c) (has-it-p "uiop") (has-it-p "asdf"))
506 507 508 509 510 511
               `(cond
                  ((system-source-directory :uiop) `(,(find-system :uiop)))
                  ((system-source-directory :asdf) `(,(find-system :asdf)))
                  (t `(,@(if-let (uiop (uiop-library-pathname))
                           `(,(make-library-system "uiop" uiop)))
                       ,(make-library-system "asdf" (asdf-library-pathname))))))
512 513
           ,@deps)))))

514
  (defmethod perform ((o link-op) (c system))
515 516 517
    (let* ((object-files (input-files o c))
           (output (output-files o c))
           (bundle (first output))
518
           (programp (typep o 'program-op))
519
           (kind (bundle-type o)))
520
      (when output
521
        (apply 'create-image
522 523 524 525
               bundle (append
                       (when programp (prefix-lisp-object-files c))
                       object-files
                       (when programp (postfix-lisp-object-files c)))
526
               :kind kind
527 528
               :prologue-code (or (prologue-code o) (when programp (prologue-code c)))
               :epilogue-code (or (epilogue-code o) (when programp (epilogue-code c)))
529 530
               :build-args (or (extra-build-args o) (when programp (extra-build-args c)))
               :extra-object-files (or (extra-object-files o) (when programp (extra-object-files c)))
531
               :no-uiop (no-uiop c)
532
               (when programp `(:entry-point ,(component-entry-point c))))))))
533

534
#+(and (not asdf-use-unsafe-mac-bundle-op)
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
535
       (or (and clasp ecl darwin)
536
           (and abcl darwin (not abcl-bundle-op-supported))))
537
(defmethod perform :before ((o basic-compile-bundle-op) (c component))
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
538
  (unless (featurep :asdf-use-unsafe-mac-bundle-op)
539
    (cerror "Continue after modifying *FEATURES*."
540
            "BASIC-COMPILE-BUNDLE-OP operations are not supported on Mac OS X for this lisp.~%~T~
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
541 542
To continue, push :asdf-use-unsafe-mac-bundle-op onto *FEATURES*.~%~T~
Please report to ASDF-DEVEL if this works for you.")))
543 544


545
;;; Backward compatibility with pre-3.1.2 names
546 547 548 549 550 551 552 553 554 555 556 557
;; (defclass fasl-op (selfward-operation)
;;   ((selfward-operation :initform 'compile-bundle-op :allocation :class)))
;; (defclass load-fasl-op (selfward-operation)
;;   ((selfward-operation :initform 'load-bundle-op :allocation :class)))
;; (defclass binary-op (selfward-operation)
;;   ((selfward-operation :initform 'deliver-asd-op :allocation :class)))
;; (defclass monolithic-fasl-op (selfward-operation)
;;   ((selfward-operation :initform 'monolithic-compile-bundle-op :allocation :class)))
;; (defclass monolithic-load-fasl-op (selfward-operation)
;;   ((selfward-operation :initform 'monolithic-load-bundle-op :allocation :class)))
;; (defclass monolithic-binary-op (selfward-operation)
;;   ((selfward-operation :initform 'monolithic-deliver-asd-op :allocation :class)))