guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Proposal for search-input-file


From: Liliana Marie Prikler
Subject: Re: Proposal for search-input-file
Date: Tue, 15 Aug 2023 11:49:44 +0200
User-agent: Evolution 3.46.4

Hi (,

Am Donnerstag, dem 10.08.2023 um 14:28 +0100 schrieb (:
> 
> Hello Guix,
> 
> While the nicest way to search for files or directories in Guix build
> phases is SEARCH-INPUT-FILE or SEARCH-INPUT-DIRECTORY:
> 
>   (search-input-file inputs "bin/foobarbaz")
>   (search-input-directory inputs "share/foobarbaz-state")
> 
> there are many situations where you need to either wrap it up in an
> ugly way or just use #$(this-package-input) instead:
> 
>   (dirname (search-input-file inputs "lib/libfoobarbaz.so"))
>   (string-append #$(this-package-input "foobarbaz") "lib")
> 
> To make this common case less annoying, while further improving other
> aspects of the usability of SEARCH-INPUT-* in general, we could add
> keyword arguments to the SEARCH-INPUT procedures, and possibly merge
> them into one:
> 
>   ;; old
>   (search-input-file INPUTS-ALIST PATH)
>   (search-input-directory INPUTS-ALIST PATH)
> 
>   ;; new
>   (find-in-inputs INPUTS-ALIST PATH-OR-PATHS [PREDICATE?]
>                   [#:contents CHILD-PATH-OR-PATHS]
>                   [#:regexp? REGEXP?]
>                   [#:collect? COLLECT?])
> 
>   ;; auxillary (for use with PREDICATE?)
>   (regular-file? PATH/PORT/FD)
>   (directory? PATH/PORT/FD)
>   (symlink? PATH/PORT/FD)
> 
> We could simply add the new functionality to SEARCH-INPUT-* if a new
> procedure is considered undesirable, though that would make the
> PREDICATE? key somewhat less useful.
I think adding new procedures is fine, but you have to keep them
readable.  Your procedure is trying to do too many things at once and
thus losing the simplicity that search-input-file/search-input-
directory has.

Part of what you're trying to achieve is already implemented via search
paths, so I think we can focus on the case where we want to find a
particular file, but strip parts of its name.

I think the most general definition that's still useful is this

(define* (search-input-file* inputs predicate
                             #:key (hint "<unknown>"))
  "Find the first file in INPUTS matching PREDICATE.  The return value
of PREDICATE is returned as-is, so patterns like 
  (search-input-file* inputs
    (lambda (parent)
      (and (file-exists? (string-append parent \"/lib/foobar.so\"))
           (string-append parent \"/lib\"))))
work as expected.

When PREDICATE returns no match, raise a search error using HINT for a
file name."
  (match inputs
    (((_ . directories) ...)
     (or (any predicate directories)
         (raise (condition
                 (&search-error (path directories) 
                                (file hint))))))))

Of course you can then go on to define special cases, e.g. matching
regular expressions or the like.

Cheers



reply via email to

[Prev in Thread] Current Thread [Next in Thread]