Subject: [PATCH v2] [WIP] gnu: python-notmuch2: Fix build.

From: Tanguy Le Carrour <[email-masked]>
Date: Wed, 16 Mar 2022 12:16:24 +0100

Hi Liliana,

Did you have something along these lines in mind?

I wanted to add the `create-notmuch-config` phase after the `enter-python-dir`,
but I don't know how to get the source folder from there. I suppose
there's a way to get the `../../` of the `cwd`, but I don't (yet) know how.

The generated contains the expected paths:

```
NOTMUCH_VERSION_FILE='/tmp/guix-build-python-notmuch2-0.35.drv-0/notmuch-0.35/version.txt'
NOTMUCH_INCLUDE_DIR='/tmp/guix-build-python-notmuch2-0.35.drv-0/notmuch-0.35/lib'
NOTMUCH_LIB_DIR='/tmp/guix-build-python-notmuch2-0.35.drv-0/notmuch-0.35/lib'
```

… but they **always** reference `drv-0`, even if it's not the first build!?
For instance:

```
$ cat /tmp/guix-build-python-notmuch2-0.35.drv-6/notmuch-0.35/bindings/python-cffi/_notmuch_config.py                                                                                                                      [profile] guix-dev
NOTMUCH_VERSION_FILE='/tmp/guix-build-python-notmuch2-0.35.drv-0/notmuch-0.35/version.txt'
NOTMUCH_INCLUDE_DIR='/tmp/guix-build-python-notmuch2-0.35.drv-0/notmuch-0.35/lib'
NOTMUCH_LIB_DIR='/tmp/guix-build-python-notmuch2-0.35.drv-0/notmuch-0.35/lib'
```

Does it matter?!

Regards,

--
Tanguy
---
 gnu/packages/mail.scm | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/gnu/packages/mail.scm b/gnu/packages/mail.scm
index d253ca7011..f6769cad02 100644
--- a/gnu/packages/mail.scm
+++ b/gnu/packages/mail.scm
@@ -28,7 +28,7 @@
 ;;; Copyright © 2018 Alex Vong <[email-masked]>
 ;;; Copyright © 2018 Gábor Boskovits <[email-masked]>
 ;;; Copyright © 2018, 2019, 2020, 2021, 2022 Ricardo Wurmus <[email-masked]>
-;;; Copyright © 2019, 2020, 2021 Tanguy Le Carrour <[email-masked]>
+;;; Copyright © 2019, 2020-2022 Tanguy Le Carrour <[email-masked]>
 ;;; Copyright © 2020 Vincent Legoll <[email-masked]>
 ;;; Copyright © 2020 Justus Winter <[email-masked]>
 ;;; Copyright © 2020 Eric Brown <[email-masked]>
@@ -1490,9 +1490,21 @@ (define-public python-notmuch2
     (arguments
      `(#:phases
        (modify-phases %standard-phases
+         ;; configure generates `bindings/python-cffi/_notmuch_config.py`
+         ;; https://git.notmuchmail.org/git?p=notmuch;a=commit;h=7b5921877e748338359a25dae578771f768183af
+         (add-after 'unpack 'create-notmuch-config
+           (lambda _
+             (let ((cwd (getcwd)))
+               (with-output-to-file "bindings/python-cffi/_notmuch_config.py"
+                 (lambda _
+                   (display
+                    (string-append
+                     "NOTMUCH_VERSION_FILE='" cwd "/version.txt'\n"
+                     "NOTMUCH_INCLUDE_DIR='" cwd "/lib'\n"
+                     "NOTMUCH_LIB_DIR='" cwd "/lib'")))))))
          ;; This python package lives in a subdirectory of the notmuch source
          ;; tree, so chdir into it before building.
-         (add-after 'unpack 'enter-python-dir
+         (add-after 'create-notmuch-config 'enter-python-dir
            (lambda _ (chdir "bindings/python-cffi"))))))
     (synopsis "Pythonic bindings for the notmuch mail database using CFFI")
     (license license:gpl3+)))
-- 
2.34.0