diff options
| author | Maxime Devos <maximedevos@telenet.be> | 2021-05-31 18:36:09 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2021-06-04 22:34:26 +0200 |
| commit | 5378edeab4e90f9dec6ae9bc5706a4ac790294b7 (patch) | |
| tree | baed37d75161af23a14feb08c54403c7e8fc77cb /tests/build-utils.scm | |
| parent | 8b0899963faa3b04ed09192ac58db0a711c6a654 (diff) | |
utils: Define ‘search-input-file’ procedure.
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: <https://issues.guix.gnu.org/47869>
Co-Authored-By: Ludovic Courtès <ludo@gnu.org>
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'tests/build-utils.scm')
| -rw-r--r-- | tests/build-utils.scm | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/build-utils.scm b/tests/build-utils.scm index 31be7ff80f7..6b131c0af85 100644 --- a/tests/build-utils.scm +++ b/tests/build-utils.scm | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | ;;; Copyright © 2012, 2015, 2016, 2019, 2020 Ludovic Courtès <ludo@gnu.org> | 2 | ;;; Copyright © 2012, 2015, 2016, 2019, 2020 Ludovic Courtès <ludo@gnu.org> |
| 3 | ;;; Copyright © 2019 Ricardo Wurmus <rekado@elephly.net> | 3 | ;;; Copyright © 2019 Ricardo Wurmus <rekado@elephly.net> |
| 4 | ;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com> | 4 | ;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com> |
| 5 | ;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be> | ||
| 5 | ;;; | 6 | ;;; |
| 6 | ;;; This file is part of GNU Guix. | 7 | ;;; This file is part of GNU Guix. |
| 7 | ;;; | 8 | ;;; |
| @@ -263,4 +264,28 @@ print('hello world')")) | |||
| 263 | (lambda _ | 264 | (lambda _ |
| 264 | (get-string-all (current-input-port)))))))) | 265 | (get-string-all (current-input-port)))))))) |
| 265 | 266 | ||
| 267 | (test-equal "search-input-file: exception if not found" | ||
| 268 | `((path) | ||
| 269 | (file . "does-not-exist")) | ||
| 270 | (guard (e ((search-error? e) | ||
| 271 | `((path . ,(search-error-path e)) | ||
| 272 | (file . ,(search-error-file e))))) | ||
| 273 | (search-input-file '() "does-not-exist"))) | ||
| 274 | |||
| 275 | (test-equal "search-input-file: can find if existent" | ||
| 276 | (which "guile") | ||
| 277 | (search-input-file | ||
| 278 | `(("guile/bin" . ,(dirname (which "guile")))) | ||
| 279 | "guile")) | ||
| 280 | |||
| 281 | (test-equal "search-input-file: can search in multiple directories" | ||
| 282 | (which "guile") | ||
| 283 | (call-with-temporary-directory | ||
| 284 | (lambda (directory) | ||
| 285 | (search-input-file | ||
| 286 | `(("irrelevant" . ,directory) | ||
| 287 | ("guile/bin" . ,(dirname (which "guile")))) | ||
| 288 | "guile")))) | ||
| 289 | |||
| 290 | |||
| 266 | (test-end) | 291 | (test-end) |
