unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* bug#26273: [PATCH] import cran: Automatically add gfortran and zlib when needed.
@ 2017-03-27 10:53 Ricardo Wurmus
  2017-03-28 11:15 ` Ludovic Courtès
  2017-03-30 12:58 ` bug#26273: merged: " Ricardo Wurmus
  0 siblings, 2 replies; 4+ messages in thread
From: Ricardo Wurmus @ 2017-03-27 10:53 UTC (permalink / raw)
  To: 26273; +Cc: Ricardo Wurmus

* guix/import/cran.scm (needs-fortran?, needs-zlib?): New procedures.
(description->package): Use them.
---
 guix/import/cran.scm | 48 +++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 45 insertions(+), 3 deletions(-)

diff --git a/guix/import/cran.scm b/guix/import/cran.scm
index 7521a39bc..54bd37007 100644
--- a/guix/import/cran.scm
+++ b/guix/import/cran.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2015, 2016 Ricardo Wurmus <rekado@elephly.net>
+;;; Copyright © 2015, 2016, 2017 Ricardo Wurmus <rekado@elephly.net>
 ;;; Copyright © 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
 ;;;
 ;;; This file is part of GNU Guix.
@@ -20,7 +20,7 @@
 (define-module (guix import cran)
   #:use-module (ice-9 match)
   #:use-module (ice-9 regex)
-  #:use-module ((ice-9 rdelim) #:select (read-string))
+  #:use-module ((ice-9 rdelim) #:select (read-string read-line))
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-26)
   #:use-module (srfi srfi-34)
@@ -34,6 +34,8 @@
   #:use-module (guix base32)
   #:use-module ((guix download) #:select (download-to-store))
   #:use-module (guix import utils)
+  #:use-module ((guix build utils) #:select (find-files))
+  #:use-module (guix utils)
   #:use-module ((guix build-system r) #:select (cran-uri bioconductor-uri))
   #:use-module (guix upstream)
   #:use-module (guix packages)
@@ -187,6 +189,39 @@ empty list when the FIELD cannot be found."
                                     (chr (char-downcase chr)))
                                   name)))
 
+(define (needs-fortran? tarball)
+  "Check if the TARBALL contains Fortran source files."
+  (define (check pattern)
+    (parameterize ((current-error-port (%make-void-port "rw+")))
+      (zero? (system* "tar" "--wildcards" "--list" pattern "-f" tarball))))
+  (or (check "*.f90")
+      (check "*.f95")
+      (check "*.f")))
+
+(define (needs-zlib? tarball)
+  "Return #T if any of the Makevars files in the src directory of the TARBALL
+contain a zlib linker flag."
+  (call-with-temporary-directory
+   (lambda (dir)
+     (let ((pattern (make-regexp "-lz")))
+       (parameterize ((current-error-port (%make-void-port "rw+")))
+         (system* "tar"
+                  "xf" tarball "-C" dir
+                  "--wildcards" "*/src/Makevars*"
+                  "--wildcards" "*/src/configure*"
+                  "--wildcards" "*/configure*"))
+       (any (lambda (file)
+              (call-with-input-file file
+                (lambda (port)
+                  (let loop ()
+                    (let ((line (read-line port)))
+                      (cond
+                       ((eof-object? line) #f)
+                       ((regexp-exec pattern line) #t)
+                       (else (loop)))))))
+              #t)
+            (find-files dir))))))
+
 (define (description->package repository meta)
   "Return the `package' s-expression for an R package published on REPOSITORY
 from the alist META, which was derived from the R package's DESCRIPTION file."
@@ -209,7 +244,9 @@ from the alist META, which was derived from the R package's DESCRIPTION file."
                        ((? string? url) url)
                        (_ #f)))
          (tarball    (with-store store (download-to-store store source-url)))
-         (sysdepends (map string-downcase (listify meta "SystemRequirements")))
+         (sysdepends (append
+                      (if (needs-zlib? tarball) '("zlib") '())
+                      (map string-downcase (listify meta "SystemRequirements"))))
          (propagate  (filter (lambda (name)
                                (not (member name default-r-packages)))
                              (lset-union equal?
@@ -234,6 +271,11 @@ from the alist META, which was derived from the R package's DESCRIPTION file."
         (build-system r-build-system)
         ,@(maybe-inputs sysdepends)
         ,@(maybe-inputs (map guix-name propagate) 'propagated-inputs)
+        ,@(if (needs-fortran? tarball)
+              `((native-inputs (,'quasiquote
+                                ,(list "gfortran"
+                                       (list 'unquote 'gfortran)))))
+              '())
         (home-page ,(if (string-null? home-page)
                         (string-append base-url name)
                         home-page))
-- 
2.11.1

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

* bug#26273: [PATCH] import cran: Automatically add gfortran and zlib when needed.
  2017-03-27 10:53 bug#26273: [PATCH] import cran: Automatically add gfortran and zlib when needed Ricardo Wurmus
@ 2017-03-28 11:15 ` Ludovic Courtès
  2017-03-28 12:28   ` Ricardo Wurmus
  2017-03-30 12:58 ` bug#26273: merged: " Ricardo Wurmus
  1 sibling, 1 reply; 4+ messages in thread
From: Ludovic Courtès @ 2017-03-28 11:15 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: 26273

Ricardo Wurmus <ricardo.wurmus@mdc-berlin.de> skribis:

> * guix/import/cran.scm (needs-fortran?, needs-zlib?): New procedures.
> (description->package): Use them.

[...]

> +(define (needs-fortran? tarball)
> +  "Check if the TARBALL contains Fortran source files."
> +  (define (check pattern)
> +    (parameterize ((current-error-port (%make-void-port "rw+")))
> +      (zero? (system* "tar" "--wildcards" "--list" pattern "-f" tarball))))
> +  (or (check "*.f90")
> +      (check "*.f95")
> +      (check "*.f")))

I think we can use:

  tar --list -f tarball --wildcards *.f90 *.f95 *.f

If that works, it would allow us to get test everything in one run.

> +(define (needs-zlib? tarball)
> +  "Return #T if any of the Makevars files in the src directory of the TARBALL
> +contain a zlib linker flag."
> +  (call-with-temporary-directory
> +   (lambda (dir)
> +     (let ((pattern (make-regexp "-lz")))
> +       (parameterize ((current-error-port (%make-void-port "rw+")))
> +         (system* "tar"
> +                  "xf" tarball "-C" dir
> +                  "--wildcards" "*/src/Makevars*"
> +                  "--wildcards" "*/src/configure*"
> +                  "--wildcards" "*/configure*"))

IIUC “--wildcards” needs only appear once.

Otherwise LGTM, nice improvement!

Thanks,
Ludo’.

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

* bug#26273: [PATCH] import cran: Automatically add gfortran and zlib when needed.
  2017-03-28 11:15 ` Ludovic Courtès
@ 2017-03-28 12:28   ` Ricardo Wurmus
  0 siblings, 0 replies; 4+ messages in thread
From: Ricardo Wurmus @ 2017-03-28 12:28 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 26273


Ludovic Courtès <ludo@gnu.org> writes:

> Ricardo Wurmus <ricardo.wurmus@mdc-berlin.de> skribis:
>
>> * guix/import/cran.scm (needs-fortran?, needs-zlib?): New procedures.
>> (description->package): Use them.
>
> [...]
>
>> +(define (needs-fortran? tarball)
>> +  "Check if the TARBALL contains Fortran source files."
>> +  (define (check pattern)
>> +    (parameterize ((current-error-port (%make-void-port "rw+")))
>> +      (zero? (system* "tar" "--wildcards" "--list" pattern "-f" tarball))))
>> +  (or (check "*.f90")
>> +      (check "*.f95")
>> +      (check "*.f")))
>
> I think we can use:
>
>   tar --list -f tarball --wildcards *.f90 *.f95 *.f
>
> If that works, it would allow us to get test everything in one run.

I tried that, but it doesn’t work.  It returns a non-zero exit code when
only files with one of the endings are present (i.e. the patterns are
ANDed).

>> +(define (needs-zlib? tarball)
>> +  "Return #T if any of the Makevars files in the src directory of the TARBALL
>> +contain a zlib linker flag."
>> +  (call-with-temporary-directory
>> +   (lambda (dir)
>> +     (let ((pattern (make-regexp "-lz")))
>> +       (parameterize ((current-error-port (%make-void-port "rw+")))
>> +         (system* "tar"
>> +                  "xf" tarball "-C" dir
>> +                  "--wildcards" "*/src/Makevars*"
>> +                  "--wildcards" "*/src/configure*"
>> +                  "--wildcards" "*/configure*"))
>
> IIUC “--wildcards” needs only appear once.

Yes, it seems that you’re right.  I’ll push an updated version to master
in a few minutes.

Thanks for the review!

--
Ricardo

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

* bug#26273: merged: import cran: Automatically add gfortran and zlib when needed.
  2017-03-27 10:53 bug#26273: [PATCH] import cran: Automatically add gfortran and zlib when needed Ricardo Wurmus
  2017-03-28 11:15 ` Ludovic Courtès
@ 2017-03-30 12:58 ` Ricardo Wurmus
  1 sibling, 0 replies; 4+ messages in thread
From: Ricardo Wurmus @ 2017-03-30 12:58 UTC (permalink / raw)
  To: 26273-done

Pushed to master with commit 2dca8b2d513db69aed3790096bc75c7c096b920c.

~~ Ricardo

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

end of thread, other threads:[~2017-03-30 12:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-27 10:53 bug#26273: [PATCH] import cran: Automatically add gfortran and zlib when needed Ricardo Wurmus
2017-03-28 11:15 ` Ludovic Courtès
2017-03-28 12:28   ` Ricardo Wurmus
2017-03-30 12:58 ` bug#26273: merged: " Ricardo Wurmus

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