unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
* How to copy a file to the package /bin folder using the r-build-system?
@ 2023-03-31 23:21 Kyle Andrews
  2023-04-07 16:07 ` Simon Tournier
  0 siblings, 1 reply; 5+ messages in thread
From: Kyle Andrews @ 2023-03-31 23:21 UTC (permalink / raw)
  To: help-guix


Dear Guix,

I want to package the littler R package.

Unlike most R packages, this one provides an executable (a little r to
complement the big R) that should go on the PATH rather than be tucked
away into site-library where it cannot be used. Surprisingly, to me,
when the command below fails ...

```
guix build -K -f littler.scm
```

... the resulting temporary directory skips directly to the littler
folder wheras the /gnu/store builds show the output inside of
site-library. The /tmp output also looks different, lacking a bin/
folder like in the /gnu/store/*littlr* builds.

How do I go about getting r out of site-library/littler/bin/r in there
using the r-build-system?

Here is what I have right now:

```
(use-modules
 (guix packages)
 (guix download)
 (gnu packages statistics)
 (gnu packages compression)
 (gnu packages icu4c)
 (guix gexp)
 (guix build-system r)
 (gnu packages cran)
 (gnu packages autotools)
 ((guix licenses) #:prefix license:))

(define-public r-littler
  (package
    (name "r-littler")
    (version "0.3.18")
    (source (origin
              (method url-fetch)
              (uri (cran-uri "littler" version))
              (sha256
               (base32
                "1lp6a62g3yhzr4pv9kynibv7k9pd546w6hifs1aficyxbyg4dgqq"))))
    (properties `((upstream-name . "littler")))
    (build-system r-build-system)
    (arguments
     (list
      #:phases
      #~(modify-phases %standard-phases
	  (add-after 'install 'add-to-path
	    (lambda* (#:key inputs outputs #:allow-other-keys)
	      (let ((out (assoc-ref outputs "out")))
		;;; TODO: this doesn't work!
		;; copy site-library/littler/bin/r to bin/r
		(copy-file
		 (string-append out "site-library/littler/src/r")
		 (string-append out "/bin/r"))))))))
    (inputs (list icu4c))
    (native-inputs (list r-simplermarkdown automake autoconf zlib))
    (home-page "https://github.com/eddelbuettel/littler")
    (synopsis "R at the Command-Line via 'r'")
    (description
     "This package provides a scripting and command-line front-end is provided by r
(aka littler') as a lightweight binary wrapper around the GNU R language and
environment for statistical computing and graphics.  While R can be used in
batch mode, the r binary adds full support for both shebang'-style scripting
(i.e.  using a hash-mark-exclamation-path expression as the first line in
scripts) as well as command-line use in standard Unix pipelines.  In other
words, r provides the R language without the environment.")
    (license license:gpl2+)))

;; (packages->manifest (list r r-littler))

r-littler
```

I'm grateful for any assistance!

Best Regards,
Kyle


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

* Re: How to copy a file to the package /bin folder using the r-build-system?
  2023-03-31 23:21 How to copy a file to the package /bin folder using the r-build-system? Kyle Andrews
@ 2023-04-07 16:07 ` Simon Tournier
  2023-04-09  3:15   ` Kyle Andrews
  0 siblings, 1 reply; 5+ messages in thread
From: Simon Tournier @ 2023-04-07 16:07 UTC (permalink / raw)
  To: Kyle Andrews, help-guix

Hi,

On ven., 31 mars 2023 at 23:21, Kyle Andrews <kyle@posteo.net> wrote:

> 	      (let ((out (assoc-ref outputs "out")))
> 		;;; TODO: this doesn't work!
> 		;; copy site-library/littler/bin/r to bin/r
> 		(copy-file
> 		 (string-append out "site-library/littler/src/r")
> 		 (string-append out "/bin/r"))))))))

I guess what you want is:

--8<---------------cut here---------------start------------->8---
              (let* ((out (assoc-ref outputs "out"))
                     (out/bin (string-append out "/bin")))
                (mkdir out/bin)
                (copy-file "inst/bin/r"
                 (string-append out/bin "/r"))))))))
--8<---------------cut here---------------end--------------->8---

And I would write,

            (lambda _
              (mkdir (string-append #$output "/bin"))
              (copy-file "inst/bin/r"
                         (string-append #$output "/bin/r")))



Well, using one or the other, I get:

--8<---------------cut here---------------start------------->8---
$ guix shell -L /tmp/foo r-littler -C -- r --help

Usage: r [options] [-|file]

Launch GNU R to execute the R commands supplied in the specified file, or
from stdin if '-' is used. Suitable for so-called shebang '#!/'-line scripts.

Options:
  -h, --help           Give this help list
      --usage          Give a short usage message
  -V, --version        Show the version number
  -v, --vanilla        Pass the '--vanilla' option to R
  -t, --rtemp          Use per-session temporary directory as R does
  -i, --interactive    Let interactive() return 'true' rather than 'false'
  -q, --quick          Skip autoload / delayed assign of default libraries
  -p, --verbose        Print the value of expressions to the console
  -l, --packages list  Load the R packages from the comma-separated 'list'
  -d, --datastdin      Prepend command to load 'X' as csv from stdin
  -L, --libpath dir    Add directory to library path via '.libPaths(dir)'
  -e, --eval expr      Let R evaluate 'expr'

--8<---------------cut here---------------end--------------->8---


Hope that helps,
simon


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

* Re: How to copy a file to the package /bin folder using the r-build-system?
  2023-04-07 16:07 ` Simon Tournier
@ 2023-04-09  3:15   ` Kyle Andrews
  2023-04-09  9:36     ` (
  0 siblings, 1 reply; 5+ messages in thread
From: Kyle Andrews @ 2023-04-09  3:15 UTC (permalink / raw)
  To: Simon Tournier; +Cc: help-guix


Simon Tournier <zimon.toutoune@gmail.com> writes:

> Hi,
>
> On ven., 31 mars 2023 at 23:21, Kyle Andrews <kyle@posteo.net> wrote:
>
>> 	      (let ((out (assoc-ref outputs "out")))
>> 		;;; TODO: this doesn't work!
>> 		;; copy site-library/littler/bin/r to bin/r
>> 		(copy-file
>> 		 (string-append out "site-library/littler/src/r")
>> 		 (string-append out "/bin/r"))))))))
>
> I guess what you want is:
>
> --8<---------------cut here---------------start------------->8---
>               (let* ((out (assoc-ref outputs "out"))
>                      (out/bin (string-append out "/bin")))
>                 (mkdir out/bin)
>                 (copy-file "inst/bin/r"
>                  (string-append out/bin "/r"))))))))
> --8<---------------cut here---------------end--------------->8---

Gotcha. That must mean my mental model should be that "out" refers to the directory in the store, while the working directory is inside of the decompressed source directory. I probably should have inferred that would almost always be the case since most build-systems will (re-)use 'unpack.

I also made the mistake of now always starting my path strings with a forward slash.

>
> And I would write,
>
>             (lambda _
>               (mkdir (string-append #$output "/bin"))
>               (copy-file "inst/bin/r"
>                          (string-append #$output "/bin/r")))

This perfect makes sense now and is much more concise.

>
>
> Well, using one or the other, I get:
>
> --8<---------------cut here---------------start------------->8---
> $ guix shell -L /tmp/foo r-littler -C -- r --help
>
> Usage: r [options] [-|file]
>
> Launch GNU R to execute the R commands supplied in the specified file, or
> from stdin if '-' is used. Suitable for so-called shebang '#!/'-line scripts.
>
> Options:
>   -h, --help           Give this help list
>       --usage          Give a short usage message
>   -V, --version        Show the version number
>   -v, --vanilla        Pass the '--vanilla' option to R
>   -t, --rtemp          Use per-session temporary directory as R does
>   -i, --interactive    Let interactive() return 'true' rather than 'false'
>   -q, --quick          Skip autoload / delayed assign of default libraries
>   -p, --verbose        Print the value of expressions to the console
>   -l, --packages list  Load the R packages from the comma-separated 'list'
>   -d, --datastdin      Prepend command to load 'X' as csv from stdin
>   -L, --libpath dir    Add directory to library path via '.libPaths(dir)'
>   -e, --eval expr      Let R evaluate 'expr'
>
> --8<---------------cut here---------------end--------------->8---
>

Thanks! I had been "toggling" back and forth between (packages->manifest (list r-littler)) and r-littler. In other words, the former gets uncommented when running guix shell -m littler.scm while the latter gets uncommented when used with guix build -f r-littler with the former getting commented. I can see from your example how writing a module would obviate the need to edit the source file over and over with the promise that alternatives can be illustrated at the same level.

Sadly, when I tried to take that idea and run with it I got an unexpected error.

```
$ guix build -L dev r-littler
...
ld: cannot find -lz
collect2: error: ld returned 1 exit status
...
```

I know I have seen that error before, but I thought it was fixed by importing compression, prefixing (guix licenses) to prevent a namespace collision, and including zlib in the package inputs.

```
$ diff littler.scm dev/littler.scm 
1,11c1,11
< (use-modules
<  (guix packages)
<  (guix download)
<  (gnu packages statistics)
<  (gnu packages compression)
<  (gnu packages icu4c)
<  (guix gexp)
<  (guix build-system r)
<  (gnu packages cran)
<  (gnu packages autotools)
<  ((guix licenses) #:prefix license:))
---
> (define-module (littler)
>   #:use-module (guix packages)
>   #:use-module (guix download)
>   #:use-module (gnu packages statistics)
>   #:use-module (gnu packages compression)
>   #:use-module (gnu packages icu4c)
>   #:use-module (guix gexp)
>   #:use-module (guix build-system r)
>   #:use-module (gnu packages cran)
>   #:use-module (gnu packages autotools)
>   #:use-module ((guix licenses) #:prefix license:))
47,50d46
< 
< ;; (packages->manifest (list r r-littler))
< 
< r-littler
```

Meanwhile, your command ran the same for me as it did for you.

```
guix shell -L dev r-littler -C -- r --help
```

What am I missing?


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

* Re: How to copy a file to the package /bin folder using the r-build-system?
  2023-04-09  3:15   ` Kyle Andrews
@ 2023-04-09  9:36     ` (
  2023-04-09 12:54       ` Kyle Andrews
  0 siblings, 1 reply; 5+ messages in thread
From: ( @ 2023-04-09  9:36 UTC (permalink / raw)
  To: Kyle Andrews, Simon Tournier; +Cc: help-guix

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

Heya,

On Sun Apr 9, 2023 at 4:15 AM BST, Kyle Andrews wrote:
> >             (lambda _
> >               (mkdir (string-append #$output "/bin"))
> >               (copy-file "inst/bin/r"
> >                          (string-append #$output "/bin/r")))
>
> This perfect makes sense now and is much more concise.

Actually, you can even do:

```
(lambda _
  (install-file "inst/bin/r"
                (string-append #$output "/bin")))
```

> ```
> $ guix build -L dev r-littler
> ...
> ld: cannot find -lz
> collect2: error: ld returned 1 exit status
> ...
> ```
>
> I know I have seen that error before, but I thought it was fixed by importing compression, prefixing (guix licenses) to prevent a namespace collision, and including zlib in the package inputs.

I think (!) you also need to import (gnu packages pkg-config) and add
PKG-CONFIG to NATIVE-INPUTS.

    -- (

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

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

* Re: How to copy a file to the package /bin folder using the r-build-system?
  2023-04-09  9:36     ` (
@ 2023-04-09 12:54       ` Kyle Andrews
  0 siblings, 0 replies; 5+ messages in thread
From: Kyle Andrews @ 2023-04-09 12:54 UTC (permalink / raw)
  To: (; +Cc: Simon Tournier, help-guix


"(" <paren@disroot.org> writes:

> [[PGP Signed Part:Undecided]]
> Heya,
>
> On Sun Apr 9, 2023 at 4:15 AM BST, Kyle Andrews wrote:
>> >             (lambda _
>> >               (mkdir (string-append #$output "/bin"))
>> >               (copy-file "inst/bin/r"
>> >                          (string-append #$output "/bin/r")))
>>
>> This perfect makes sense now and is much more concise.
>
> Actually, you can even do:
>
> ```
> (lambda _
>   (install-file "inst/bin/r"
>                 (string-append #$output "/bin")))
> ```

That is nice and intentional!

>> ```
>> $ guix build -L dev r-littler
>> ...
>> ld: cannot find -lz
>> collect2: error: ld returned 1 exit status
>> ...
>> ```
>>
>> I know I have seen that error before, but I thought it was fixed by
>> importing compression, prefixing (guix licenses) to prevent a
>> namespace collision, and including zlib in the package inputs.
>
> I think (!) you also need to import (gnu packages pkg-config) and add
> PKG-CONFIG to NATIVE-INPUTS.

That fixed it! Thanks!

>     -- (


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

end of thread, other threads:[~2023-04-09 13:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-31 23:21 How to copy a file to the package /bin folder using the r-build-system? Kyle Andrews
2023-04-07 16:07 ` Simon Tournier
2023-04-09  3:15   ` Kyle Andrews
2023-04-09  9:36     ` (
2023-04-09 12:54       ` Kyle Andrews

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