diff mbox series

[bug#50960,v2,01/11] packages: Add 'package-development-inputs'.

Message ID 20211011213809.17482-2-ludo@gnu.org
State Accepted
Headers show
Series 'guix shell' strikes again | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Ludovic Courtès Oct. 11, 2021, 9:37 p.m. UTC
* guix/packages.scm (package-development-inputs): New procedure.
* guix/scripts/environment.scm (package-environment-inputs): Use it.
* tests/packages.scm ("package-development-inputs")
("package-development-inputs, cross-compilation"): New tests.
* doc/guix.texi (package Reference): Document it.
---
 doc/guix.texi                | 41 ++++++++++++++++++++++++++++++++++++
 guix/packages.scm            | 10 +++++++++
 guix/scripts/environment.scm |  2 +-
 tests/packages.scm           | 14 ++++++++++++
 4 files changed, 66 insertions(+), 1 deletion(-)

Comments

Simon Tournier Oct. 12, 2021, 6:39 a.m. UTC | #1
Hi Ludo,

On Mon, 11 Oct 2021 at 23:37, Ludovic Courtès <ludo@gnu.org> wrote:
> * guix/packages.scm (package-development-inputs): New procedure.
> * guix/scripts/environment.scm (package-environment-inputs): Use it.
> * tests/packages.scm ("package-development-inputs")
> ("package-development-inputs, cross-compilation"): New tests.
> * doc/guix.texi (package Reference): Document it.

LGTM, except…

>  guix/packages.scm            | 10 +++++++++
>  guix/scripts/environment.scm |  2 +-

[...]

> +(define* (package-development-inputs package
> +                                     #:optional (system (%current-system))
> +                                     #:key target)
> +  "Return the list of inputs required by PACKAGE for development purposes on
> +SYSTEM.  When TARGET is true, return the inputs needed to cross-compile
> +PACKAGE from SYSTEM to TRIPLET, where TRIPLET is a triplet such as
> +\"aarch64-linux-gnu\"."
> +  (bag-transitive-inputs (package->bag package system target)))

[...]

>    ;; Remove non-package inputs such as origin records.
>    (filter-map input->manifest-entry
> -              (bag-transitive-inputs (package->bag package))))
> +              (package-development-inputs package system)))

Why ’system’ is used here?  Why is not simply?

 +              (package-development-inputs package)))

because ’system’ should be not defined, or I do not know where IIUC.


Cheers,
simon
Ludovic Courtès Oct. 12, 2021, 9:54 a.m. UTC | #2
zimoun <zimon.toutoune@gmail.com> skribis:

>> +(define* (package-development-inputs package
>> +                                     #:optional (system (%current-system))
>> +                                     #:key target)
>> +  "Return the list of inputs required by PACKAGE for development purposes on
>> +SYSTEM.  When TARGET is true, return the inputs needed to cross-compile
>> +PACKAGE from SYSTEM to TRIPLET, where TRIPLET is a triplet such as
>> +\"aarch64-linux-gnu\"."
>> +  (bag-transitive-inputs (package->bag package system target)))
>
> [...]
>
>>    ;; Remove non-package inputs such as origin records.
>>    (filter-map input->manifest-entry
>> -              (bag-transitive-inputs (package->bag package))))
>> +              (package-development-inputs package system)))
>
> Why ’system’ is used here?  Why is not simply?
>
>  +              (package-development-inputs package)))
>
> because ’system’ should be not defined, or I do not know where IIUC.

It’s an optional parameter above.

Ludo’.
Simon Tournier Oct. 12, 2021, 11:52 a.m. UTC | #3
On Tue, 12 Oct 2021 at 11:54, Ludovic Courtès <ludo@gnu.org> wrote:
> zimoun <zimon.toutoune@gmail.com> skribis:
>
>>> +(define* (package-development-inputs package
>>> +                                     #:optional (system (%current-system))
>>> +                                     #:key target)
>>> +  "Return the list of inputs required by PACKAGE for development purposes on
>>> +SYSTEM.  When TARGET is true, return the inputs needed to cross-compile
>>> +PACKAGE from SYSTEM to TRIPLET, where TRIPLET is a triplet such as
>>> +\"aarch64-linux-gnu\"."
>>> +  (bag-transitive-inputs (package->bag package system target)))
>>
>> [...]
>>
>>>    ;; Remove non-package inputs such as origin records.
>>>    (filter-map input->manifest-entry
>>> -              (bag-transitive-inputs (package->bag package))))
>>> +              (package-development-inputs package system)))
>>
>> Why ’system’ is used here?  Why is not simply?
>>
>>  +              (package-development-inputs package)))
>>
>> because ’system’ should be not defined, or I do not know where IIUC.
>
> It’s an optional parameter above.

Sorry if I miss, to me, ’system’ is not bounded when calling:

--8<---------------cut here---------------start------------->8---
   ;; Remove non-package inputs such as origin records.
   (filter-map input->manifest-entry
-              (bag-transitive-inputs (package->bag package))))
+              (package-development-inputs package system)))
--8<---------------cut here---------------end--------------->8---

and it seems bounded to something:

    ;;; (#<procedure system (#:optional _)>)”

and I do not know from where this definition comes.

Maybe I misread what optional means.  From my understanding, it means:

    (package-development-inputs foo)

will use ’(%current-system)’ as default.  And it also means that:

    (package-development-inputs foo system)

where ’system’ is bounded to something and from my understanding this
something is not necessary ’(%current-system)’.


Again, sorry if I misread something.

Cheers,
simon
diff mbox series

Patch

diff --git a/doc/guix.texi b/doc/guix.texi
index a72a726b54..49399e792b 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -6847,6 +6847,47 @@  cross-compiling:
 It is an error to refer to @code{this-package} outside a package definition.
 @end deffn
 
+@cindex development inputs, of a package
+@cindex implicit inputs, of a package
+Sometimes you will want to obtain the list of inputs needed to
+@emph{develop} a package---all the inputs that are visible when the
+package is compiled.  This is what the @code{package-development-inputs}
+procedure returns.
+
+@deffn {Scheme Procedure} package-development-inputs @var{package} @
+   [@var{system}] [#:target #f]
+Return the list of inputs required by @var{package} for development
+purposes on @var{system}.  When @var{target} is true, return the inputs
+needed to cross-compile @var{package} from @var{system} to
+@var{triplet}, where @var{triplet} is a triplet such as
+@code{"aarch64-linux-gnu"}.
+
+Note that the result includes both explicit inputs and implicit
+inputs---inputs automatically added by the build system (@pxref{Build
+Systems}).  Let us take the @code{hello} package to illustrate that:
+
+@lisp
+(use-modules (gnu packages base) (guix packages))
+
+hello
+@result{} #<package hello@@2.10 gnu/packages/base.scm:79 7f585d4f6790>
+
+(package-direct-inputs hello)
+@result{} ()
+
+(package-development-inputs hello)
+@result{} (("source" @dots{}) ("tar" #<package tar@@1.32 @dots{}>) @dots{})
+@end lisp
+
+In this example, @code{package-direct-inputs} returns the empty list,
+because @code{hello} has zero explicit dependencies.  Conversely,
+@code{package-development-inputs} includes inputs implicitly added by
+@code{gnu-build-system} that are required to build @code{hello}: tar,
+gzip, GCC, libc, Bash, and more.  To visualize it, @command{guix graph
+hello} would show you explicit inputs, whereas @command{guix graph -t
+bag hello} would include implicit inputs (@pxref{Invoking guix graph}).
+@end deffn
+
 Because packages are regular Scheme objects that capture a complete
 dependency graph and associated build procedures, it is often useful to
 write procedures that take a package and return a modified version
diff --git a/guix/packages.scm b/guix/packages.scm
index 8c3a0b0b7b..43e0130793 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -153,6 +153,7 @@  (define-module (guix packages)
             bag-transitive-host-inputs
             bag-transitive-build-inputs
             bag-transitive-target-inputs
+            package-development-inputs
             package-closure
 
             default-guile
@@ -1070,6 +1071,15 @@  (define (bag-transitive-target-inputs bag)
                  (%current-system (bag-system bag)))
     (transitive-inputs (bag-target-inputs bag))))
 
+(define* (package-development-inputs package
+                                     #:optional (system (%current-system))
+                                     #:key target)
+  "Return the list of inputs required by PACKAGE for development purposes on
+SYSTEM.  When TARGET is true, return the inputs needed to cross-compile
+PACKAGE from SYSTEM to TRIPLET, where TRIPLET is a triplet such as
+\"aarch64-linux-gnu\"."
+  (bag-transitive-inputs (package->bag package system target)))
+
 (define* (package-closure packages #:key (system (%current-system)))
   "Return the closure of PACKAGES on SYSTEM--i.e., PACKAGES and the list of
 packages they depend on, recursively."
diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm
index 6958bd6238..d555969b27 100644
--- a/guix/scripts/environment.scm
+++ b/guix/scripts/environment.scm
@@ -82,7 +82,7 @@  (define (package-environment-inputs package)
 packages for PACKAGE."
   ;; Remove non-package inputs such as origin records.
   (filter-map input->manifest-entry
-              (bag-transitive-inputs (package->bag package))))
+              (package-development-inputs package system)))
 
 (define (show-help)
   (display (G_ "Usage: guix environment [OPTION]... PACKAGE... [-- COMMAND...]
diff --git a/tests/packages.scm b/tests/packages.scm
index 3756877270..266b5aeb7a 100644
--- a/tests/packages.scm
+++ b/tests/packages.scm
@@ -353,6 +353,20 @@  (define read-at
           (package-transitive-supported-systems d)
           (package-transitive-supported-systems e))))
 
+(test-assert "package-development-inputs"
+  ;; Note: Due to propagated inputs, 'package-development-inputs' returns a
+  ;; couple more inputs, such as 'linux-libre-headers'.
+  (lset<= equal?
+          `(("source" ,(package-source hello)) ,@(standard-packages))
+          (package-development-inputs hello)))
+
+(test-assert "package-development-inputs, cross-compilation"
+  (lset<= equal?
+          `(("source" ,(package-source hello))
+            ,@(standard-cross-packages "mips64el-linux-gnu" 'host)
+            ,@(standard-cross-packages "mips64el-linux-gnu" 'target))
+          (package-development-inputs hello #:target "mips64el-linux-gnu")))
+
 (test-assert "package-closure"
   (let-syntax ((dummy-package/no-implicit
                 (syntax-rules ()