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 --- guix/build/utils.scm | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'guix') diff --git a/guix/build/utils.scm b/guix/build/utils.scm index c6731b37ae..2636da392f 100644 --- a/guix/build/utils.scm +++ b/guix/build/utils.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès +;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès ;;; Copyright © 2013 Andreas Enge ;;; Copyright © 2013 Nikita Karetnikov ;;; Copyright © 2015, 2018, 2021 Mark H Weaver @@ -80,6 +80,10 @@ (define-module (guix build utils) search-path-as-string->list list->search-path-as-string which + search-input-file + search-error? + search-error-path + search-error-file every* alist-cons-before @@ -614,6 +618,21 @@ (define (which program) (search-path (search-path-as-string->list (getenv "PATH")) program)) +(define-condition-type &search-error &error + search-error? + (path search-error-path) + (file search-error-file)) + +(define (search-input-file inputs file) + "Find a file named FILE among the INPUTS and return its absolute file name. + +FILE must be a string like \"bin/sh\". If FILE is not found, an exception is +raised." + (match inputs + (((_ . directories) ...) + (or (search-path directories file) + (raise (condition (&search-error (path directories) (file file)))))))) + ;;; ;;; Phases. -- cgit v1.2.3