From 51a9a6ea6615eef9ce66985bb1ad0c3ddec5c8d8 Mon Sep 17 00:00:00 2001 From: Tim Gesthuizen Date: Fri, 4 Jan 2019 22:34:36 +0100 Subject: [PATCH 4/5] gnu: Add package-elisp-from-package Add a function to generate package definitions that packages single elisp files from other packages. * gnu/packages/emacs.scm (package-elisp-from-package): New function --- gnu/packages/emacs.scm | 64 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/gnu/packages/emacs.scm b/gnu/packages/emacs.scm index 52f4018c2..cdee59ce4 100644 --- a/gnu/packages/emacs.scm +++ b/gnu/packages/emacs.scm @@ -35,7 +35,7 @@ ;;; Copyright © 2018 Sohom Bhattacharjee ;;; Copyright © 2018 Mathieu Lirzin ;;; Copyright © 2018 Pierre Neidhardt -;;; Copyright © 2018 Tim Gesthuizen +;;; Copyright © 2018, 2019 Tim Gesthuizen ;;; Copyright © 2018 Jack Hill ;;; Copyright © 2018 Pierre-Antoine Rouby ;;; Copyright © 2018 Alex Branham @@ -333,6 +333,68 @@ editor (without an X toolkit)" ) (lambda _ (invoke "mkdir" "-p" "src/deps"))))))))) +;;; Returns a package definition that packages an emacs-lisp file from the +;;; SRCPKG source. The package has the name PKGNAME and packages the file +;;; SRC-FILE from the source in its root directory as TARGET-FILE or the +;;; basename of SRC-FILE where INPUTS NATIVE-INPUTS and PROPAGATED-INPUTS are +;;; added as package inputs and SUBSTITUTIONS substitutions will be performed +;;; on the elisp file and SYNOPSIS and DESCRIPTION as the package synopsis and +;;; description. +(define* (package-elisp-from-package + srcpkg pkgname src-file + #:key (target-file #f) + (inputs '()) + (native-inputs '()) + (propagated-inputs '()) + (substitutions '()) + (synopsis #f) + (description #f)) + (let ((real-target-file (if target-file + target-file + (basename src-file))) + (orig (package-source srcpkg))) + (package + (inherit srcpkg) + (name pkgname) + (source (origin + (method (origin-method orig)) + (uri (origin-uri orig)) + (sha256 (origin-sha256 orig)) + (file-name (string-append pkgname "-" (package-version srcpkg))) + (modules '((guix build utils) + (srfi srfi-1) + (ice-9 ftw))) + (snippet + `(begin + ;; Copy target file to source root and delete all other files + (copy-file ,src-file + ,real-target-file) + (map delete-file-recursively + (fold delete + (scandir ".") + '("." ".." ,real-target-file))) + #t)))) + (build-system emacs-build-system) + (inputs inputs) + (native-inputs native-inputs) + (propagated-inputs propagated-inputs) + (arguments + `(#:phases + (modify-phases %standard-phases + (add-after 'unpack 'configure + (lambda* (#:key inputs #:allow-other-keys) + (emacs-substitute-variables ,real-target-file + ,substitutions) + #t))))) + (synopsis (if synopsis + synopsis + (package-synopsis srcpkg))) + (description (if description + description + (package-description srcpkg)))))) + +(export package-elisp-from-package) + ;;; ;;; Emacs hacking. -- 2.20.1