2016-10-07 23:57:08 +02:00
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
2017-04-03 15:01:20 +02:00
|
|
|
;;; Copyright © 2016, 2017 Andy Patterson <ajpatter@uwaterloo.ca>
|
2016-10-07 23:57:08 +02:00
|
|
|
;;;
|
|
|
|
;;; This file is part of GNU Guix.
|
|
|
|
;;;
|
|
|
|
;;; GNU Guix is free software; you can redistribute it and/or modify it
|
|
|
|
;;; under the terms of the GNU General Public License as published by
|
|
|
|
;;; the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
;;; your option) any later version.
|
|
|
|
;;;
|
|
|
|
;;; GNU Guix is distributed in the hope that it will be useful, but
|
|
|
|
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;;; GNU General Public License for more details.
|
|
|
|
;;;
|
|
|
|
;;; You should have received a copy of the GNU General Public License
|
|
|
|
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
(define-module (guix build asdf-build-system)
|
|
|
|
#:use-module ((guix build gnu-build-system) #:prefix gnu:)
|
|
|
|
#:use-module (guix build utils)
|
|
|
|
#:use-module (guix build lisp-utils)
|
|
|
|
#:use-module (srfi srfi-1)
|
2017-04-03 15:01:23 +02:00
|
|
|
#:use-module (srfi srfi-11)
|
2016-10-07 23:57:08 +02:00
|
|
|
#:use-module (srfi srfi-26)
|
|
|
|
#:use-module (ice-9 rdelim)
|
|
|
|
#:use-module (ice-9 receive)
|
|
|
|
#:use-module (ice-9 regex)
|
|
|
|
#:use-module (ice-9 match)
|
|
|
|
#:use-module (ice-9 format)
|
|
|
|
#:use-module (ice-9 ftw)
|
|
|
|
#:export (%standard-phases
|
|
|
|
%standard-phases/source
|
|
|
|
asdf-build
|
|
|
|
asdf-build/source))
|
|
|
|
|
|
|
|
;; Commentary:
|
|
|
|
;;
|
|
|
|
;; System for building ASDF packages; creating executable programs and images
|
|
|
|
;; from them.
|
|
|
|
;;
|
|
|
|
;; Code:
|
|
|
|
|
|
|
|
(define %object-prefix "/lib")
|
|
|
|
|
2017-04-03 15:01:27 +02:00
|
|
|
(define (%lisp-source-install-prefix)
|
|
|
|
(string-append %source-install-prefix "/" (%lisp-type) "-source"))
|
2016-10-07 23:57:08 +02:00
|
|
|
|
|
|
|
(define %system-install-prefix
|
2017-04-03 15:01:20 +02:00
|
|
|
(string-append %source-install-prefix "/systems"))
|
2016-10-07 23:57:08 +02:00
|
|
|
|
2017-04-03 15:01:27 +02:00
|
|
|
(define (lisp-source-directory output name)
|
|
|
|
(string-append output (%lisp-source-install-prefix) "/" name))
|
2016-10-07 23:57:08 +02:00
|
|
|
|
|
|
|
(define (source-directory output name)
|
2017-04-03 15:01:20 +02:00
|
|
|
(string-append output %source-install-prefix "/source/" name))
|
2016-10-07 23:57:08 +02:00
|
|
|
|
2017-04-03 15:01:27 +02:00
|
|
|
(define (library-directory output)
|
2016-10-07 23:57:08 +02:00
|
|
|
(string-append output %object-prefix
|
2017-04-03 15:01:27 +02:00
|
|
|
"/" (%lisp-type)))
|
2016-10-07 23:57:08 +02:00
|
|
|
|
|
|
|
(define (output-translation source-path
|
2017-04-03 15:01:27 +02:00
|
|
|
object-output)
|
2016-10-07 23:57:08 +02:00
|
|
|
"Return a translation for the system's source path
|
|
|
|
to it's binary output."
|
|
|
|
`((,source-path
|
|
|
|
:**/ :*.*.*)
|
2017-04-03 15:01:27 +02:00
|
|
|
(,(library-directory object-output)
|
2016-10-07 23:57:08 +02:00
|
|
|
:**/ :*.*.*)))
|
|
|
|
|
2017-04-03 15:01:27 +02:00
|
|
|
(define (source-asd-file output name asd-file)
|
|
|
|
(string-append (lisp-source-directory output name) "/" asd-file))
|
2016-10-07 23:57:08 +02:00
|
|
|
|
2017-04-03 15:01:21 +02:00
|
|
|
(define (library-output outputs)
|
|
|
|
"If a `lib' output exists, build things there. Otherwise use `out'."
|
|
|
|
(or (assoc-ref outputs "lib") (assoc-ref outputs "out")))
|
|
|
|
|
|
|
|
(define (copy-files-to-output out name)
|
|
|
|
"Copy all files from the current directory to OUT. Create an extra link to
|
|
|
|
any system-defining files in the source to a convenient location. This is
|
|
|
|
done before any compiling so that the compiled source locations will be
|
|
|
|
valid."
|
|
|
|
(let ((source (getcwd))
|
|
|
|
(target (source-directory out name))
|
|
|
|
(system-path (string-append out %system-install-prefix)))
|
2016-10-07 23:57:08 +02:00
|
|
|
(copy-recursively source target)
|
|
|
|
(mkdir-p system-path)
|
|
|
|
(for-each
|
|
|
|
(lambda (file)
|
|
|
|
(symlink file
|
|
|
|
(string-append system-path "/" (basename file))))
|
|
|
|
(find-files target "\\.asd$"))
|
|
|
|
#t))
|
|
|
|
|
|
|
|
(define* (install #:key outputs #:allow-other-keys)
|
|
|
|
"Copy and symlink all the source files."
|
2017-04-09 05:48:38 +02:00
|
|
|
(define output (assoc-ref outputs "out"))
|
|
|
|
(copy-files-to-output output
|
|
|
|
(package-name->name+version
|
|
|
|
(strip-store-file-name output))))
|
2016-10-07 23:57:08 +02:00
|
|
|
|
2017-04-09 05:48:38 +02:00
|
|
|
(define* (copy-source #:key outputs asd-system-name #:allow-other-keys)
|
2017-04-03 15:01:21 +02:00
|
|
|
"Copy the source to the library output."
|
|
|
|
(let* ((out (library-output outputs))
|
2017-04-03 15:01:20 +02:00
|
|
|
(install-path (string-append out %source-install-prefix)))
|
2017-04-09 05:48:38 +02:00
|
|
|
(copy-files-to-output out asd-system-name)
|
2016-10-07 23:57:08 +02:00
|
|
|
;; Hide the files from asdf
|
|
|
|
(with-directory-excursion install-path
|
2017-04-03 15:01:27 +02:00
|
|
|
(rename-file "source" (string-append (%lisp-type) "-source"))
|
2016-10-07 23:57:08 +02:00
|
|
|
(delete-file-recursively "systems")))
|
|
|
|
#t)
|
|
|
|
|
2017-04-09 05:48:38 +02:00
|
|
|
(define* (build #:key outputs inputs asd-file asd-system-name
|
2016-10-07 23:57:08 +02:00
|
|
|
#:allow-other-keys)
|
|
|
|
"Compile the system."
|
2017-04-03 15:01:21 +02:00
|
|
|
(let* ((out (library-output outputs))
|
2017-04-09 05:48:38 +02:00
|
|
|
(source-path (lisp-source-directory out asd-system-name))
|
2016-10-07 23:57:08 +02:00
|
|
|
(translations (wrap-output-translations
|
|
|
|
`(,(output-translation source-path
|
2017-04-03 15:01:27 +02:00
|
|
|
out))))
|
2017-04-03 15:01:29 +02:00
|
|
|
(asd-file (source-asd-file out asd-system-name asd-file)))
|
2016-10-07 23:57:08 +02:00
|
|
|
|
|
|
|
(setenv "ASDF_OUTPUT_TRANSLATIONS"
|
|
|
|
(replace-escaped-macros (format #f "~S" translations)))
|
|
|
|
|
|
|
|
(setenv "HOME" out) ; ecl's asdf sometimes wants to create $HOME/.cache
|
|
|
|
|
2017-04-09 05:48:38 +02:00
|
|
|
(compile-system asd-system-name asd-file)
|
2016-10-07 23:57:08 +02:00
|
|
|
|
|
|
|
;; As above, ecl will sometimes create this even though it doesn't use it
|
|
|
|
|
|
|
|
(let ((cache-directory (string-append out "/.cache")))
|
|
|
|
(when (directory-exists? cache-directory)
|
|
|
|
(delete-file-recursively cache-directory))))
|
|
|
|
#t)
|
|
|
|
|
2017-04-09 05:48:38 +02:00
|
|
|
(define* (check #:key tests? outputs inputs asd-file asd-system-name
|
2016-10-07 23:57:08 +02:00
|
|
|
#:allow-other-keys)
|
|
|
|
"Test the system."
|
2017-04-09 05:48:38 +02:00
|
|
|
(let* ((out (library-output outputs))
|
2017-04-03 15:01:29 +02:00
|
|
|
(asd-file (source-asd-file out asd-system-name asd-file)))
|
2016-10-07 23:57:08 +02:00
|
|
|
(if tests?
|
2017-04-09 05:48:38 +02:00
|
|
|
(test-system asd-system-name asd-file)
|
2016-10-07 23:57:08 +02:00
|
|
|
(format #t "test suite not run~%")))
|
|
|
|
#t)
|
|
|
|
|
2017-04-03 15:01:23 +02:00
|
|
|
(define* (create-asd-file #:key outputs
|
2016-10-07 23:57:08 +02:00
|
|
|
inputs
|
2017-04-03 15:01:23 +02:00
|
|
|
asd-file
|
2017-04-09 05:48:38 +02:00
|
|
|
asd-system-name
|
2016-10-07 23:57:08 +02:00
|
|
|
#:allow-other-keys)
|
2017-04-03 15:01:23 +02:00
|
|
|
"Create a system definition file for the built system."
|
|
|
|
(let*-values (((out) (library-output outputs))
|
2017-04-09 05:48:38 +02:00
|
|
|
((_ version) (package-name->name+version
|
|
|
|
(strip-store-file-name out)))
|
2017-04-03 15:01:27 +02:00
|
|
|
((new-asd-file) (string-append (library-directory out)
|
2017-04-09 05:48:38 +02:00
|
|
|
"/" asd-system-name ".asd")))
|
2017-04-03 15:01:23 +02:00
|
|
|
|
|
|
|
(make-asd-file new-asd-file
|
2017-04-09 05:48:38 +02:00
|
|
|
#:system asd-system-name
|
2017-04-03 15:01:23 +02:00
|
|
|
#:version version
|
|
|
|
#:inputs inputs
|
|
|
|
#:system-asd-file asd-file))
|
2016-10-07 23:57:08 +02:00
|
|
|
#t)
|
|
|
|
|
2017-04-03 15:01:27 +02:00
|
|
|
(define* (symlink-asd-files #:key outputs #:allow-other-keys)
|
2016-10-07 23:57:08 +02:00
|
|
|
"Create an extra reference to the system in a convenient location."
|
2017-04-03 15:01:21 +02:00
|
|
|
(let* ((out (library-output outputs)))
|
2016-10-07 23:57:08 +02:00
|
|
|
(for-each
|
|
|
|
(lambda (asd-file)
|
|
|
|
(receive (new-asd-file asd-file-directory)
|
2017-04-03 15:01:27 +02:00
|
|
|
(bundle-asd-file out asd-file)
|
2016-10-07 23:57:08 +02:00
|
|
|
(mkdir-p asd-file-directory)
|
|
|
|
(symlink asd-file new-asd-file)
|
|
|
|
;; Update the source registry for future phases which might want to
|
|
|
|
;; use the newly compiled system.
|
|
|
|
(prepend-to-source-registry
|
|
|
|
(string-append asd-file-directory "/"))))
|
|
|
|
|
2017-04-03 15:01:23 +02:00
|
|
|
(find-files (string-append out %object-prefix) "\\.asd$")))
|
2016-10-07 23:57:08 +02:00
|
|
|
#t)
|
|
|
|
|
2017-04-03 15:01:27 +02:00
|
|
|
(define* (cleanup-files #:key outputs
|
2017-04-03 15:01:23 +02:00
|
|
|
#:allow-other-keys)
|
2016-10-07 23:57:08 +02:00
|
|
|
"Remove any compiled files which are not a part of the final bundle."
|
2017-04-03 15:01:21 +02:00
|
|
|
(let ((out (library-output outputs)))
|
2017-04-03 15:01:27 +02:00
|
|
|
(match (%lisp-type)
|
2016-10-07 23:57:08 +02:00
|
|
|
("sbcl"
|
|
|
|
(for-each
|
|
|
|
(lambda (file)
|
|
|
|
(unless (string-suffix? "--system.fasl" file)
|
|
|
|
(delete-file file)))
|
|
|
|
(find-files out "\\.fasl$")))
|
|
|
|
("ecl"
|
|
|
|
(for-each delete-file
|
|
|
|
(append (find-files out "\\.fas$")
|
2017-04-03 15:01:25 +02:00
|
|
|
(find-files out "\\.o$")))))
|
2016-10-07 23:57:08 +02:00
|
|
|
|
2017-04-03 15:01:27 +02:00
|
|
|
(with-directory-excursion (library-directory out)
|
2016-10-07 23:57:08 +02:00
|
|
|
(for-each
|
|
|
|
(lambda (file)
|
|
|
|
(rename-file file
|
|
|
|
(string-append "./" (basename file))))
|
|
|
|
(find-files "."))
|
|
|
|
(for-each delete-file-recursively
|
|
|
|
(scandir "."
|
|
|
|
(lambda (file)
|
|
|
|
(and
|
|
|
|
(directory-exists? file)
|
|
|
|
(string<> "." file)
|
|
|
|
(string<> ".." file)))))))
|
|
|
|
#t)
|
|
|
|
|
2017-04-03 15:01:27 +02:00
|
|
|
(define* (strip #:rest args)
|
2016-10-07 23:57:08 +02:00
|
|
|
;; stripping sbcl binaries removes their entry program and extra systems
|
2017-04-03 15:01:27 +02:00
|
|
|
(or (string=? (%lisp-type) "sbcl")
|
2016-10-07 23:57:08 +02:00
|
|
|
(apply (assoc-ref gnu:%standard-phases 'strip) args)))
|
|
|
|
|
|
|
|
(define %standard-phases/source
|
|
|
|
(modify-phases gnu:%standard-phases
|
|
|
|
(delete 'configure)
|
|
|
|
(delete 'check)
|
|
|
|
(delete 'build)
|
|
|
|
(replace 'install install)))
|
|
|
|
|
|
|
|
(define %standard-phases
|
|
|
|
(modify-phases gnu:%standard-phases
|
|
|
|
(delete 'configure)
|
|
|
|
(delete 'install)
|
|
|
|
(replace 'build build)
|
|
|
|
(add-before 'build 'copy-source copy-source)
|
|
|
|
(replace 'check check)
|
|
|
|
(replace 'strip strip)
|
2017-04-03 15:01:23 +02:00
|
|
|
(add-after 'check 'create-asd-file create-asd-file)
|
|
|
|
(add-after 'create-asd-file 'cleanup cleanup-files)
|
2016-10-07 23:57:08 +02:00
|
|
|
(add-after 'cleanup 'create-symlinks symlink-asd-files)))
|
|
|
|
|
|
|
|
(define* (asdf-build #:key inputs
|
|
|
|
(phases %standard-phases)
|
|
|
|
#:allow-other-keys
|
|
|
|
#:rest args)
|
|
|
|
(apply gnu:gnu-build
|
|
|
|
#:inputs inputs
|
|
|
|
#:phases phases
|
|
|
|
args))
|
|
|
|
|
|
|
|
(define* (asdf-build/source #:key inputs
|
|
|
|
(phases %standard-phases/source)
|
|
|
|
#:allow-other-keys
|
|
|
|
#:rest args)
|
|
|
|
(apply gnu:gnu-build
|
|
|
|
#:inputs inputs
|
|
|
|
#:phases phases
|
|
|
|
args))
|
|
|
|
|
|
|
|
;;; asdf-build-system.scm ends here
|