From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alex Sassmannshausen Subject: bug#27003: [PATCH 1/3] build/utils: Add 'program-wrapper'. Date: Sat, 20 May 2017 11:40:28 +0200 Message-ID: <20170520094030.2471-1-alex@pompo.co> References: <20170520093742.2115-1-alex@pompo.co> Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:43694) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dC0sl-0000HI-Gp for bug-guix@gnu.org; Sat, 20 May 2017 05:41:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dC0sg-0008Tf-Jd for bug-guix@gnu.org; Sat, 20 May 2017 05:41:07 -0400 Received: from debbugs.gnu.org ([208.118.235.43]:53330) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dC0sg-0008Ta-Ce for bug-guix@gnu.org; Sat, 20 May 2017 05:41:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dC0sf-000375-W1 for bug-guix@gnu.org; Sat, 20 May 2017 05:41:02 -0400 In-Reply-To: <20170520093742.2115-1-alex@pompo.co> Sender: "Debbugs-submit" Resent-Message-ID: List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+gcggb-bug-guix=m.gmane.org@gnu.org Sender: "bug-Guix" To: 27003@debbugs.gnu.org * guix/build/utils.scm (program-wrapper): New procedure. --- guix/build/utils.scm | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/guix/build/utils.scm b/guix/build/utils.scm index e8efb0653..af5583651 100644 --- a/guix/build/utils.scm +++ b/guix/build/utils.scm @@ -78,6 +78,7 @@ patch-/usr/bin/file fold-port-matches remove-store-references + program-wrapper wrap-program locale-category->string)) @@ -956,6 +957,41 @@ known as `nuke-refs' in Nixpkgs." (put-u8 out (char->integer char)) result)))))) +(define (program-wrapper path-proc env-var) + "Return a procedure, which, invoked as part of a 'wrap' phase, is capable of +wrapping executables inside an environment in which ENV-VAR is correctly set. + +The string ENV-VAR is the name of the environmental variable we are setting +for the executable we are wrapping. PATH-PROC is a procedure of 2 arguments, +'inputs' and 'outputs', returning the value that we should set ENV-VAR to. + +This is a specialized version of 'wrap-program' below, intended specifically +to grant all executables that are part of our output access to all libraries +that were declared in our inputs. This is of use for languages such as Perl, +Python and Guile." + (define (list-of-files dir) + (map (cut string-append dir "/" <>) + (or (scandir dir (lambda (f) + (let ((s (stat (string-append dir "/" f)))) + (eq? 'regular (stat:type s))))) + '()))) + (lambda* (#:key inputs outputs #:allow-other-keys) + (define bindirs + (append-map (match-lambda + ((_ . dir) + (list (string-append dir "/bin") + (string-append dir "/sbin")))) + outputs)) + (define vars + `(,env-var prefix ,(cons (path-proc inputs outputs) + (search-path-as-string->list + (or (getenv env-var) ""))))) + (for-each (lambda (dir) + (let ((files (list-of-files dir))) + (for-each (cut wrap-program <> vars) + files))) + bindirs))) + (define* (wrap-program prog #:rest vars) "Make a wrapper for PROG. VARS should look like this: -- 2.12.2