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 lisp-utils)
|
|
|
|
#:use-module (ice-9 format)
|
2017-04-03 15:01:23 +02:00
|
|
|
#:use-module (ice-9 hash-table)
|
2016-10-07 23:57:08 +02:00
|
|
|
#:use-module (ice-9 match)
|
|
|
|
#:use-module (ice-9 regex)
|
|
|
|
#:use-module (srfi srfi-1)
|
|
|
|
#:use-module (srfi srfi-26)
|
|
|
|
#:use-module (guix build utils)
|
|
|
|
#:export (%lisp
|
2017-04-03 15:01:27 +02:00
|
|
|
%lisp-type
|
2017-04-03 15:01:20 +02:00
|
|
|
%source-install-prefix
|
2016-10-07 23:57:08 +02:00
|
|
|
lisp-eval-program
|
|
|
|
compile-system
|
|
|
|
test-system
|
|
|
|
replace-escaped-macros
|
|
|
|
generate-executable-wrapper-system
|
|
|
|
generate-executable-entry-point
|
|
|
|
generate-executable-for-system
|
2017-04-03 15:01:27 +02:00
|
|
|
%bundle-install-prefix
|
2016-10-07 23:57:08 +02:00
|
|
|
bundle-asd-file
|
|
|
|
wrap-output-translations
|
|
|
|
prepend-to-source-registry
|
|
|
|
build-program
|
2017-04-03 15:01:23 +02:00
|
|
|
build-image
|
2017-04-03 15:01:30 +02:00
|
|
|
make-asd-file
|
|
|
|
valid-char-set
|
2017-04-03 15:01:33 +02:00
|
|
|
normalize-string
|
|
|
|
library-output))
|
2016-10-07 23:57:08 +02:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;;;
|
|
|
|
;;; Tools to evaluate lisp programs within a lisp session, generate wrapper
|
|
|
|
;;; systems for executables. Compile, test, and produce images for systems and
|
|
|
|
;;; programs, and link them with their dependencies.
|
|
|
|
;;;
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(define %lisp
|
|
|
|
;; File name of the Lisp compiler.
|
|
|
|
(make-parameter "lisp"))
|
|
|
|
|
2017-04-03 15:01:27 +02:00
|
|
|
(define %lisp-type
|
|
|
|
;; String representing the class of implementation being used.
|
|
|
|
(make-parameter "lisp"))
|
|
|
|
|
2017-04-03 15:01:20 +02:00
|
|
|
;; The common parent for Lisp source files, as will as the symbolic
|
|
|
|
;; link farm for system definition (.asd) files.
|
|
|
|
(define %source-install-prefix "/share/common-lisp")
|
2016-10-07 23:57:08 +02:00
|
|
|
|
2017-04-03 15:01:27 +02:00
|
|
|
(define (%bundle-install-prefix)
|
|
|
|
(string-append %source-install-prefix "/" (%lisp-type) "-bundle-systems"))
|
2016-10-07 23:57:08 +02:00
|
|
|
|
2017-04-03 15:01:33 +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")))
|
|
|
|
|
2017-04-03 15:01:30 +02:00
|
|
|
;; See nix/libstore/store-api.cc#checkStoreName.
|
|
|
|
(define valid-char-set
|
|
|
|
(string->char-set
|
|
|
|
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+-._?="))
|
|
|
|
|
|
|
|
(define (normalize-string str)
|
|
|
|
"Replace invalid characters in STR with a hyphen."
|
|
|
|
(string-join (string-tokenize str valid-char-set) "-"))
|
|
|
|
|
2018-08-30 07:36:28 +02:00
|
|
|
(define (normalize-dependency dependency)
|
|
|
|
"Normalize the name of DEPENDENCY. Handles dependency definitions of the
|
|
|
|
dependency-def form described by
|
2018-10-02 10:57:31 +02:00
|
|
|
<https://common-lisp.net/project/asdf/asdf.html#The-defsystem-grammar>.
|
|
|
|
Assume that any symbols in DEPENDENCY will be in upper-case."
|
2018-08-30 07:36:28 +02:00
|
|
|
(match dependency
|
2018-10-02 10:57:31 +02:00
|
|
|
((':VERSION name rest ...)
|
2018-08-30 07:36:28 +02:00
|
|
|
`(:version ,(normalize-string name) ,@rest))
|
2018-10-02 10:57:31 +02:00
|
|
|
((':FEATURE feature-specification dependency-specification)
|
2018-08-30 07:36:28 +02:00
|
|
|
`(:feature
|
|
|
|
,feature-specification
|
|
|
|
,(normalize-dependency dependency-specification)))
|
|
|
|
((? string? name) (normalize-string name))
|
|
|
|
(require-specification require-specification)))
|
|
|
|
|
2017-04-03 15:01:27 +02:00
|
|
|
(define (inputs->asd-file-map inputs)
|
2017-04-03 15:01:23 +02:00
|
|
|
"Produce a hash table of the form (system . asd-file), where system is the
|
|
|
|
name of an ASD system, and asd-file is the full path to its definition."
|
|
|
|
(alist->hash-table
|
|
|
|
(filter-map
|
|
|
|
(match-lambda
|
|
|
|
((_ . path)
|
2017-04-03 15:01:27 +02:00
|
|
|
(let ((prefix (string-append path (%bundle-install-prefix))))
|
2017-04-03 15:01:23 +02:00
|
|
|
(and (directory-exists? prefix)
|
|
|
|
(match (find-files prefix "\\.asd$")
|
|
|
|
((asd-file)
|
|
|
|
(cons
|
|
|
|
(string-drop-right (basename asd-file) 4) ; drop ".asd"
|
|
|
|
asd-file))
|
|
|
|
(_ #f))))))
|
|
|
|
inputs)))
|
|
|
|
|
2016-10-07 23:57:08 +02:00
|
|
|
(define (wrap-output-translations translations)
|
|
|
|
`(:output-translations
|
|
|
|
,@translations
|
|
|
|
:inherit-configuration))
|
|
|
|
|
2017-04-03 15:01:27 +02:00
|
|
|
(define (lisp-eval-program program)
|
2016-10-07 23:57:08 +02:00
|
|
|
"Evaluate PROGRAM with a given LISP implementation."
|
2018-08-30 07:36:29 +02:00
|
|
|
(define invocation (lisp-invocation program))
|
|
|
|
(format #t "Invoking ~a: ~{~s ~}~%" (%lisp-type) invocation)
|
2018-08-30 07:36:30 +02:00
|
|
|
(apply invoke invocation))
|
2016-10-07 23:57:08 +02:00
|
|
|
|
2017-04-03 15:01:32 +02:00
|
|
|
(define (spread-statements program argument-name)
|
|
|
|
"Return a list with the statements from PROGRAM spread between
|
|
|
|
ARGUMENT-NAME, a string representing the argument a lisp implementation uses
|
|
|
|
to accept statements to be evaluated before starting."
|
|
|
|
(append-map (lambda (statement)
|
|
|
|
(list argument-name (format #f "~S" statement)))
|
|
|
|
program))
|
|
|
|
|
|
|
|
(define (lisp-invocation program)
|
2016-10-07 23:57:08 +02:00
|
|
|
"Return a list of arguments for system* determining how to invoke LISP
|
|
|
|
with PROGRAM."
|
2017-04-03 15:01:27 +02:00
|
|
|
(match (%lisp-type)
|
2017-04-03 15:01:32 +02:00
|
|
|
("sbcl" `(,(%lisp) "--non-interactive"
|
|
|
|
,@(spread-statements program "--eval")))
|
|
|
|
("ecl" `(,(%lisp)
|
|
|
|
,@(spread-statements program "--eval")
|
|
|
|
"--eval" "(quit)"))
|
2017-04-03 15:01:23 +02:00
|
|
|
(_ (error "The LISP provided is not supported at this time."))))
|
2016-10-07 23:57:08 +02:00
|
|
|
|
|
|
|
(define (asdf-load-all systems)
|
|
|
|
(map (lambda (system)
|
2017-04-03 15:01:32 +02:00
|
|
|
`(asdf:load-system ,system))
|
2016-10-07 23:57:08 +02:00
|
|
|
systems))
|
|
|
|
|
2017-04-03 15:01:27 +02:00
|
|
|
(define (compile-system system asd-file)
|
2016-10-07 23:57:08 +02:00
|
|
|
"Use a lisp implementation to compile SYSTEM using asdf. Load ASD-FILE
|
2017-04-03 15:01:29 +02:00
|
|
|
first."
|
2017-04-03 15:01:27 +02:00
|
|
|
(lisp-eval-program
|
2017-04-03 15:01:32 +02:00
|
|
|
`((require :asdf)
|
2018-08-30 07:36:31 +02:00
|
|
|
(asdf:load-asd (truename ,asd-file) :name ,(normalize-string system))
|
2017-04-03 15:01:32 +02:00
|
|
|
(asdf:operate 'asdf:compile-bundle-op ,system))))
|
2017-04-03 15:01:27 +02:00
|
|
|
|
|
|
|
(define (system-dependencies system asd-file)
|
2017-04-03 15:01:23 +02:00
|
|
|
"Return the dependencies of SYSTEM, as reported by
|
2017-04-03 15:01:29 +02:00
|
|
|
asdf:system-depends-on. First load the system's ASD-FILE."
|
2017-04-03 15:01:23 +02:00
|
|
|
(define deps-file ".deps.sexp")
|
|
|
|
(define program
|
2017-04-03 15:01:32 +02:00
|
|
|
`((require :asdf)
|
2018-08-30 07:36:31 +02:00
|
|
|
(asdf:load-asd (truename ,asd-file) :name ,(normalize-string system))
|
2017-04-03 15:01:23 +02:00
|
|
|
(with-open-file
|
|
|
|
(stream ,deps-file :direction :output)
|
|
|
|
(format stream
|
|
|
|
"~s~%"
|
2017-04-03 15:01:32 +02:00
|
|
|
(asdf:system-depends-on
|
|
|
|
(asdf:find-system ,system))))))
|
2017-04-03 15:01:23 +02:00
|
|
|
|
|
|
|
(dynamic-wind
|
|
|
|
(lambda _
|
2017-04-03 15:01:27 +02:00
|
|
|
(lisp-eval-program program))
|
2017-04-03 15:01:23 +02:00
|
|
|
(lambda _
|
|
|
|
(call-with-input-file deps-file read))
|
|
|
|
(lambda _
|
|
|
|
(when (file-exists? deps-file)
|
|
|
|
(delete-file deps-file)))))
|
|
|
|
|
2017-04-03 15:01:27 +02:00
|
|
|
(define (compiled-system system)
|
2017-04-03 15:01:30 +02:00
|
|
|
(let ((system (basename system))) ; this is how asdf handles slashes
|
|
|
|
(match (%lisp-type)
|
|
|
|
("sbcl" (string-append system "--system"))
|
|
|
|
(_ system))))
|
2017-04-03 15:01:23 +02:00
|
|
|
|
2017-04-03 15:01:27 +02:00
|
|
|
(define* (generate-system-definition system
|
2017-04-03 15:01:23 +02:00
|
|
|
#:key version dependencies)
|
|
|
|
`(asdf:defsystem
|
2017-04-03 15:01:30 +02:00
|
|
|
,(normalize-string system)
|
2017-04-03 15:01:23 +02:00
|
|
|
:class asdf/bundle:prebuilt-system
|
|
|
|
:version ,version
|
|
|
|
:depends-on ,dependencies
|
2017-04-03 15:01:27 +02:00
|
|
|
:components ((:compiled-file ,(compiled-system system)))
|
|
|
|
,@(if (string=? "ecl" (%lisp-type))
|
2017-04-03 15:01:23 +02:00
|
|
|
`(:lib ,(string-append system ".a"))
|
|
|
|
'())))
|
|
|
|
|
2017-04-09 05:43:31 +02:00
|
|
|
(define (test-system system asd-file test-asd-file)
|
|
|
|
"Use a lisp implementation to test SYSTEM using asdf. Load ASD-FILE first.
|
|
|
|
Also load TEST-ASD-FILE if necessary."
|
2017-04-03 15:01:27 +02:00
|
|
|
(lisp-eval-program
|
2017-04-03 15:01:32 +02:00
|
|
|
`((require :asdf)
|
2018-08-30 07:36:31 +02:00
|
|
|
(asdf:load-asd (truename ,asd-file) :name ,(normalize-string system))
|
|
|
|
,@(if test-asd-file
|
|
|
|
`((asdf:load-asd (truename ,test-asd-file)))
|
|
|
|
;; Try some likely files.
|
|
|
|
(map (lambda (file)
|
|
|
|
`(when (uiop:file-exists-p ,file)
|
|
|
|
(asdf:load-asd (truename ,file))))
|
|
|
|
(list
|
|
|
|
(string-append system "-tests.asd")
|
|
|
|
(string-append system "-test.asd")
|
|
|
|
"tests.asd"
|
|
|
|
"test.asd")))
|
2017-04-03 15:01:32 +02:00
|
|
|
(asdf:test-system ,system))))
|
2016-10-07 23:57:08 +02:00
|
|
|
|
|
|
|
(define (string->lisp-keyword . strings)
|
|
|
|
"Return a lisp keyword for the concatenation of STRINGS."
|
|
|
|
(string->symbol (apply string-append ":" strings)))
|
|
|
|
|
2017-04-03 15:01:27 +02:00
|
|
|
(define (generate-executable-for-system type system)
|
2017-04-03 15:01:32 +02:00
|
|
|
"Use LISP to generate an executable, whose TYPE can be 'asdf:image-op or
|
|
|
|
'asdf:program-op. The latter will always be standalone. Depends on having
|
|
|
|
created a \"SYSTEM-exec\" system which contains the entry program."
|
2016-10-07 23:57:08 +02:00
|
|
|
(lisp-eval-program
|
2017-04-03 15:01:32 +02:00
|
|
|
`((require :asdf)
|
|
|
|
(asdf:operate ',type ,(string-append system "-exec")))))
|
2016-10-07 23:57:08 +02:00
|
|
|
|
|
|
|
(define (generate-executable-wrapper-system system dependencies)
|
|
|
|
"Generates a system which can be used by asdf to produce an image or program
|
|
|
|
inside the current directory. The image or program will contain
|
|
|
|
DEPENDENCIES."
|
|
|
|
(with-output-to-file (string-append system "-exec.asd")
|
|
|
|
(lambda _
|
|
|
|
(format #t "~y~%"
|
|
|
|
`(defsystem ,(string->lisp-keyword system "-exec")
|
|
|
|
:entry-point ,(string-append system "-exec:main")
|
|
|
|
:depends-on (:uiop
|
|
|
|
,@(map string->lisp-keyword
|
|
|
|
dependencies))
|
|
|
|
:components ((:file ,(string-append system "-exec"))))))))
|
|
|
|
|
|
|
|
(define (generate-executable-entry-point system entry-program)
|
|
|
|
"Generates an entry point program from the list of lisp statements
|
|
|
|
ENTRY-PROGRAM for SYSTEM within the current directory."
|
|
|
|
(with-output-to-file (string-append system "-exec.lisp")
|
|
|
|
(lambda _
|
|
|
|
(let ((system (string->lisp-keyword system "-exec")))
|
|
|
|
(format #t "~{~y~%~%~}"
|
|
|
|
`((defpackage ,system
|
|
|
|
(:use :cl)
|
|
|
|
(:export :main))
|
|
|
|
|
|
|
|
(in-package ,system)
|
|
|
|
|
|
|
|
(defun main ()
|
|
|
|
(let ((arguments uiop:*command-line-arguments*))
|
|
|
|
(declare (ignorable arguments))
|
|
|
|
,@entry-program))))))))
|
|
|
|
|
2017-04-03 15:01:27 +02:00
|
|
|
(define (generate-dependency-links registry system)
|
2017-04-03 15:01:23 +02:00
|
|
|
"Creates a program which populates asdf's source registry from REGISTRY, an
|
|
|
|
alist of dependency names to corresponding asd files. This allows the system
|
|
|
|
to locate its dependent systems."
|
|
|
|
`(progn
|
|
|
|
(asdf/source-registry:ensure-source-registry)
|
|
|
|
,@(map (match-lambda
|
|
|
|
((name . asd-file)
|
|
|
|
`(setf
|
|
|
|
(gethash ,name
|
|
|
|
asdf/source-registry:*source-registry*)
|
|
|
|
,(string->symbol "#p")
|
|
|
|
,asd-file)))
|
|
|
|
registry)))
|
|
|
|
|
|
|
|
(define* (make-asd-file asd-file
|
2017-04-03 15:01:27 +02:00
|
|
|
#:key system version inputs
|
2017-04-03 15:01:23 +02:00
|
|
|
(system-asd-file #f))
|
|
|
|
"Create an ASD-FILE for SYSTEM@VERSION, appending a program to allow the
|
|
|
|
system to find its dependencies, as described by GENERATE-DEPENDENCY-LINKS."
|
|
|
|
(define dependencies
|
2017-04-03 15:01:30 +02:00
|
|
|
(let ((deps
|
|
|
|
(system-dependencies system system-asd-file)))
|
|
|
|
(if (eq? 'NIL deps)
|
|
|
|
'()
|
2018-08-30 07:36:28 +02:00
|
|
|
(map normalize-dependency deps))))
|
2017-04-03 15:01:23 +02:00
|
|
|
|
|
|
|
(define lisp-input-map
|
2017-04-03 15:01:27 +02:00
|
|
|
(inputs->asd-file-map inputs))
|
2017-04-03 15:01:23 +02:00
|
|
|
|
2018-08-30 07:36:28 +02:00
|
|
|
(define dependency-name
|
|
|
|
(match-lambda
|
|
|
|
((':version name _ ...) name)
|
|
|
|
((':feature _ dependency-specification)
|
|
|
|
(dependency-name dependency-specification))
|
|
|
|
((? string? name) name)
|
|
|
|
(_ #f)))
|
|
|
|
|
2017-04-03 15:01:23 +02:00
|
|
|
(define registry
|
|
|
|
(filter-map hash-get-handle
|
2017-04-03 15:01:30 +02:00
|
|
|
(make-list (length dependencies)
|
2017-04-03 15:01:23 +02:00
|
|
|
lisp-input-map)
|
2018-08-30 07:36:28 +02:00
|
|
|
(map dependency-name dependencies)))
|
2017-04-03 15:01:23 +02:00
|
|
|
|
|
|
|
(call-with-output-file asd-file
|
|
|
|
(lambda (port)
|
|
|
|
(display
|
|
|
|
(replace-escaped-macros
|
|
|
|
(format #f "~y~%~y~%"
|
2017-04-03 15:01:27 +02:00
|
|
|
(generate-system-definition system
|
2017-04-03 15:01:23 +02:00
|
|
|
#:version version
|
|
|
|
#:dependencies dependencies)
|
2017-04-03 15:01:27 +02:00
|
|
|
(generate-dependency-links registry system)))
|
2017-04-03 15:01:23 +02:00
|
|
|
port))))
|
2016-10-07 23:57:08 +02:00
|
|
|
|
2017-04-03 15:01:27 +02:00
|
|
|
(define (bundle-asd-file output-path original-asd-file)
|
2016-10-07 23:57:08 +02:00
|
|
|
"Find the symlinked bundle file for ORIGINAL-ASD-FILE by looking in
|
|
|
|
OUTPUT-PATH/share/common-lisp/LISP-bundle-systems/<system>.asd. Returns two
|
|
|
|
values: the asd file itself and the directory in which it resides."
|
|
|
|
(let ((bundle-asd-path (string-append output-path
|
2017-04-03 15:01:27 +02:00
|
|
|
(%bundle-install-prefix))))
|
2016-10-07 23:57:08 +02:00
|
|
|
(values (string-append bundle-asd-path "/" (basename original-asd-file))
|
|
|
|
bundle-asd-path)))
|
|
|
|
|
|
|
|
(define (replace-escaped-macros string)
|
|
|
|
"Replace simple lisp forms that the guile writer escapes, for example by
|
|
|
|
replacing #{#p}# with #p. Should only be used to replace truly simple forms
|
|
|
|
which are not nested."
|
|
|
|
(regexp-substitute/global #f "(#\\{)(\\S*)(\\}#)" string
|
|
|
|
'pre 2 'post))
|
|
|
|
|
|
|
|
(define (prepend-to-source-registry path)
|
|
|
|
(setenv "CL_SOURCE_REGISTRY"
|
|
|
|
(string-append path ":" (or (getenv "CL_SOURCE_REGISTRY") ""))))
|
|
|
|
|
2017-04-03 15:01:33 +02:00
|
|
|
(define* (build-program program outputs #:key
|
|
|
|
(dependency-prefixes (list (library-output outputs)))
|
2016-10-07 23:57:08 +02:00
|
|
|
(dependencies (list (basename program)))
|
|
|
|
entry-program
|
|
|
|
#:allow-other-keys)
|
|
|
|
"Generate an executable program containing all DEPENDENCIES, and which will
|
|
|
|
execute ENTRY-PROGRAM. The result is placed in PROGRAM. When executed, it
|
|
|
|
will run ENTRY-PROGRAM, a list of Common Lisp expressions in which `arguments'
|
2017-04-03 15:01:33 +02:00
|
|
|
has been bound to the command-line arguments which were passed. Link in any
|
|
|
|
asd files from DEPENDENCY-PREFIXES to ensure references to those libraries are
|
|
|
|
retained."
|
2017-04-03 15:01:27 +02:00
|
|
|
(generate-executable program
|
2016-10-07 23:57:08 +02:00
|
|
|
#:dependencies dependencies
|
2017-04-03 15:01:33 +02:00
|
|
|
#:dependency-prefixes dependency-prefixes
|
2016-10-07 23:57:08 +02:00
|
|
|
#:entry-program entry-program
|
2017-04-03 15:01:32 +02:00
|
|
|
#:type 'asdf:program-op)
|
2016-10-07 23:57:08 +02:00
|
|
|
(let* ((name (basename program))
|
|
|
|
(bin-directory (dirname program)))
|
|
|
|
(with-directory-excursion bin-directory
|
|
|
|
(rename-file (string-append name "-exec")
|
|
|
|
name)))
|
|
|
|
#t)
|
|
|
|
|
2017-04-03 15:01:33 +02:00
|
|
|
(define* (build-image image outputs #:key
|
|
|
|
(dependency-prefixes (list (library-output outputs)))
|
2016-10-07 23:57:08 +02:00
|
|
|
(dependencies (list (basename image)))
|
|
|
|
#:allow-other-keys)
|
|
|
|
"Generate an image, possibly standalone, which contains all DEPENDENCIES,
|
2017-04-03 15:01:33 +02:00
|
|
|
placing the result in IMAGE.image. Link in any asd files from
|
|
|
|
DEPENDENCY-PREFIXES to ensure references to those libraries are retained."
|
2017-04-03 15:01:27 +02:00
|
|
|
(generate-executable image
|
2016-10-07 23:57:08 +02:00
|
|
|
#:dependencies dependencies
|
2017-04-03 15:01:33 +02:00
|
|
|
#:dependency-prefixes dependency-prefixes
|
2016-10-07 23:57:08 +02:00
|
|
|
#:entry-program '(nil)
|
2017-04-03 15:01:32 +02:00
|
|
|
#:type 'asdf:image-op)
|
2016-10-07 23:57:08 +02:00
|
|
|
(let* ((name (basename image))
|
|
|
|
(bin-directory (dirname image)))
|
|
|
|
(with-directory-excursion bin-directory
|
|
|
|
(rename-file (string-append name "-exec--all-systems.image")
|
|
|
|
(string-append name ".image"))))
|
|
|
|
#t)
|
|
|
|
|
2017-04-03 15:01:27 +02:00
|
|
|
(define* (generate-executable out-file #:key
|
2016-10-07 23:57:08 +02:00
|
|
|
dependencies
|
2017-04-03 15:01:33 +02:00
|
|
|
dependency-prefixes
|
2016-10-07 23:57:08 +02:00
|
|
|
entry-program
|
|
|
|
type
|
|
|
|
#:allow-other-keys)
|
2017-04-03 15:01:32 +02:00
|
|
|
"Generate an executable by using asdf operation TYPE, containing whithin the
|
2016-10-07 23:57:08 +02:00
|
|
|
image all DEPENDENCIES, and running ENTRY-PROGRAM in the case of an
|
2017-04-03 15:01:33 +02:00
|
|
|
executable. Link in any asd files from DEPENDENCY-PREFIXES to ensure
|
|
|
|
references to those libraries are retained."
|
2016-10-07 23:57:08 +02:00
|
|
|
(let* ((bin-directory (dirname out-file))
|
|
|
|
(name (basename out-file)))
|
|
|
|
(mkdir-p bin-directory)
|
|
|
|
(with-directory-excursion bin-directory
|
|
|
|
(generate-executable-wrapper-system name dependencies)
|
|
|
|
(generate-executable-entry-point name entry-program))
|
|
|
|
|
|
|
|
(prepend-to-source-registry
|
|
|
|
(string-append bin-directory "/"))
|
|
|
|
|
|
|
|
(setenv "ASDF_OUTPUT_TRANSLATIONS"
|
|
|
|
(replace-escaped-macros
|
|
|
|
(format
|
|
|
|
#f "~S"
|
|
|
|
(wrap-output-translations
|
|
|
|
`(((,bin-directory :**/ :*.*.*)
|
|
|
|
(,bin-directory :**/ :*.*.*)))))))
|
|
|
|
|
2017-04-03 15:01:27 +02:00
|
|
|
(generate-executable-for-system type name)
|
2016-10-07 23:57:08 +02:00
|
|
|
|
2017-04-03 15:01:33 +02:00
|
|
|
(let* ((after-store-prefix-index
|
|
|
|
(string-index out-file #\/
|
|
|
|
(1+ (string-length (%store-directory)))))
|
|
|
|
(output (string-take out-file after-store-prefix-index))
|
|
|
|
(hidden-asd-links (string-append output "/.asd-files")))
|
|
|
|
|
|
|
|
(mkdir-p hidden-asd-links)
|
|
|
|
(for-each
|
|
|
|
(lambda (path)
|
|
|
|
(for-each
|
|
|
|
(lambda (asd-file)
|
|
|
|
(symlink asd-file
|
|
|
|
(string-append hidden-asd-links
|
|
|
|
"/" (basename asd-file))))
|
|
|
|
(find-files (string-append path (%bundle-install-prefix))
|
|
|
|
"\\.asd$")))
|
|
|
|
dependency-prefixes))
|
|
|
|
|
2016-10-07 23:57:08 +02:00
|
|
|
(delete-file (string-append bin-directory "/" name "-exec.asd"))
|
|
|
|
(delete-file (string-append bin-directory "/" name "-exec.lisp"))))
|