all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Christopher Baines <mail@cbaines.net>
To: edk@beaver-labs.com
Cc: help-guix@gnu.org
Subject: Re: How to lower a record to the build code ?
Date: Wed, 05 May 2021 19:18:37 +0100	[thread overview]
Message-ID: <87tunhavsy.fsf@cbaines.net> (raw)
In-Reply-To: <87eeelglsm.fsf@rdklein.fr>

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


edk@beaver-labs.com writes:

> I've been stuck for a few days on the following:
> Let's say I have a record type:
>
> (define-record-type* <my-record> my-record make-my-record
>   my-record?
>   this-record
>  (first-field my-record-first-field)
>  (second-field my-record-second-field))
>
> And a function that uses such a record, but needs to run on the build
> side, because it also needs the store path of a package (I can't edit
> this function):
>
> (define (function-of-a-record-and-a-build-time-path rec path)
>   "Concatenate the path, first, and second field"
>   (string-append path " " (my-record-first-field rec) " " (car
>   (my-record-second-field rec)) " " (cdr (my-record-second-field rec))))
>
> How can I use this record in the build side. For example, I'm unable to
> build the following G-exp:
> (define a-record (my-record
>               (first-field "first")
>               (second-field '("second" . "third"))))
>
>
> #~(with-output-to-file (string-append #$output "/file.txt")
>      (lambda _
>        (display (function-of-a-record-and-a-build-time-path #$a-record
>      #$bash)))))

Could you ungexp the record access bits? So something like:

  (string-append #$path " " #$(my-record-first-field rec) " " #$(car
    (my-record-second-field rec)) " " #$(cdr (my-record-second-field
    rec)))

Obviously, then the handling of rec would just be on the build side.

I'm not quite sure quite what your code looks like, in the example you
give, you've got a number of problems.

Ignoring the #$a-record, you'll need to (mkdir #$output) before trying
to write to a file within that directory.

Secondly, function-of-a-record-and-a-build-time-path isn't defined on
the build side.

If you want to define function-of-a-record-and-a-build-time-path on the
host side, then you could have it return a gexp, something like:

  (define (function-of-a-record-and-a-build-time-path rec path)
    "Concatenate the path, first, and second field"
    #~(string-append #$path " " #$(my-record-first-field rec) " " #$(car (my-record-second-field rec)) " " #$(cdr (my-record-second-field rec))))

  (build-gexp
   #~(begin
       (mkdir #$output)
       (with-output-to-file (string-append #$output "/file.txt")
         (lambda _
           (display #$(function-of-a-record-and-a-build-time-path  a-record bash))))))

With these changes, the example you give works for me.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 987 bytes --]

  reply	other threads:[~2021-05-05 18:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-05 16:58 How to lower a record to the build code ? edk
2021-05-05 18:18 ` Christopher Baines [this message]
2021-05-07 16:21   ` Edouard Klein

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

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

  git send-email \
    --in-reply-to=87tunhavsy.fsf@cbaines.net \
    --to=mail@cbaines.net \
    --cc=edk@beaver-labs.com \
    --cc=help-guix@gnu.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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.