From 5de8779ad933faf883348f6cab09671f1e081a67 Mon Sep 17 00:00:00 2001 From: Liliana Marie Prikler Date: Thu, 19 Oct 2023 06:06:48 +0200 Subject: guix: emacs-build-system: Process package source in build tree. * guix/build/emacs-build-system.scm (ensure-package-description) (patch-el-files, make-autoloads): Operate on the current working directory, either implicitly, or through (getcwd). (enable-autoloads-compilation): Deleted variable, logic moved into make-autoloads. (%standard-phases): Adjust accordingly. --- guix/build/emacs-build-system.scm | 85 ++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 51 deletions(-) (limited to 'guix') diff --git a/guix/build/emacs-build-system.scm b/guix/build/emacs-build-system.scm index 3808b60445..aa083c6409 100644 --- a/guix/build/emacs-build-system.scm +++ b/guix/build/emacs-build-system.scm @@ -132,29 +132,25 @@ (define* (build #:key outputs inputs #:allow-other-keys) (parameterize ((%emacs emacs)) (emacs-compile-directory (elpa-directory out))))) -(define* (patch-el-files #:key outputs #:allow-other-keys) - "Substitute the absolute \"/bin/\" directory with the right location in the -store in '.el' files." - - (let* ((out (assoc-ref outputs "out")) - (elpa-name-ver (store-directory->elpa-name-version out)) - (el-dir (string-append out %install-dir "/" elpa-name-ver)) - (el-files (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 - ;; ISO-8859-1-encoded. - (unless (false-if-exception (substitute-program-names)) - (with-fluids ((%default-port-encoding "ISO-8859-1")) - (substitute-program-names)))) - #t)) +(define* (patch-el-files #:key inputs outputs #:allow-other-keys) + "Substitute the absolute \"/bin/\" and \"/sbin\" directories with the right +locations in the store in '.el' files." + + (define substitute-program-names + (let ((el-files (find-files (getcwd) "\\.el$"))) + (lambda () + (substitute* el-files + (("\"/(s?bin/[^.]\\S*)\"" _ cmd) + (let ((cmd (search-input-file inputs cmd))) + (unless cmd + (error "patch-el-files: unable to locate " (basename cmd))) + (string-append "\"" cmd "\""))))))) + + (unless (false-if-exception (substitute-program-names)) + ;; Some old '.el' files (e.g., tex-buf.el in AUCTeX) are still + ;; ISO-8859-1-encoded. + (with-fluids ((%default-port-encoding "ISO-8859-1")) + (substitute-program-names)))) (define (find-root-library-file name) (let loop ((parts (string-split @@ -224,10 +220,8 @@ (define %write-pkg-file-form (emacs-batch-edit-file (string-append name ".el") %write-pkg-file-form))) - (let* ((out (assoc-ref outputs "out")) - (elpa-name-ver (store-directory->elpa-name-version out))) - (with-directory-excursion (elpa-directory out) - (and=> (find-root-library-file elpa-name-ver) write-pkg-file)))) + (let ((name (store-directory->elpa-name-version (assoc-ref outputs "out")))) + (and=> (find-root-library-file name) write-pkg-file))) (define* (check #:key tests? (test-command '("make" "check")) (parallel-tests? #t) #:allow-other-keys) @@ -306,24 +300,15 @@ (define* (move-doc #:key outputs #:allow-other-keys) info-files))) #t)) -(define* (make-autoloads #:key outputs inputs #:allow-other-keys) +(define* (make-autoloads #:key outputs #:allow-other-keys) "Generate the autoloads file." - (let* ((emacs (search-input-file inputs "/bin/emacs")) - (out (assoc-ref outputs "out")) - (elpa-name-ver (store-directory->elpa-name-version out)) - (elpa-name (package-name->name+version elpa-name-ver)) - (el-dir (elpa-directory out))) - (parameterize ((%emacs emacs)) - (emacs-generate-autoloads elpa-name el-dir)))) - -(define* (enable-autoloads-compilation #:key outputs #:allow-other-keys) - "Remove the NO-BYTE-COMPILATION local variable embedded in the generated -autoload files." - (let* ((out (assoc-ref outputs "out")) - (autoloads (find-files out "-autoloads.el$"))) - (substitute* autoloads - ((";; no-byte-compile.*") "")) - #t)) + (emacs-generate-autoloads + (package-name->name+version (store-directory->elpa-name-version + (assoc-ref outputs "out"))) + (getcwd)) + ;; Ensure that autoloads can be byte-compiled. + (substitute* (find-files "." "-autoloads\\.el$") + ((";; no-byte-compile.*") ""))) (define* (validate-compiled-autoloads #:key outputs #:allow-other-keys) "Verify whether the byte compiled autoloads load fine." @@ -358,7 +343,11 @@ (define (elpa-directory store-dir) (define %standard-phases (modify-phases gnu:%standard-phases (replace 'unpack unpack) + (add-after 'unpack 'ensure-package-description + ensure-package-description) (add-after 'unpack 'expand-load-path expand-load-path) + (add-after 'unpack 'patch-el-files patch-el-files) + (add-after 'expand-load-path 'make-autoloads make-autoloads) (add-after 'expand-load-path 'add-install-to-native-load-path add-install-to-native-load-path) (delete 'bootstrap) @@ -366,14 +355,8 @@ (define %standard-phases (delete 'build) (replace 'check check) (replace 'install install) - (add-after 'install 'make-autoloads make-autoloads) - (add-after 'make-autoloads 'enable-autoloads-compilation - enable-autoloads-compilation) - (add-after 'enable-autoloads-compilation 'patch-el-files patch-el-files) - (add-after 'patch-el-files 'ensure-package-description - ensure-package-description) ;; The .el files are byte compiled directly in the store. - (add-after 'ensure-package-description 'build build) + (add-after 'install 'build build) (add-after 'build 'validate-compiled-autoloads validate-compiled-autoloads) (add-after 'validate-compiled-autoloads 'move-doc move-doc))) -- cgit v1.2.3 From 56a7c1308a1f1601299b8c7706fb4d00d5c185d0 Mon Sep 17 00:00:00 2001 From: Liliana Marie Prikler Date: Tue, 13 Feb 2024 19:30:50 +0100 Subject: build-system: emacs: Compute relative file names. With the previous commit, relative file names are expanded relative to ELN_DIR -- more or less. To make use of this in emacs-build-system, we must also pass relative file names. * guix/build/emacs-build-system.scm (emacs-compile-directory): Compute the relative file names of the files to compile. Change-Id: I8983f80fb0fe1573e46748222403ba8873f1599f --- guix/build/emacs-utils.scm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'guix') diff --git a/guix/build/emacs-utils.scm b/guix/build/emacs-utils.scm index 8e12b5b6d4..eca42bf305 100644 --- a/guix/build/emacs-utils.scm +++ b/guix/build/emacs-utils.scm @@ -146,7 +146,9 @@ (define* (emacs-compile-directory dir) (cadr native-comp-eln-load-path)))) (if byte+native-compile (native-compile file - (comp-el-to-eln-filename file eln-dir)) + (comp-el-to-eln-filename + (file-relative-name file ,dir) + eln-dir)) (byte-compile-file file)) ;; After native compilation, write the bytecode file. (unless (null byte-to-native-output-buffer-file) -- cgit v1.2.3 From 7f3f70eedbbec74481a0ca9fea4c19250961685e Mon Sep 17 00:00:00 2001 From: Liliana Marie Prikler Date: Sat, 2 Mar 2024 16:56:13 +0100 Subject: guix: emacs-utils: Make emacs-compile-directory forwards-compatible. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Newer (development) builds of Emacs 30 mark a number of functions related to native compilation as ‘internal’. Since we rely on such functions and there does not appear to be a high-level replacement at the moment, let's work around this case. * guix/build/emacs-utils.scm (emacs-compile-directory): Require comp early and check if ‘comp-write-bytecode-file’ is available. Fixes: Upstream renamed comp-write-bytecode-file --- guix/build/emacs-utils.scm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'guix') diff --git a/guix/build/emacs-utils.scm b/guix/build/emacs-utils.scm index eca42bf305..aeb364133a 100644 --- a/guix/build/emacs-utils.scm +++ b/guix/build/emacs-utils.scm @@ -136,7 +136,14 @@ (define* (emacs-compile-directory dir) (emacs-batch-eval `(let ((byte-compile-debug t) ; for proper exit status (byte+native-compile (native-comp-available-p)) - (files (directory-files-recursively ,dir "\\.el$"))) + (files (directory-files-recursively ,dir "\\.el$")) + (write-bytecode + (and (native-comp-available-p) + (progn + (require 'comp) + (if (fboundp 'comp-write-bytecode-file) + 'comp-write-bytecode-file + 'comp--write-bytecode-file))))) (mapc (lambda (file) (let (byte-to-native-output-buffer-file @@ -152,7 +159,7 @@ (define* (emacs-compile-directory dir) (byte-compile-file file)) ;; After native compilation, write the bytecode file. (unless (null byte-to-native-output-buffer-file) - (comp-write-bytecode-file nil)))) + (funcall write-bytecode nil)))) files)) #:dynamic? #t)) -- cgit v1.2.3