From patchwork Fri Sep 2 14:02:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Tropin X-Patchwork-Id: 42146 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 7E00027BBEA; Fri, 2 Sep 2022 15:03:17 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 400F227BBE9 for ; Fri, 2 Sep 2022 15:03:16 +0100 (BST) Received: from localhost ([::1]:33744 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU7GN-0004td-BG for patchwork@mira.cbaines.net; Fri, 02 Sep 2022 10:03:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41482) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU7GB-0004qA-L2 for guix-patches@gnu.org; Fri, 02 Sep 2022 10:03:05 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:57595) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oU7GA-00018t-47 for guix-patches@gnu.org; Fri, 02 Sep 2022 10:03:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oU7G9-0005rS-UL for guix-patches@gnu.org; Fri, 02 Sep 2022 10:03:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#57280] [PATCH 0/3] Add documentation-files argument to emacs build system. Resent-From: Andrew Tropin Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 02 Sep 2022 14:03:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 57280 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Liliana Marie Prikler Cc: 57280@debbugs.gnu.org Received: via spool by 57280-submit@debbugs.gnu.org id=B57280.166212737822521 (code B ref 57280); Fri, 02 Sep 2022 14:03:01 +0000 Received: (at 57280) by debbugs.gnu.org; 2 Sep 2022 14:02:58 +0000 Received: from localhost ([127.0.0.1]:47344 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oU7G5-0005rA-5p for submit@debbugs.gnu.org; Fri, 02 Sep 2022 10:02:57 -0400 Received: from relay1-d.mail.gandi.net ([217.70.183.193]:53675) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oU7G1-0005qq-O4 for 57280@debbugs.gnu.org; Fri, 02 Sep 2022 10:02:55 -0400 Received: (Authenticated sender: andrew@trop.in) by mail.gandi.net (Postfix) with ESMTPSA id 8CFFA240006; Fri, 2 Sep 2022 14:02:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trop.in; s=gm1; t=1662127367; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=0EwNg86zb8Hcd8tLlcqYfiY3MrnpAWmw2At2YJsKIdE=; b=Soucy1jp9lYK1WJ4rMx9PNwF519Ug5ojckCFjWOB4AIs0LuXMMKpJVNkPpX+5YTEljFC/7 Gn9reidZTcI5Wnzl7QEJGxHWT0uodvxBnc65+fvU4qVmqPdD4USA1xn1GHXnStsw2oybOM VoWtAgTXCmdoPfanTGvpqjiSLHGLXKps6Z1s6gBZQ9R9jRN9T9rZBhmUqEq1j3mWjY1xfr tyGnxZNW3SwZi4kfEw17sdyhZ+dZGOkHwEZXqEj7xoJooVcUVCdD4wovzMU5I0YVNg5RLo MccTWaKYAk0KiElVhnEfIFyELm2jm7xqCxDxNGmQ5Badi1itkI/FpgNR9uFx9g== From: Andrew Tropin In-Reply-To: <64cd6f7171047bfe95ba9621c4616b9288b7dba9.camel@gmail.com> References: <87v8q8u54p.fsf@trop.in> <64cd6f7171047bfe95ba9621c4616b9288b7dba9.camel@gmail.com> Date: Fri, 02 Sep 2022 17:02:42 +0300 Message-ID: <87czcd3md9.fsf@trop.in> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches On 2022-08-31 12:07, Liliana Marie Prikler wrote: > Am Mittwoch, dem 31.08.2022 um 12:36 +0300 schrieb Andrew Tropin: >> > I think if we want to go this more generic route, we'd have to >> > redesign this a little.  For instance, (build-texinfo- >> > documentation) should take >> > regular expressions as remaining arguments.  >> >> What can be a good place (module) for such build phases? > I was thinking (guix build utils). Of course, one could introduce a > new module, but doing that would come with even more downsides in terms > of UX (or PX if we're pedantic). Ok, I prepared more generic version of the patch. Picked (guix build emacs-utils) for now, it's done to avoid huge rebuilds, while testing, later we can move it to (guix build utils). Also, temporary added pandoc and texinfo to native-inputs for emacs-build-system, otherwise I would need to update inputs for almost every emacs-* package. Need to figure out what to do with this. > >> Attaching the latest version of the documentation-files patch I have > Looking at this patch, perhaps we'd also have to allow customizing > command line options. Also, as for installing, I think this should be > handled by the install phase, which already has includes > "^[^/]*\\.info$" and "^doc/.*\\.info$" by default. Thus, you only need > to build documentation before the install phase. That's right, but in the new iteration (v3) of build-documentation phase I use find-root-library-file, which expects to be executed when elpa directory is already available, so I can't do it before install phase and need to manually install info files. Also, current build phases order is a little confusing, a lot of builds happens after install phase, directly in output directory: `set-SOURCE-DATE-EPOCH' `set-paths' `install-locale' `unpack' `expand-load-path' `patch-usr-bin-file' `patch-source-shebangs' `patch-generated-file-shebangs' `check' `install' `make-autoloads' `enable-autoloads-compilation' `patch-el-files' `ensure-package-description' `build' `validate-compiled-autoloads' `build-documentation' `move-doc' `patch-shebangs' `strip' `validate-runpath' `validate-documentation-location' `delete-info-dir-file' `patch-dot-desktop-files' `make-dynamic-linker-cache' `install-license-files' `reset-gzip-timestamps' `compress-documentation' What if instead of install phase we will use create-tmp-lisp-and-documentation-directories phase (or something more meaningful) to make a temporary directory, where we will build all the stuff and after that, at the end of the build process will install everything from this temporary directory to the store? This way emacs-build-system will become more usual and easier to understand and predict. From 4a706908491daafc0493ab15297665eb2b9fce4e Mon Sep 17 00:00:00 2001 From: Andrew Tropin Date: Fri, 2 Sep 2022 08:23:18 +0300 Subject: [PATCH v3] build-system: emacs: Add build-documentation phase. Allows to build info files from texinfo, org or other markup files. * guix/build-system/emacs.scm (default-texinfo, default-pandoc): New variable. (lower)[build-inputs]: Add texinfo and pandoc. * guix/build/emacs-build-system.scm (build-documentantion): New variable. * guix/build/emacs-utils.scm (build-documentantion-texinfo, build-documentation-org, convert-documentation): New variable. * gnu/packages/emacs-xyz.scm (emacs-orderless)[arguments]: Remove custom documentation build phase. (emacs-org)[arguments]: Remove build-documentation as it already builds documentation with make. --- gnu/packages/emacs-xyz.scm | 21 ++++++------- guix/build-system/emacs.scm | 16 +++++++++- guix/build/emacs-build-system.scm | 42 +++++++++++++++++++++++++- guix/build/emacs-utils.scm | 49 +++++++++++++++++++++++++++++++ 4 files changed, 114 insertions(+), 14 deletions(-) diff --git a/gnu/packages/emacs-xyz.scm b/gnu/packages/emacs-xyz.scm index 074d4d1c4c..f6fb76258b 100644 --- a/gnu/packages/emacs-xyz.scm +++ b/gnu/packages/emacs-xyz.scm @@ -2974,6 +2974,7 @@ (define-public emacs-auctex #:exclude '("^tests/" "^latex/README") #:phases (modify-phases %standard-phases + (delete 'build-documentation) (add-after 'unpack 'configure (lambda* (#:key inputs #:allow-other-keys) (emacs-substitute-variables "preview.el" @@ -9155,17 +9156,6 @@ (define-public emacs-orderless (base32 "0m9nyz80j0qnn14drbgk8vn5yr7sv0z6yiz8w95ahcw2qwlgyjs7")) (file-name (git-file-name name version)))) (build-system emacs-build-system) - (arguments - `(#:phases - (modify-phases %standard-phases - (add-after 'install 'makeinfo - (lambda* (#:key outputs #:allow-other-keys) - (invoke "makeinfo" "orderless.texi") - (install-file "orderless.info" - (string-append (assoc-ref outputs "out") - "/share/info"))))))) - (native-inputs - (list texinfo)) (home-page "https://github.com/oantolin/orderless") (synopsis "Emacs completion style that matches multiple regexps in any order") (description "This package provides an orderless completion style that @@ -13250,6 +13240,7 @@ (define-public emacs-org #:phases (modify-phases %standard-phases (delete 'build) + (delete 'build-documentation) (add-before 'check 'make (lambda _ (invoke "make" (string-append "ORGVERSION=" ,version)))) @@ -17846,7 +17837,13 @@ (define-public emacs-esxml `(#:emacs ,emacs ;need libxml ;; XXX: Only the two following files are meant to be packaged. ;; Byte-compiling the others Elisp files leads to build errors anyway. - #:include (list "esxml.el" "esxml-query.el"))) + #:include (list "esxml.el" "esxml-query.el") + #:phases (modify-phases %standard-phases + (add-before 'build-documentation 'fix-readme-org + (lambda _ + (substitute* "README.org" + ;; Fix malformed src block + (("^#\\+BEGIN_SRC\\s$") "#+BEGIN_SRC html"))))))) (propagated-inputs (list emacs-kv)) (home-page "https://github.com/tali713/esxml/") diff --git a/guix/build-system/emacs.scm b/guix/build-system/emacs.scm index 3df68789ff..61746f26a5 100644 --- a/guix/build-system/emacs.scm +++ b/guix/build-system/emacs.scm @@ -56,6 +56,18 @@ (define (default-emacs) (let ((emacs-mod (resolve-interface '(gnu packages emacs)))) (module-ref emacs-mod 'emacs-minimal))) +(define (default-texinfo) + "Return the default texinfo package." + ;; Lazily resolve the binding to avoid a circular dependency. + (let ((texinfo-mod (resolve-interface '(gnu packages texinfo)))) + (module-ref texinfo-mod 'texinfo))) + +(define (default-pandoc) + "Return the default pandoc package." + ;; Lazily resolve the binding to avoid a circular dependency. + (let ((pandoc-mod (resolve-interface '(gnu packages haskell-xyz)))) + (module-ref pandoc-mod 'pandoc))) + (define* (lower name #:key source inputs native-inputs outputs system target (emacs (default-emacs)) @@ -77,7 +89,9 @@ (define private-keywords ;; Keep the standard inputs of 'gnu-build-system'. ,@(standard-packages))) (build-inputs `(("emacs" ,emacs) - ,@native-inputs)) + ,@native-inputs + ("pandoc" ,(default-pandoc)) + ("texinfo" ,(default-texinfo)))) (outputs outputs) (build emacs-build) (arguments (strip-keyword-arguments private-keywords arguments))))) diff --git a/guix/build/emacs-build-system.scm b/guix/build/emacs-build-system.scm index 6a6918bfdd..fe03fa975c 100644 --- a/guix/build/emacs-build-system.scm +++ b/guix/build/emacs-build-system.scm @@ -274,6 +274,45 @@ (define (match-stripped-file action regex) (install-file? file stat #:verbose? #t))) #f)))) +(define* (build-documentation #:key outputs #:allow-other-keys) + (let* ((out (assoc-ref outputs "out")) + (library-root (with-directory-excursion (elpa-directory out) + (find-root-library-file + (store-directory->elpa-name-version out)))) + (texi-file-name (if library-root + (string-append library-root ".texi") + #f)) + + (readme-regexp (make-regexp "README.*" regexp/icase)) + (readme-files (find-files "." readme-regexp)) + (readme-file (match readme-files + ((file . _) file) + (_ #f))) + + (texi-regexp (string-append library-root "\\.texi")) + (texinfo-files (find-files "." texi-regexp))) + + (if (null? texinfo-files) + (cond + ((and readme-file (string-suffix? ".org" readme-file)) + ((build-documentation-org #:files (list readme-file)))) + ((and readme-file texi-file-name) + ((convert-documentation #:mapping + `((,readme-file . ,texi-file-name)))) + ((build-documentation-texinfo + #:files (list texi-file-name) + ;; Some README.md can have missing levels of subheadings or + ;; incorrect links, this is why --force is used. Examples of such + ;; READMEs: emacs-avy, emacs-git-gutter, emacs-f. + #:command '("makeinfo" "--no-split" "--force")))) + (else #t)) + + ((build-documentation-texinfo #:files texinfo-files))) + + (for-each (lambda (f) + (install-file f (string-append out %install-dir))) + (find-files "." "\\.info$")))) + (define* (move-doc #:key outputs #:allow-other-keys) "Move info files from the ELPA package directory to the info directory." (let* ((out (assoc-ref outputs "out")) @@ -357,7 +396,8 @@ (define %standard-phases ;; The .el files are byte compiled directly in the store. (add-after 'ensure-package-description 'build build) (add-after 'build 'validate-compiled-autoloads validate-compiled-autoloads) - (add-after 'validate-compiled-autoloads 'move-doc move-doc))) + (add-after 'validate-compiled-autoloads 'move-doc move-doc) + (add-before 'move-doc 'build-documentation build-documentation))) (define* (emacs-build #:key inputs (phases %standard-phases) #:allow-other-keys #:rest args) diff --git a/guix/build/emacs-utils.scm b/guix/build/emacs-utils.scm index 8ee547f2b3..b7e0a3e939 100644 --- a/guix/build/emacs-utils.scm +++ b/guix/build/emacs-utils.scm @@ -36,6 +36,10 @@ (define-module (guix build emacs-utils) emacs-batch-error? emacs-batch-error-message + build-documentation-texinfo + build-documentation-org + convert-documentation + emacs-generate-autoloads emacs-byte-compile-directory emacs-header-parse @@ -100,6 +104,51 @@ (define (emacs-batch-script expr) (message (read-string (car error-pipe))))))) output)) + +;;; +;;; Helpers for generating frequently used phases. +;;; + +(define* (build-documentation-texinfo + #:key + (files '()) + (command '("makeinfo" "--no-split"))) + "Don't forget to add texinfo into list of inputs for the package." + (lambda* (#:key outputs #:allow-other-keys) + (for-each (lambda (f) (apply invoke (append command (list f)))) files))) + +(define* (build-documentation-org + #:key + (files '())) + "This is a preferred way over pandoc, because it keeps the meta information +from in-buffer org settings. Don't forget to add texinfo and emacs into list +of inputs for the package." + (lambda* (#:key outputs #:allow-other-keys) + (for-each (lambda (f) + (emacs-batch-script + `(progn + (require 'ox-texinfo) + (find-file ,f) + (let ((org-export-use-babel nil) + (org-texinfo-info-process + '("makeinfo --force --no-split %f"))) + (org-texinfo-export-to-info))))) files))) + +(define* (convert-documentation + #:key + (mapping '()) + (command '("pandoc"))) + "Don't forget to add pandoc into list of inputs for the package." + (lambda* (#:key outputs #:allow-other-keys) + (for-each (lambda (p) (apply invoke + (append command + (list (car p) "-o" (cdr p))))) + mapping))) + +;;; +;;; Helpers for generating frequently used phases ends here. +;;; + (define (emacs-generate-autoloads name directory) "Generate autoloads for Emacs package NAME placed in DIRECTORY." (let* ((file (string-append directory "/" name "-autoloads.el")) -- 2.37.2