From patchwork Sun Apr 18 11:20:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: M X-Patchwork-Id: 28643 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 5D19127BC77; Sun, 18 Apr 2021 13:14:14 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id B7C5027BC79 for ; Sun, 18 Apr 2021 13:14:12 +0100 (BST) Received: from localhost ([::1]:36622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lY6JX-0007mA-Rm for patchwork@mira.cbaines.net; Sun, 18 Apr 2021 08:14:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38538) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lY6JO-0007kz-FR for guix-patches@gnu.org; Sun, 18 Apr 2021 08:14:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:34081) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lY6JO-0002uD-7x for guix-patches@gnu.org; Sun, 18 Apr 2021 08:14:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lY6JO-0006rh-3Z for guix-patches@gnu.org; Sun, 18 Apr 2021 08:14:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#47869] [PATCH core-updates] =?utf-8?b?4oCYd2hpY2jigJk=?= looks in PATH, incorrect when cross-compiling Resent-From: Maxime Devos Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 18 Apr 2021 12:14:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 47869 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 47869@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.161874802826361 (code B ref -1); Sun, 18 Apr 2021 12:14:01 +0000 Received: (at submit) by debbugs.gnu.org; 18 Apr 2021 12:13:48 +0000 Received: from localhost ([127.0.0.1]:45627 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lY6J9-0006r6-SN for submit@debbugs.gnu.org; Sun, 18 Apr 2021 08:13:48 -0400 Received: from lists.gnu.org ([209.51.188.17]:37882) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lY6J8-0006qz-EX for submit@debbugs.gnu.org; Sun, 18 Apr 2021 08:13:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38466) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lY6J8-0007ak-8k for guix-patches@gnu.org; Sun, 18 Apr 2021 08:13:46 -0400 Received: from michel.telenet-ops.be ([2a02:1800:110:4::f00:18]:34698) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lY6J4-0002e5-4V for guix-patches@gnu.org; Sun, 18 Apr 2021 08:13:45 -0400 Received: from butterfly.local ([5.23.206.113]) by michel.telenet-ops.be with bizsmtp id uCDa2400A2TKVvH06CDblm; Sun, 18 Apr 2021 14:13:35 +0200 Message-ID: From: Maxime Devos Date: Sun, 18 Apr 2021 13:20:37 +0200 MIME-Version: 1.0 User-Agent: Evolution 3.34.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telenet.be; s=r21; t=1618748015; bh=tbzNzZxUeOst9MMKj+miH6ytcIL6LS0ulgYEWEe5bj0=; h=Subject:From:To:Date; b=F9FcAZOhzsLIf7vjur89RmCS6258pH6b+ndLE8gttcxBv+U8mhfw7KGo3gy/IniE/ sxSIdtwS3kmqdz1dO/YaEOWyNkWegfjm4h9yUJ7V9vN8BYVvf5n/C+AVAX37+KL3LD zchFJepCphokyqokOt6bApPryukKHQ9WwzKHQ5116wIKDLsoA46nkB+cyKgjazXbt5 Ji6735pGyyV8iNkJ6s8PAkayLha7+nWykgStb90tJqwnraBZM+TWNmVv5eBCTePgfH LIEWlZxDyOGlzcaFRpyXpfkNOTwklnWIsDaQhXpCIAqMHLeZ8ftdRvNZTFgBvQc5OH AVAB7W16u0kkg== Received-SPF: pass client-ip=2a02:1800:110:4::f00:18; envelope-from=maximedevos@telenet.be; helo=michel.telenet-ops.be X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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 The procedure ‘which’ from (guix build utils) is used for two different purposes: 1. for finding the absolute file name of a binary that we need to run during the build process 2. for finding the absolute file name of a binary, for the target system (as in --target=TARGET), e.g. for substituting sh->/gnu/store/.../bin/sh, python->/gnu/store/.../bin/python When compiling natively (SYSTEM=TARGET modulo nix/autotools differences), this is perfectly fine. However, when cross-compiling, we have a problem. "which" looks in $PATH for binaries. That's good for purpose (1), but incorrect for (2), as the $PATH contains binaries from native-inputs instead of inputs. Admittedly, ‘which’ is simply very convenient (although incorrect when cross-compiling), and we don't have the right tool ... until now, that is (see patch)! This patch adds an optional 'inputs' argument. When it is present, 'which' will look in the bin and sbin subdirectories of the directories in the 'inputs' alist. Use it like this: (package [...] (arguments `(#:modules (guix build utils) #:phases (modify-phases %standard-phases (delete 'configure) (delete 'check) (add-after 'install 'wrap (lambda* (#:key outputs inputs #:allow-other-keys) (let ((growpart (string-append (assoc-ref outputs "out") "/bin/growpart"))) (wrap-program growpart `("PATH" ":" prefix (,(dirname (which "sfdisk" inputs)) ,(dirname (which "readlink" inputs))))))))))) (Examples comes from the "cloud-utils" package) The only change is adding adding the 'inputs' argument. Isn't that easy? Alternative methods I've seen: * (string-append (assoc-ref inputs "coreutils") "/bin/readlink") * (let ((coreutils (assoc-ref inputs "coreutils"))) (setenv "PATH" (string-append coreutils "/bin")) [code using (which "readlink")]) * (which "readlink") ; possibly incorrect when cross-compiling I've tested this with "cloud-utils", though admittedly I didn't try to cross-compile yet, and I've placed my adjusted "which" in a separate module to avoid having to rebuild everything. (The attached patch just modifies (guix build utils).) I've written a few tests, which pass. I also documented the new functionality in the manual. Currently incorrect uses of "which" can be fixed in a follow-up patch. Thoughts? Maxime. From 6561c943fa134ca1e2a17e43f8f5498fca9b1560 Mon Sep 17 00:00:00 2001 From: Maxime Devos Date: Sun, 18 Apr 2021 13:15:08 +0200 Subject: [PATCH 2/2] =?UTF-8?q?doc:=20Document=20new=20functionality=20of?= =?UTF-8?q?=20=E2=80=98which=E2=80=99.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * doc/guix.texi (File Search)[which]: Document the optional 'inputs' argument, and give an example on how to use the procedure. --- doc/guix.texi | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 6464fa32cb..365cb13604 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -87,6 +87,7 @@ Copyright @copyright{} 2020 Daniel Brooks@* Copyright @copyright{} 2020 John Soo@* Copyright @copyright{} 2020 Jonathan Brielmaier@* Copyright @copyright{} 2020 Edgar Vincent@* +Copyright @copyright{} 2021 Maxime Devos@* Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or @@ -8598,11 +8599,25 @@ the root of the Guix source tree: @result{} ("./libformat.a" "./libstore.a" @dots{}) @end lisp -@deffn {Scheme Procedure} which @var{program} +@deffn {Scheme Procedure} which @var{program} [@var{inputs}=#false] Return the complete file name for @var{program} as found in -@code{$PATH}, or @code{#f} if @var{program} could not be found. +@code{$PATH}, or @code{#false} if @var{program} could not be found. +If @var{INPUTS} is not @code{#false}, instead look in the +@file{/bin} and @file{/sbin} subdirectories of @var{INPUTS}. +@var{inputs} is an alist; its keys are ignored." @end deffn +Here is an example using the @code{which} procedure in a build phase: + +@lisp +(lambda* (#:key outputs inputs #:allow-other-keys) + (let ((growpart (string-append (assoc-ref outputs "out") + "/bin/growpart"))) + (wrap-program growpart + `("PATH" ":" prefix (,(dirname (which "sfdisk" inputs)) + ,(dirname (which "readlink" inputs))))))) +@end lisp + @subsection Build Phases @cindex build phases -- 2.31.1