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

4 5
(asdf/package:define-package :asdf/concatenate-source
  (:recycle :asdf/concatenate-source :asdf)
6
  (:use :uiop/common-lisp :uiop :asdf/upgrade
7
   :asdf/component :asdf/operation
8 9
   :asdf/system :asdf/find-system :asdf/defsystem
   :asdf/action :asdf/lisp-action :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
  (defclass basic-concatenate-source-op (bundle-op)
26
    ((bundle-type :initform "lisp")))
27 28 29
  (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) ())
30

31 32 33 34 35 36 37
  (defclass concatenate-source-op (basic-concatenate-source-op) ())
  (defclass load-concatenated-source-op (basic-load-concatenated-source-op)
    ((selfward-operation :initform '(prepare-op concatenate-source-op))))
  (defclass compile-concatenated-source-op (basic-compile-concatenated-source-op)
    ((selfward-operation :initform '(prepare-op concatenate-source-op))))
  (defclass load-compiled-concatenated-source-op (basic-load-compiled-concatenated-source-op)
    ((selfward-operation :initform '(prepare-op compile-concatenated-source-op))))
38

39 40 41 42 43 44 45 46 47
  (defclass monolithic-concatenate-source-op (basic-concatenate-source-op monolithic-bundle-op) ())
  (defclass monolithic-load-concatenated-source-op (basic-load-concatenated-source-op)
    ((selfward-operation :initform 'monolithic-concatenate-source-op)))
  (defclass monolithic-compile-concatenated-source-op (basic-compile-concatenated-source-op)
    ((selfward-operation :initform '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)))

  (defmethod input-files ((operation basic-concatenate-source-op) (s system))
48 49 50 51 52 53 54 55 56 57 58 59
    (loop :with encoding = (or (component-encoding s) *default-encoding*)
          :with other-encodings = '()
          :with around-compile = (around-compile-hook s)
          :with other-around-compile = '()
          :for c :in (required-components
                      s :goal-operation 'compile-op
                        :keep-operation 'compile-op
                        :other-systems (operation-monolithic-p operation))
          :append
          (when (typep c 'cl-source-file)
            (let ((e (component-encoding c)))
              (unless (equal e encoding)
60 61 62 63 64
                (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))
65 66 67
            (input-files (make-operation 'compile-op) c)) :into inputs
          :finally
             (when other-encodings
68 69 70 71
               (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)))
72 73 74 75
             (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)))
76 77
  (defmethod output-files ((o basic-compile-concatenated-source-op) (s system))
    (lisp-compilation-output-files o s))
78

79
  (defmethod perform ((o basic-concatenate-source-op) (s system))
80 81 82
    (let ((inputs (input-files o s))
          (output (output-file o s)))
      (concatenate-files inputs output)))
83
  (defmethod perform ((o basic-load-concatenated-source-op) (s system))
84
    (perform-lisp-load-source o s))
85
  (defmethod perform ((o basic-compile-concatenated-source-op) (s system))
86
    (perform-lisp-compilation o s))
87 88
  (defmethod perform ((o basic-load-compiled-concatenated-source-op) (s system))
    (perform-lisp-load-fasl o s)))
89