unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Liliana Marie Prikler <liliana.prikler@gmail.com>
To: "(" <paren@disroot.org>, guix-devel@gnu.org
Subject: Re: Proposal for search-input-file
Date: Tue, 15 Aug 2023 11:49:44 +0200	[thread overview]
Message-ID: <cd9e15c0fd858a759a06184c120a5cc22336a4b2.camel@gmail.com> (raw)
In-Reply-To: <875y5n3rgk.fsf@disroot.org>

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	other threads:[~2023-08-15  9:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-10 13:28 Proposal for search-input-file (
2023-08-15  9:49 ` Liliana Marie Prikler [this message]
2023-08-15 16:53   ` (
2023-08-16 14:49   ` Ludovic Courtès
2023-08-16 15:50     ` Liliana Marie Prikler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cd9e15c0fd858a759a06184c120a5cc22336a4b2.camel@gmail.com \
    --to=liliana.prikler@gmail.com \
    --cc=guix-devel@gnu.org \
    --cc=paren@disroot.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).