Subject: bug#63337: [PATCH] package-vc--build-documentation: Fix relative @include statements

From: Joseph Turner <[email-masked]>
Date: Mon, 08 May 2023 12:05:51 -0700

Philip Kaludercic <[email-masked]> writes:

> It might be, but I'll have to look into that in more detail, that the
> first default-directory binding is not necessary if we pass
> (package-desc-dir pkg-desc) as the second argument to `expand-file-name'
> when binding `output'.  Then this would all be simplified, and we could
> avoid the confusion you mention.

While this would mean binding default-directory only once, it still
requires two `let'-bindings.

The solution in the attached patch requires only one let-binding while
changing the behavior of package-vc--build-documentation slightly. Now
the output .info file is put inside the same directory as FILE, instead
of inside the directory returned by (package-desc-dir pkg-desc).

Note about the following two lines:

+ (file-path (expand-file-name file (package-desc-dir pkg-desc)))
+ (default-directory (expand-file-name (file-name-directory file-path)))

(package-desc-dir pkg-desc) may return a relative path with or without a
directory, e.g. "doc/manual.org" or "manual.org". In the latter case,
(file-name-directory "manual.org") would return `nil' and
(expand-file-name nil) would signal an error.

Therefore, in the `file-path' `let'-binding, we first expand the return
value of (package-desc-dir pkg-desc) to ensure that it contains a directory.

Best,

Joseph

>From 2cf2d522818c75ff5626324251bb74cdc3c36dc7 Mon Sep 17 00:00:00 2001
From: Joseph Turner <[email-masked]>
Date: Sat, 6 May 2023 14:49:43 -0700
Subject: [PATCH] Fix: (package-vc--build-documentation) Relative @include
 statements

---
 lisp/emacs-lisp/package-vc.el | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lisp/emacs-lisp/package-vc.el b/lisp/emacs-lisp/package-vc.el
index 476c38916a8..65767cf043a 100644
--- a/lisp/emacs-lisp/package-vc.el
+++ b/lisp/emacs-lisp/package-vc.el
@@ -376,14 +376,17 @@ Package specs are loaded from trusted package archives."
 FILE can be an Org file, indicated by its \".org\" extension,
 otherwise it's assumed to be an Info file."
   (let* ((pkg-name (package-desc-name pkg-desc))
-         (default-directory (package-desc-dir pkg-desc))
+         (file-path (expand-file-name file (package-desc-dir pkg-desc)))
+         ;; `let'-bind `default-directory' to the directory containing the .org or .info FILE
+         ;; so that makeinfo can resolve relative @include statements in the docs directory.
+         (default-directory (expand-file-name (file-name-directory file-path)))
          (output (expand-file-name (format "%s.info" pkg-name)))
          clean-up)
     (when (string-match-p "\\.org\\'" file)
       (require 'ox)
       (require 'ox-texinfo)
       (with-temp-buffer
-        (insert-file-contents file)
+        (insert-file-contents file-path)
         (setq file (make-temp-file "ox-texinfo-"))
         (org-export-to-file 'texinfo file)
         (setq clean-up t)))
-- 
2.39.2