unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
To: 60868@debbugs.gnu.org
Cc: jgart <jgart@dismail.de>,
	ludo@gnu.org, Lars-Dominik Braun <lars@6xq.net>,
	Maxim Cournoyer <maxim.cournoyer@gmail.com>
Subject: [bug#60868] [PATCH v2] build: pyproject-build-system: Use wrap-script instead of wrap-program.
Date: Mon, 23 Jan 2023 08:33:54 -0500	[thread overview]
Message-ID: <20230123133354.1345-1-maxim.cournoyer@gmail.com> (raw)
In-Reply-To: <20230116203711.2214-1-maxim.cournoyer@gmail.com>

* guix/build-system/pyproject.scm (default-guile): New procedure.
(lower) Add guile to the host-inputs of the bag.
* guix/build/pyproject-build-system.scm (wrap): Replace wrap-program with
wrap-script.  Rename bash-related nested variables/procedure with
guile-related ones.

---

Changes in v2:
- Rebase

 guix/build-system/pyproject.scm       |  9 +++++++-
 guix/build/pyproject-build-system.scm | 30 ++++++++++++++++++++++++---
 2 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/guix/build-system/pyproject.scm b/guix/build-system/pyproject.scm
index 74d739023f..8b5091c654 100644
--- a/guix/build-system/pyproject.scm
+++ b/guix/build-system/pyproject.scm
@@ -59,6 +59,12 @@ (define (default-python)
   (let ((python (resolve-interface '(gnu packages python))))
     (module-ref python 'python-toolchain)))
 
+(define (default-guile)
+  "Return the default Guile used to wrap Python scripts."
+  ;; Lazily resolve the binding to avoid a circular dependency.
+  (let ((guile (resolve-interface '(gnu packages guile))))
+    (module-ref guile 'guile-3.0)))
+
 (define sanity-check.py
   ;; TODO: Merge with sanity-check.py in the next rebuild cycle.
   (search-auxiliary-file "python/sanity-check-next.py"))
@@ -88,7 +94,8 @@ (define private-keywords
                           '())
                     ;; Keep the standard inputs of 'gnu-build-system'.
                     ,@(standard-packages)))
-    (host-inputs inputs)
+    (host-inputs (modify-inputs inputs
+                   (append (default-guile))))
     (target-inputs (if target
                        (standard-cross-packages target 'target)
                        '()))
diff --git a/guix/build/pyproject-build-system.scm b/guix/build/pyproject-build-system.scm
index e51b5cfc43..a66c1fb34a 100644
--- a/guix/build/pyproject-build-system.scm
+++ b/guix/build/pyproject-build-system.scm
@@ -445,9 +445,33 @@ (define* (add-install-to-pythonpath #:key native-inputs outputs
   "A phase that just wraps the 'add-installed-pythonpath' procedure."
   (add-installed-pythonpath native-inputs outputs))
 
-(define* (wrap #:key native-inputs outputs #:allow-other-keys #:rest args)
-  (apply (assoc-ref python:%standard-phases 'wrap)
-         (append args (list #:inputs native-inputs))))
+(define* (wrap #:key inputs outputs #:allow-other-keys)
+  (define (list-of-files dir)
+    (find-files dir (lambda (file stat)
+                      (and (eq? 'regular (stat:type stat))
+                           (not (wrapped-program? file))))))
+
+  (define bindirs
+    (append-map (match-lambda
+                  ((_ . dir)
+                   (list (string-append dir "/bin")
+                         (string-append dir "/sbin"))))
+                outputs))
+
+  ;; Do not require "guile" to be present in the package inputs
+  ;; even when there is nothing to wrap.
+  ;; Also, calculate (guile) only once to prevent some I/O.
+  (define %guile (delay (search-input-file inputs "bin/guile")))
+  (define (guile) (force %guile))
+
+  (let* ((var `("GUIX_PYTHONPATH" prefix
+                ,(search-path-as-string->list
+                  (or (getenv "GUIX_PYTHONPATH") "")))))
+    (for-each (lambda (dir)
+                (let ((files (list-of-files dir)))
+                  (for-each (cut wrap-script <> #:guile (guile) var)
+                            files)))
+              bindirs)))
 
 (define* (rename-pth-file #:key name native-inputs outputs #:allow-other-keys
                           #:rest args)

base-commit: 67458b9793d69c7d10c7d885edd5d1ce5a2e9648
-- 
2.39.1





  parent reply	other threads:[~2023-01-23 13:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-16 20:37 [bug#60868] [PATCH] build: pyproject-build-system: Use wrap-script instead of wrap-program Maxim Cournoyer
2023-01-17 15:52 ` Maxim Cournoyer
2023-01-23 13:33 ` Maxim Cournoyer [this message]
2023-01-24  8:42   ` [bug#60868] [PATCH v2] " Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230123133354.1345-1-maxim.cournoyer@gmail.com \
    --to=maxim.cournoyer@gmail.com \
    --cc=60868@debbugs.gnu.org \
    --cc=jgart@dismail.de \
    --cc=lars@6xq.net \
    --cc=ludo@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).