all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [go-build-system] How to access properties or keys of a package on the build side?
@ 2017-08-28 18:51 Leo Famulari
  2017-08-28 19:15 ` Ricardo Wurmus
  0 siblings, 1 reply; 7+ messages in thread
From: Leo Famulari @ 2017-08-28 18:51 UTC (permalink / raw)
  To: guix-devel

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

Recently I made some progress on finishing the prototype go-build-system
from Petter [0], and I need some advice.

AFAICT, building a Go program requires the program's Go dependencies to
have a particular filesystem layout, which corresponds to the way these
dependencies are imported by the program's code.

So, a Go build system needs to somehow create a symlink union of the
dependency graph, making the dependencies available at the correct paths
relative to the root of the build environment. AFAICT, we can't figure
these paths out programatically; they must be supplied by the packager
in advance, for example:

------
(arguments
  `(#:import-path "github.com/AudriusButkevicius/go-nat-pmp"))
------

Petter's prototype creates the symlink union, but instead of using the
#:import-path key, it instead duplicates the import path while listing a
package's dependencies, like this:

------
(inputs
 `(("github.com/AudriusButkevicius/go-nat-pmp"
    ,golang-github-com-audriusbutkevicius-go-nat-pmp)
------

... putting the import path in the car of the input, and using it as shown
below:

------
(define* (symlinking #:key inputs #:allow-other-keys)
  (for-each (lambda (input)
              (let ((import-path (car input))
                    (storepath (cdr input)))
                ; Don't deal with the compiler or source inputs
                (if (and (not (string=? import-path "go"))
                         (not (string=? import-path "source")))
                    (begin
                      (mkdir-p (string-append
                                "src/"
                                (string-take import-path
                                             (string-rindex import-path #\/))))
                      (let ((from (string-append storepath "/src/" import-path))
                            (to (string-append "src/" import-path)))
                        (if (file-exists? to) (delete-file-recursively to))
                        (symlink (string-append
                                  storepath "/src/" import-path)
                                 (string-append
                                  "src/" import-path)))))))
            inputs))
------

Are there any examples in the code base of accessing the inputs' keys? That
seems like a better solution to me, but I'm not sure how to achieve it.

[0]
https://lists.gnu.org/archive/html/guix-devel/2016-12/msg00399.html

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

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

* Re: [go-build-system] How to access properties or keys of a package on the build side?
  2017-08-28 18:51 [go-build-system] How to access properties or keys of a package on the build side? Leo Famulari
@ 2017-08-28 19:15 ` Ricardo Wurmus
  2017-08-28 20:32   ` Ricardo Wurmus
  0 siblings, 1 reply; 7+ messages in thread
From: Ricardo Wurmus @ 2017-08-28 19:15 UTC (permalink / raw)
  To: Leo Famulari; +Cc: guix-devel


Leo Famulari <leo@famulari.name> writes:

> So, a Go build system needs to somehow create a symlink union of the
> dependency graph, making the dependencies available at the correct paths
> relative to the root of the build environment. AFAICT, we can't figure
> these paths out programatically; they must be supplied by the packager
> in advance, for example:
>
> ------
> (arguments
>   `(#:import-path "github.com/AudriusButkevicius/go-nat-pmp"))
> ------
>
> Petter's prototype creates the symlink union, but instead of using the
> #:import-path key, it instead duplicates the import path while listing a
> package's dependencies, like this:
>
> ------
> (inputs
>  `(("github.com/AudriusButkevicius/go-nat-pmp"
>     ,golang-github-com-audriusbutkevicius-go-nat-pmp)
> ------
[…]
>
> Are there any examples in the code base of accessing the inputs' keys? That
> seems like a better solution to me, but I'm not sure how to achieve it.

Instead of recording this information in the input labels (which I
consider rather inelegant) you could put the key in the properties
field.  In the build phase of another package you can access it like
this:

   (arguments
     `(#:phases …
       (lambda _
         …
         ,(assoc-ref (package-properties the-package) 'the-key)
         …
         )…))

You could also access the arguments of another package with
“package-arguments”.  Using the “properties” field isn’t pretty because
it is a free form alist.

You can use “find-tail” to jump to the keyword in “arguments” and then
pick the following value.

--
Ricardo

GPG: BCA6 89B6 3655 3801 C3C6  2150 197A 5888 235F ACAC
https://elephly.net

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

* Re: [go-build-system] How to access properties or keys of a package on the build side?
  2017-08-28 19:15 ` Ricardo Wurmus
@ 2017-08-28 20:32   ` Ricardo Wurmus
  2017-08-31  1:01     ` Leo Famulari
  2017-09-01 17:15     ` Leo Famulari
  0 siblings, 2 replies; 7+ messages in thread
From: Ricardo Wurmus @ 2017-08-28 20:32 UTC (permalink / raw)
  To: Leo Famulari; +Cc: guix-devel


Ricardo Wurmus <rekado@elephly.net> writes:

> You could also access the arguments of another package with
> “package-arguments”.  Using the “properties” field isn’t pretty because
> it is a free form alist.
>
> You can use “find-tail” to jump to the keyword in “arguments” and then
> pick the following value.

Here an example:

--8<---------------cut here---------------start------------->8---
(define (assoc-args-ref pkg key)
  "Return the value associated with KEY in the arguments of package PKG,
or #F if there is no such key."
  (let ((ref (find-tail (cut eq? <> key)
                        (package-arguments pkg))))
    (and=> ref second)))

(assoc-args-ref golang-github-com-audriusbutkevicius-go-nat-pmp
                #:import-path)

=> "github.com/AudriusButkevicius/go-nat-pmp"
--8<---------------cut here---------------end--------------->8---


-- 
Ricardo

GPG: BCA6 89B6 3655 3801 C3C6  2150 197A 5888 235F ACAC
https://elephly.net

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

* [go-build-system] How to access properties or keys of a package on the build side?
@ 2017-08-29 12:54 Frederick Muriithi
  0 siblings, 0 replies; 7+ messages in thread
From: Frederick Muriithi @ 2017-08-29 12:54 UTC (permalink / raw)
  To: guix-devel

Maybe the following will help clarify the issue:

The package being built needs the sources of the dependenc(y/ies) to
be available in its GOPATH.

The build system needs to set the GOPATH such that the Go build system
will find the the dependencies and build against them.

I have a repository[1] where I'm currently working on definitions for
IPFS before translating them for mainline guix.
If you checkout commit f7f97edc635381384c3532eb8a2bd92cf10a5ac9 and
look at the code there, you can see that I manually set up GOPATH in
the build of go-log so that it can find go-logging (the modified
version[2]).

Now, when building, you need to lay out the code such that go is able
to find everything, and in my code, I do that manually in the
"setup-go-workspace" phase.

I hope this will help clarify issues a bit.

[1] (https://github.com/fredmanglis/guix-ipfs)
[1] (https://github.com/whyrusleeping/go-logging)

-- 
Frederick M. Muriithi

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

* Re: [go-build-system] How to access properties or keys of a package on the build side?
  2017-08-28 20:32   ` Ricardo Wurmus
@ 2017-08-31  1:01     ` Leo Famulari
  2017-09-01 17:15     ` Leo Famulari
  1 sibling, 0 replies; 7+ messages in thread
From: Leo Famulari @ 2017-08-31  1:01 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

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

On Mon, Aug 28, 2017 at 10:32:41PM +0200, Ricardo Wurmus wrote:
> 
> Ricardo Wurmus <rekado@elephly.net> writes:
> 
> > You could also access the arguments of another package with
> > “package-arguments”.  Using the “properties” field isn’t pretty because
> > it is a free form alist.
> >
> > You can use “find-tail” to jump to the keyword in “arguments” and then
> > pick the following value.
> 
> Here an example:
> 
> --8<---------------cut here---------------start------------->8---
> (define (assoc-args-ref pkg key)
>   "Return the value associated with KEY in the arguments of package PKG,
> or #F if there is no such key."
>   (let ((ref (find-tail (cut eq? <> key)
>                         (package-arguments pkg))))
>     (and=> ref second)))
> 
> (assoc-args-ref golang-github-com-audriusbutkevicius-go-nat-pmp
>                 #:import-path)
> 
> => "github.com/AudriusButkevicius/go-nat-pmp"
> --8<---------------cut here---------------end--------------->8---

Thanks, this is a nice example.

I realized that the GOPATH variable can be a list of directories, like
PATH, so I'm working in that direction instead of building the symlink
union.

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

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

* Re: [go-build-system] How to access properties or keys of a package on the build side?
  2017-08-28 20:32   ` Ricardo Wurmus
  2017-08-31  1:01     ` Leo Famulari
@ 2017-09-01 17:15     ` Leo Famulari
  2017-09-01 20:58       ` Ricardo Wurmus
  1 sibling, 1 reply; 7+ messages in thread
From: Leo Famulari @ 2017-09-01 17:15 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

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

On Mon, Aug 28, 2017 at 10:32:41PM +0200, Ricardo Wurmus wrote:
> 
> Ricardo Wurmus <rekado@elephly.net> writes:
> 
> > You could also access the arguments of another package with
> > “package-arguments”.  Using the “properties” field isn’t pretty because
> > it is a free form alist.
> >
> > You can use “find-tail” to jump to the keyword in “arguments” and then
> > pick the following value.
> 
> Here an example:
> 
> --8<---------------cut here---------------start------------->8---
> (define (assoc-args-ref pkg key)
>   "Return the value associated with KEY in the arguments of package PKG,
> or #F if there is no such key."
>   (let ((ref (find-tail (cut eq? <> key)
>                         (package-arguments pkg))))
>     (and=> ref second)))
> 
> (assoc-args-ref golang-github-com-audriusbutkevicius-go-nat-pmp
>                 #:import-path)
> 
> => "github.com/AudriusButkevicius/go-nat-pmp"
> --8<---------------cut here---------------end--------------->8---

I didn't get very far in this direction before deciding to try another
technique. But wouldn't this not work on the build side, since (guix
packages) is not available there?

I considered building an alist of store items and "import paths" and
passing that into the build from the host side, but it started to feel
like the wrong approach.

Instead my latest approach [0] is to "record" the packages' import paths
via their store items' filesystem layouts.

[0]
https://lists.gnu.org/archive/html/guix-devel/2017-08/msg00323.html

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

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

* Re: [go-build-system] How to access properties or keys of a package on the build side?
  2017-09-01 17:15     ` Leo Famulari
@ 2017-09-01 20:58       ` Ricardo Wurmus
  0 siblings, 0 replies; 7+ messages in thread
From: Ricardo Wurmus @ 2017-09-01 20:58 UTC (permalink / raw)
  To: Leo Famulari; +Cc: guix-devel


Leo Famulari <leo@famulari.name> writes:

> On Mon, Aug 28, 2017 at 10:32:41PM +0200, Ricardo Wurmus wrote:
>>
>> Ricardo Wurmus <rekado@elephly.net> writes:
>>
>> > You could also access the arguments of another package with
>> > “package-arguments”.  Using the “properties” field isn’t pretty because
>> > it is a free form alist.
>> >
>> > You can use “find-tail” to jump to the keyword in “arguments” and then
>> > pick the following value.
>>
>> Here an example:
>>
>> --8<---------------cut here---------------start------------->8---
>> (define (assoc-args-ref pkg key)
>>   "Return the value associated with KEY in the arguments of package PKG,
>> or #F if there is no such key."
>>   (let ((ref (find-tail (cut eq? <> key)
>>                         (package-arguments pkg))))
>>     (and=> ref second)))
>>
>> (assoc-args-ref golang-github-com-audriusbutkevicius-go-nat-pmp
>>                 #:import-path)
>>
>> => "github.com/AudriusButkevicius/go-nat-pmp"
>> --8<---------------cut here---------------end--------------->8---
>
> I didn't get very far in this direction before deciding to try another
> technique. But wouldn't this not work on the build side, since (guix
> packages) is not available there?

It would work because you’re executing this on the host side and paste
the result into the S-expression that is the value of the “arguments”
field.

--
Ricardo

GPG: BCA6 89B6 3655 3801 C3C6  2150 197A 5888 235F ACAC
https://elephly.net

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

end of thread, other threads:[~2017-09-01 20:58 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-28 18:51 [go-build-system] How to access properties or keys of a package on the build side? Leo Famulari
2017-08-28 19:15 ` Ricardo Wurmus
2017-08-28 20:32   ` Ricardo Wurmus
2017-08-31  1:01     ` Leo Famulari
2017-09-01 17:15     ` Leo Famulari
2017-09-01 20:58       ` Ricardo Wurmus
  -- strict thread matches above, loose matches on Subject: below --
2017-08-29 12:54 Frederick Muriithi

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.