unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* packages: [PoC] Expand range of objects 'add-input-label' can label
@ 2022-01-17 10:01 elaexuotee
  2022-01-18 15:32 ` Ludovic Courtès
  0 siblings, 1 reply; 2+ messages in thread
From: elaexuotee @ 2022-01-17 10:01 UTC (permalink / raw)
  To: guix-devel

[-- Attachment #1: Type: text/plain, Size: 1891 bytes --]

Hey Guix!

This is me grubbing around with internals I know nothing about. Here is a quick
and dirty proof-of-concept patch that extends 'add-input-label' to use the
'name' property of plain-file, program-file, etc.

In addition, it also labels auxiliary files, using the same path string one
provides to search-auxiliary-file. This part is the dirtiest, especially since
we cannot make use of %auxiliary-files-path from (gnu packages) since that
would introduce a circular dependency.

The motivation for this arose while recently munging a package to use new-style
inputs. The package's inputs include an auxiliary file and custom program-file
gexp; however, with new-style inputs there is no obvious way to get get access
to these input paths within the build phases:

- Both get the default "_" label; and
- search-input-file only finds files inside store path *directories*.

There potentially a workaround using file-union, but it's clearly friction.

Naive package-writing me wanted one of two things:

1) Ability to mix old, explicit labels with the new labelless inputs, or
2) Labels that come from the gexp name.

The first option is much more general, but somehow I stumbled across the
add-input-label procedure, so went with 2.

What are your thoughts?

Clear unknows to me:

- Is add-input-label in a fast path? This patch significantly increases the
  cases supplied to 'match', which feels like it has the potential to hit
  performance in a bad way.

- Using the 'name' property is kind of obvious, but add-input-label looks
  deliberatly small. Was using 'name' intentionally avoided for some reason?

- Are there other implicit concerns/constraints within guix/packages.scm that I
  am oblivious to?

- etc?

Anyway, by no means do I expect this to get merged, mostly just hoping to learn
something.

Cheers,
B. Wilson



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-packages-Expand-range-of-objects-add-input-label-can.patch --]
[-- Type: text/x-patch, Size: 2711 bytes --]

From 3b8e7fa8fbd58e7e164e3730c708419f612b8549 Mon Sep 17 00:00:00 2001
From: "B. Wilson" <elaexuotee@wilsonb.com>
Date: Sun, 16 Jan 2022 23:54:51 +0900
Subject: [PATCH 1/2] packages: Expand range of objects 'add-input-label' can
 label
To: guix-patches@gnu.org

* guix/packages.scm (%auxiliary-files-subpath-dir): New variable.
(add-input-label): Support labels from the name property of
objects that have one.  Also, name auxiliary files from their
subpath.
---
 guix/packages.scm | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/guix/packages.scm b/guix/packages.scm
index 9d5b23eb8a..4feea8ad5f 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -7,6 +7,7 @@
 ;;; Copyright © 2019 Marius Bakke <mbakke@fastmail.com>
 ;;; Copyright © 2020, 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;; Copyright © 2021 Chris Marusich <cmmarusich@gmail.com>
+;;; Copyright © 2022 B. Wilson <elaexuotee@wilsonb.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -569,6 +570,10 @@ (define-record-type* <package>
                        (default (current-definition-location))
                        (innate)))
 
+;; Note: This morally imports from gnu/packages.scm, but since they import us,
+;; we define here instead.
+(define %auxiliary-files-subdir-path "/gnu/packages/aux-files")
+
 (define (add-input-label input)
   "Add an input label to INPUT."
   (match input
@@ -576,7 +581,24 @@ (define (add-input-label input)
      (list (package-name package) package))
     (((? package? package) output)                ;XXX: ugly?
      (list (package-name package) package output))
-    ((? gexp-input?)       ;XXX: misplaced because 'native?' field is ignored?
+    ((? local-file? local-file)
+     (list (local-file-name local-file) local-file))
+    ((? plain-file? plain-file)
+     (list (plain-file-name plain-file) plain-file))
+    ((? computed-file? computed-file)
+     (list (computed-file-name computed-file) computed-file))
+    ((? program-file? program-file)
+     (list (program-file-name program-file) program-file))
+    ((? scheme-file? scheme-file)
+     (list (scheme-file-name scheme-file) scheme-file))
+    ((? string? path)
+     (let* ((regex (string-append %auxiliary-files-subdir-path "/(.*)"))
+            (match (string-match regex input)))
+       `(,(if match
+               (match:substring match 1)
+               "_")
+          ,input)))
+    ((? gexp-input?)      ;XXX: misplaced because 'native?' field is ignored?
      (let ((obj    (gexp-input-thing input))
            (output (gexp-input-output input)))
        `(,(if (package? obj)
-- 
2.34.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: packages: [PoC] Expand range of objects 'add-input-label' can label
  2022-01-17 10:01 packages: [PoC] Expand range of objects 'add-input-label' can label elaexuotee
@ 2022-01-18 15:32 ` Ludovic Courtès
  0 siblings, 0 replies; 2+ messages in thread
From: Ludovic Courtès @ 2022-01-18 15:32 UTC (permalink / raw)
  To: elaexuotee; +Cc: guix-devel

Hi,

elaexuotee@wilsonb.com skribis:

> From 3b8e7fa8fbd58e7e164e3730c708419f612b8549 Mon Sep 17 00:00:00 2001
> From: "B. Wilson" <elaexuotee@wilsonb.com>
> Date: Sun, 16 Jan 2022 23:54:51 +0900
> Subject: [PATCH 1/2] packages: Expand range of objects 'add-input-label' can
>  label
> To: guix-patches@gnu.org
>
> * guix/packages.scm (%auxiliary-files-subpath-dir): New variable.
> (add-input-label): Support labels from the name property of
> objects that have one.  Also, name auxiliary files from their
> subpath.

[...]

>  (define (add-input-label input)
>    "Add an input label to INPUT."
>    (match input
> @@ -576,7 +581,24 @@ (define (add-input-label input)
>       (list (package-name package) package))
>      (((? package? package) output)                ;XXX: ugly?
>       (list (package-name package) package output))
> -    ((? gexp-input?)       ;XXX: misplaced because 'native?' field is ignored?
> +    ((? local-file? local-file)
> +     (list (local-file-name local-file) local-file))
> +    ((? plain-file? plain-file)
> +     (list (plain-file-name plain-file) plain-file))
> +    ((? computed-file? computed-file)
> +     (list (computed-file-name computed-file) computed-file))
> +    ((? program-file? program-file)
> +     (list (program-file-name program-file) program-file))
> +    ((? scheme-file? scheme-file)
> +     (list (scheme-file-name scheme-file) scheme-file))
> +    ((? string? path)
> +     (let* ((regex (string-append %auxiliary-files-subdir-path "/(.*)"))
> +            (match (string-match regex input)))
> +       `(,(if match
> +               (match:substring match 1)
> +               "_")
> +          ,input)))
> +    ((? gexp-input?)      ;XXX: misplaced because 'native?' field is ignored?

I can see why it’s tempting to add more labels, but the medium-term goal
is to remove labels altogether since there are other mechanisms to fill
the same role:

  https://guix.gnu.org/en/blog/2021/the-big-change/

I would keep things as they are and instead encourage you to use gexps
when you need to refer to file-like objects in packages.

We’re still fine-tuning the idioms, so feel free to ask if you don’t see
how to achieve what you want.

HTH!

Ludo’.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-18 16:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-17 10:01 packages: [PoC] Expand range of objects 'add-input-label' can label elaexuotee
2022-01-18 15:32 ` Ludovic Courtès

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).