From 7c599eac0c26ea0cc61d711c5e777b893519e90c Mon Sep 17 00:00:00 2001 From: Maxim Cournoyer Date: Sun, 14 Jan 2018 22:38:20 -0500 Subject: emacs-build-system: Do not patch files containing NULs. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a temporary workaround for , where 'substitute*' throws on files containing NUL characters. * guix/build/emacs-build-system.scm (patch-el-files): Filter out elisp files that contain NUL characters. Co-authored-by: Ludovic Courtès --- guix/build/emacs-build-system.scm | 41 +++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/guix/build/emacs-build-system.scm b/guix/build/emacs-build-system.scm index a68ca60c7e..b779847424 100644 --- a/guix/build/emacs-build-system.scm +++ b/guix/build/emacs-build-system.scm @@ -97,23 +97,40 @@ archive, a directory, or an Emacs Lisp file." (define* (patch-el-files #:key outputs #:allow-other-keys) "Substitute the absolute \"/bin/\" directory with the right location in the store in '.el' files." + + (define (file-contains-nul-char? file) + (call-with-input-file file + (lambda (in) + (let loop ((line (read-line in 'concat))) + (cond + ((eof-object? line) #f) + ((string-index line #\nul) #t) + (else (loop (read-line in 'concat)))))) + #:binary #t)) + (let* ((out (assoc-ref outputs "out")) (elpa-name-ver (store-directory->elpa-name-version out)) (el-dir (string-append out %install-suffix "/" elpa-name-ver)) - (substitute-cmd (lambda () - (substitute* (find-files "." "\\.el$") - (("\"/bin/([^.]\\S*)\"" _ cmd-name) - (let ((cmd (which cmd-name))) - (unless cmd - (error - "patch-el-files: unable to locate " cmd-name)) - (string-append "\"" cmd "\""))))))) + + ;; (ice-9 regex) uses libc's regexp routines, which cannot deal with + ;; strings containing NULs. Filter out such files. TODO: Remove + ;; this workaround when is fixed. + (el-files (remove file-contains-nul-char? + (find-files (getcwd) "\\.el$")))) + (define (substitute-program-names) + (substitute* el-files + (("\"/bin/([^.]\\S*)\"" _ cmd-name) + (let ((cmd (which cmd-name))) + (unless cmd + (error "patch-el-files: unable to locate " cmd-name)) + (string-append "\"" cmd "\""))))) + (with-directory-excursion el-dir - ;; Some old '.el' files (e.g., tex-buf.el in AUCTeX) are still encoded - ;; with the "ISO-8859-1" locale. - (unless (false-if-exception (substitute-cmd)) + ;; Some old '.el' files (e.g., tex-buf.el in AUCTeX) are still + ;; ISO-8859-1-encoded. + (unless (false-if-exception (substitute-program-names)) (with-fluids ((%default-port-encoding "ISO-8859-1")) - (substitute-cmd)))) + (substitute-program-names)))) #t)) (define* (install #:key outputs -- cgit v1.2.3