From 5378edeab4e90f9dec6ae9bc5706a4ac790294b7 Mon Sep 17 00:00:00 2001 From: Maxime Devos Date: Mon, 31 May 2021 18:36:09 +0200 Subject: utils: Define ‘search-input-file’ procedure. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The procedure ‘which’ from (guix build utils) is used for two different purposes: 1. for finding the absolute file name of a binary that needs 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 (target=#f in Guix parlance), this is perfectly fine. However, when cross-compiling, there is 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. This commit defines a ‘search-input-file’ procedure. It functions like 'which', but instead of searching in $PATH, it searches in the 'inputs' of the build phase, which must be passed to ‘search-input-file’ as an argument. Also, the file name must include "bin/" or "sbin/" as appropriate. * guix/build/utils.scm (search-input-file): New procedure. * tests/build-utils.scm ("search-input-file: exception if not found") ("search-input-file: can find if existent"): Test it. * doc/guix.texi (File Search): Document it. Partially-Fixes: Co-Authored-By: Ludovic Courtès Signed-off-by: Ludovic Courtès --- doc/guix.texi | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'doc') diff --git a/doc/guix.texi b/doc/guix.texi index 535e7614fd..3557c977e1 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -8661,6 +8661,26 @@ Return the complete file name for @var{program} as found in @code{$PATH}, or @code{#f} if @var{program} could not be found. @end deffn +@deffn {Scheme Procedure} search-input-file @var{inputs} @var{name} +Return the complete file name for @var{name} as found in @var{inputs}. +If @var{name} could not be found, an exception is raised instead. +Here, @var{inputs} is an association list like @var{inputs} and +@var{native-inputs} as available to build phases. +@end deffn + +Here is a (simplified) example of how @code{search-input-file} is used +in a build phase of the @code{wireguard-tools} package: + +@lisp +(add-after 'install 'wrap-wg-quick + (lambda* (#:key inputs outputs #:allow-other-keys) + (let ((coreutils (string-append (assoc-ref inputs "coreutils") + "/bin"))) + (wrap-program (search-input-file outputs "bin/wg-quick") + #:sh (search-input-file inputs "bin/bash") + `("PATH" ":" prefix ,(list coreutils)))))) +@end lisp + @subsection Build Phases @cindex build phases -- cgit v1.2.3