* (guix modules) and ‘source-module-closure’
@ 2016-09-04 22:24 Ludovic Courtès
2016-09-05 8:13 ` Ricardo Wurmus
0 siblings, 1 reply; 4+ messages in thread
From: Ludovic Courtès @ 2016-09-04 22:24 UTC (permalink / raw)
To: guix-devel
Hi!
Commit 7ca87354db53fd1e1a7a3dfeddb9a598ea064bbe adds (guix module),
which provides a way to compute the closure of a Scheme module by
looking at its source code.
This has to do with typical ‘with-imported-modules’ usage, as explained
in the manual:
--8<---------------cut here---------------start------------->8---
Usually you want the _closure_ of the module to be imported—i.e., the
module itself and all the modules it depends on—rather than just the
module; failing to do that, attempts to use the module will fail because
of missing dependent modules. The ‘source-module-closure’ procedure
computes the closure of a module by looking at its source file headers,
which comes in handy in this case:
(use-modules (guix modules)) ;for 'source-module-closure'
(with-imported-modules (source-module-closure
'((guix build utils)
(gnu build vm)))
(gexp->derivation "something-with-vms"
#~(begin
(use-modules (guix build utils)
(gnu build vm))
...)))
--8<---------------cut here---------------end--------------->8---
The benefit can be seen in the next commit:
http://git.savannah.gnu.org/cgit/guix.git/commit/?id=239c6e276214813f59f761c9dc5cc0e9d266b49b
Comments welcome!
Ludo’.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: (guix modules) and ‘source-module-closure’
2016-09-04 22:24 (guix modules) and ‘source-module-closure’ Ludovic Courtès
@ 2016-09-05 8:13 ` Ricardo Wurmus
2016-09-05 10:05 ` Andy Wingo
0 siblings, 1 reply; 4+ messages in thread
From: Ricardo Wurmus @ 2016-09-05 8:13 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: guix-devel
Ludovic Courtès <ludo@gnu.org> writes:
> Hi!
>
> Commit 7ca87354db53fd1e1a7a3dfeddb9a598ea064bbe adds (guix module),
> which provides a way to compute the closure of a Scheme module by
> looking at its source code.
>
> This has to do with typical ‘with-imported-modules’ usage, as explained
> in the manual:
>
> --8<---------------cut here---------------start------------->8---
> Usually you want the _closure_ of the module to be imported—i.e., the
> module itself and all the modules it depends on—rather than just the
> module; failing to do that, attempts to use the module will fail because
> of missing dependent modules. The ‘source-module-closure’ procedure
> computes the closure of a module by looking at its source file headers,
> which comes in handy in this case:
>
> (use-modules (guix modules)) ;for 'source-module-closure'
>
> (with-imported-modules (source-module-closure
> '((guix build utils)
> (gnu build vm)))
> (gexp->derivation "something-with-vms"
> #~(begin
> (use-modules (guix build utils)
> (gnu build vm))
> ...)))
> --8<---------------cut here---------------end--------------->8---
>
> The benefit can be seen in the next commit:
>
> http://git.savannah.gnu.org/cgit/guix.git/commit/?id=239c6e276214813f59f761c9dc5cc0e9d266b49b
Ah, very nice!
Why is it necessary to read the file and parse the define-module
expression? Does Guile not keep any of this information? Should it?
Will something like this become part of Guile eventually?
~~ Ricardo
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: (guix modules) and ‘source-module-closure’
2016-09-05 8:13 ` Ricardo Wurmus
@ 2016-09-05 10:05 ` Andy Wingo
2016-09-05 21:24 ` Ludovic Courtès
0 siblings, 1 reply; 4+ messages in thread
From: Andy Wingo @ 2016-09-05 10:05 UTC (permalink / raw)
To: Ricardo Wurmus; +Cc: guix-devel
On Mon 05 Sep 2016 10:13, Ricardo Wurmus <ricardo.wurmus@mdc-berlin.de> writes:
> Ah, very nice!
>
> Why is it necessary to read the file and parse the define-module
> expression? Does Guile not keep any of this information? Should it?
> Will something like this become part of Guile eventually?
If you have the module loaded, there is "live-module-closure" which uses
the information Guile has at run-time. I guess Ludovic wanted to get
this information without loading the module, for some reason :)
Andy
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: (guix modules) and ‘source-module-closure’
2016-09-05 10:05 ` Andy Wingo
@ 2016-09-05 21:24 ` Ludovic Courtès
0 siblings, 0 replies; 4+ messages in thread
From: Ludovic Courtès @ 2016-09-05 21:24 UTC (permalink / raw)
To: Andy Wingo; +Cc: guix-devel
Andy Wingo <wingo@igalia.com> skribis:
> On Mon 05 Sep 2016 10:13, Ricardo Wurmus <ricardo.wurmus@mdc-berlin.de> writes:
>
>> Ah, very nice!
>>
>> Why is it necessary to read the file and parse the define-module
>> expression? Does Guile not keep any of this information? Should it?
>> Will something like this become part of Guile eventually?
>
> If you have the module loaded, there is "live-module-closure" which uses
> the information Guile has at run-time. I guess Ludovic wanted to get
> this information without loading the module, for some reason :)
Exactly. Most of the time “build-side” module are not loaded in the
Guile process that uses ‘with-imported-modules’.
It’s a bit of hack but it’s necessary. Guile could provide this
functionality, but (guix modules) bakes in a few assumptions, notably
that all the source files start with ‘define-module’.
Ludo’.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-09-05 21:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-04 22:24 (guix modules) and ‘source-module-closure’ Ludovic Courtès
2016-09-05 8:13 ` Ricardo Wurmus
2016-09-05 10:05 ` Andy Wingo
2016-09-05 21:24 ` 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).