concatenate-source.lisp 5.66 KB
Newer Older
1 2 3
;;;; -------------------------------------------------------------------------
;;;; Concatenate-source

4
(uiop/package:define-package :asdf/concatenate-source
5
  (:recycle :asdf/concatenate-source :asdf)
6
  (:use :uiop/common-lisp :uiop :asdf/upgrade
7
   :asdf/component :asdf/operation
8
   :asdf/system
9
   :asdf/action :asdf/lisp-action :asdf/plan :asdf/bundle)
10 11 12 13 14 15 16 17
  (:export
   #:concatenate-source-op
   #:load-concatenated-source-op
   #:compile-concatenated-source-op
   #:load-compiled-concatenated-source-op
   #:monolithic-concatenate-source-op
   #:monolithic-load-concatenated-source-op
   #:monolithic-compile-concatenated-source-op
18
   #:monolithic-load-compiled-concatenated-source-op))
19 20 21 22 23
(in-package :asdf/concatenate-source)

;;;
;;; Concatenate sources
;;;
24
(with-upgradability ()
25
  ;; Base classes for both regular and monolithic concatenate-source operations
26 27
  (defclass basic-concatenate-source-op (bundle-op) ())
  (defmethod bundle-type ((o basic-concatenate-source-op)) "lisp")
28 29 30
  (defclass basic-load-concatenated-source-op (basic-load-op selfward-operation) ())
  (defclass basic-compile-concatenated-source-op (basic-compile-op selfward-operation) ())
  (defclass basic-load-compiled-concatenated-source-op (basic-load-op selfward-operation) ())
31

32 33 34
  ;; Regular concatenate-source operations
  (defclass concatenate-source-op (basic-concatenate-source-op non-propagating-operation) ()
    (:documentation "Operation to concatenate all sources in a system into a single file"))
35
  (defclass load-concatenated-source-op (basic-load-concatenated-source-op)
36 37
    ((selfward-operation :initform '(prepare-op concatenate-source-op) :allocation :class))
    (:documentation "Operation to load the result of concatenate-source-op as source"))
38
  (defclass compile-concatenated-source-op (basic-compile-concatenated-source-op)
39 40
    ((selfward-operation :initform '(prepare-op concatenate-source-op) :allocation :class))
    (:documentation "Operation to compile the result of concatenate-source-op"))
41
  (defclass load-compiled-concatenated-source-op (basic-load-compiled-concatenated-source-op)
42 43
    ((selfward-operation :initform '(prepare-op compile-concatenated-source-op) :allocation :class))
    (:documentation "Operation to load the result of compile-concatenated-source-op"))
44

45 46 47 48
  (defclass monolithic-concatenate-source-op
      (basic-concatenate-source-op monolithic-bundle-op non-propagating-operation) ()
    (:documentation "Operation to concatenate all sources in a system and its dependencies
into a single file"))
49
  (defclass monolithic-load-concatenated-source-op (basic-load-concatenated-source-op)
50 51
    ((selfward-operation :initform 'monolithic-concatenate-source-op :allocation :class))
    (:documentation "Operation to load the result of monolithic-concatenate-source-op as source"))
52
  (defclass monolithic-compile-concatenated-source-op (basic-compile-concatenated-source-op)
53 54 55 56 57 58
    ((selfward-operation :initform 'monolithic-concatenate-source-op :allocation :class))
    (:documentation "Operation to compile the result of monolithic-concatenate-source-op"))
  (defclass monolithic-load-compiled-concatenated-source-op
      (basic-load-compiled-concatenated-source-op)
    ((selfward-operation :initform 'monolithic-compile-concatenated-source-op :allocation :class))
    (:documentation "Operation to load the result of monolithic-compile-concatenated-source-op"))
59 60

  (defmethod input-files ((operation basic-concatenate-source-op) (s system))
61 62 63 64
    (loop :with encoding = (or (component-encoding s) *default-encoding*)
          :with other-encodings = '()
          :with around-compile = (around-compile-hook s)
          :with other-around-compile = '()
65 66
          :for c :in (required-components  ;; see note about similar call to required-components
                      s :goal-operation 'load-op ;;  in bundle.lisp
67
                        :keep-operation 'basic-compile-op
68 69 70 71 72
                        :other-systems (operation-monolithic-p operation))
          :append
          (when (typep c 'cl-source-file)
            (let ((e (component-encoding c)))
              (unless (equal e encoding)
73 74 75 76 77
                (let ((a (assoc e other-encodings)))
                  (if a (push (component-find-path c) (cdr a))
                      (push (list a (component-find-path c)) other-encodings)))))
            (unless (equal around-compile (around-compile-hook c))
              (push (component-find-path c) other-around-compile))
78 79 80
            (input-files (make-operation 'compile-op) c)) :into inputs
          :finally
             (when other-encodings
81 82 83 84
               (warn "~S uses encoding ~A but has sources that use these encodings:~{ ~A~}"
                     operation encoding
                     (mapcar #'(lambda (x) (cons (car x) (list (reverse (cdr x)))))
                             other-encodings)))
85 86 87 88
             (when other-around-compile
               (warn "~S uses around-compile hook ~A but has sources that use these hooks: ~A"
                     operation around-compile other-around-compile))
             (return inputs)))
89 90
  (defmethod output-files ((o basic-compile-concatenated-source-op) (s system))
    (lisp-compilation-output-files o s))
91

92
  (defmethod perform ((o basic-concatenate-source-op) (s system))
93 94 95 96 97
    (let* ((ins (input-files o s))
           (out (output-file o s))
           (tmp (tmpize-pathname out)))
      (concatenate-files ins tmp)
      (rename-file-overwriting-target tmp out)))
98
  (defmethod perform ((o basic-load-concatenated-source-op) (s system))
99
    (perform-lisp-load-source o s))
100
  (defmethod perform ((o basic-compile-concatenated-source-op) (s system))
101
    (perform-lisp-compilation o s))
102 103
  (defmethod perform ((o basic-load-compiled-concatenated-source-op) (s system))
    (perform-lisp-load-fasl o s)))
104