import/cran: Always operate on source directory.
Extracting the source tarball multiple times is very slow and a speedup of >2x (without network I/O) can be achieved by coalescing all NEEDS-X? functions into a single one, which extracts a tarball only once. * guix/import/cran.scm (tarball-needs-fortran?): Remove unused function. (needs-fortran?): Ditto. (tarball-files-match-pattern?): Ditto. (tarball-needs-zlib?): Ditto. (needs-zlib?): Ditto. (tarball-needs-pkg-config?): Ditto. (needs-pkg-config?): Ditto. (source-dir->dependencies): New function. (source->dependencies): New function. (description->package): Use it.
This commit is contained in:
parent
952953be39
commit
973496100d
1 changed files with 23 additions and 55 deletions
|
|
@ -440,28 +440,12 @@ empty list when the FIELD cannot be found."
|
||||||
|
|
||||||
(define cran-guix-name (cut guix-name "r-" <>))
|
(define cran-guix-name (cut guix-name "r-" <>))
|
||||||
|
|
||||||
(define (tarball-needs-fortran? tarball)
|
|
||||||
"Check if the TARBALL contains Fortran source files."
|
|
||||||
(define (check pattern)
|
|
||||||
(parameterize ((current-error-port (%make-void-port "rw+"))
|
|
||||||
(current-output-port (%make-void-port "rw+")))
|
|
||||||
(zero? (system* "tar" "--wildcards" "--list" pattern "-f" tarball))))
|
|
||||||
(or (check "*.f90")
|
|
||||||
(check "*.f95")
|
|
||||||
(check "*.f")))
|
|
||||||
|
|
||||||
(define (directory-needs-fortran? dir)
|
(define (directory-needs-fortran? dir)
|
||||||
"Check if the directory DIR contains Fortran source files."
|
"Check if the directory DIR contains Fortran source files."
|
||||||
(match (find-files dir "\\.f(90|95)$")
|
(match (find-files dir "\\.f(90|95)$")
|
||||||
(() #f)
|
(() #f)
|
||||||
(_ #t)))
|
(_ #t)))
|
||||||
|
|
||||||
(define (needs-fortran? thing tarball?)
|
|
||||||
"Check if the THING contains Fortran source files."
|
|
||||||
(if tarball?
|
|
||||||
(tarball-needs-fortran? thing)
|
|
||||||
(directory-needs-fortran? thing)))
|
|
||||||
|
|
||||||
(define (files-match-pattern? directory regexp . file-patterns)
|
(define (files-match-pattern? directory regexp . file-patterns)
|
||||||
"Return #T if any of the files matching FILE-PATTERNS in the DIRECTORY match
|
"Return #T if any of the files matching FILE-PATTERNS in the DIRECTORY match
|
||||||
the given REGEXP."
|
the given REGEXP."
|
||||||
|
|
@ -477,53 +461,36 @@ the given REGEXP."
|
||||||
(else (loop))))))))
|
(else (loop))))))))
|
||||||
(apply find-files directory file-patterns))))
|
(apply find-files directory file-patterns))))
|
||||||
|
|
||||||
(define (tarball-files-match-pattern? tarball regexp . file-patterns)
|
|
||||||
"Return #T if any of the files represented by FILE-PATTERNS in the TARBALL
|
|
||||||
match the given REGEXP."
|
|
||||||
(call-with-temporary-directory
|
|
||||||
(lambda (dir)
|
|
||||||
(parameterize ((current-error-port (%make-void-port "rw+")))
|
|
||||||
(apply system* "tar"
|
|
||||||
"xf" tarball "-C" dir
|
|
||||||
`("--wildcards" ,@file-patterns)))
|
|
||||||
(files-match-pattern? dir regexp))))
|
|
||||||
|
|
||||||
(define (directory-needs-zlib? dir)
|
(define (directory-needs-zlib? dir)
|
||||||
"Return #T if any of the Makevars files in the src directory DIR contain a
|
"Return #T if any of the Makevars files in the src directory DIR contain a
|
||||||
zlib linker flag."
|
zlib linker flag."
|
||||||
(files-match-pattern? dir "-lz" "(Makevars.*|configure.*)"))
|
(files-match-pattern? dir "-lz" "(Makevars.*|configure.*)"))
|
||||||
|
|
||||||
(define (tarball-needs-zlib? tarball)
|
|
||||||
"Return #T if any of the Makevars files in the src directory of the TARBALL
|
|
||||||
contain a zlib linker flag."
|
|
||||||
(tarball-files-match-pattern?
|
|
||||||
tarball "-lz"
|
|
||||||
"*/src/Makevars*" "*/src/configure*" "*/configure*"))
|
|
||||||
|
|
||||||
(define (needs-zlib? thing tarball?)
|
|
||||||
"Check if the THING contains files indicating a dependency on zlib."
|
|
||||||
(if tarball?
|
|
||||||
(tarball-needs-zlib? thing)
|
|
||||||
(directory-needs-zlib? thing)))
|
|
||||||
|
|
||||||
(define (directory-needs-pkg-config? dir)
|
(define (directory-needs-pkg-config? dir)
|
||||||
"Return #T if any of the Makevars files in the src directory DIR reference
|
"Return #T if any of the Makevars files in the src directory DIR reference
|
||||||
the pkg-config tool."
|
the pkg-config tool."
|
||||||
(files-match-pattern? dir "pkg-config"
|
(files-match-pattern? dir "pkg-config"
|
||||||
"(Makevars.*|configure.*)"))
|
"(Makevars.*|configure.*)"))
|
||||||
|
|
||||||
(define (tarball-needs-pkg-config? tarball)
|
(define (source-dir->dependencies dir)
|
||||||
"Return #T if any of the Makevars files in the src directory of the TARBALL
|
"Guess dependencies of R package source in DIR and return (INPUTS
|
||||||
reference the pkg-config tool."
|
NATIVE-INPUTS)."
|
||||||
(tarball-files-match-pattern?
|
(list
|
||||||
tarball "pkg-config"
|
(if (directory-needs-zlib? dir) '("zlib") '())
|
||||||
"*/src/Makevars*" "*/src/configure*" "*/configure*"))
|
(append
|
||||||
|
(if (directory-needs-pkg-config? dir) '("pkg-config") '())
|
||||||
|
(if (directory-needs-fortran? dir) '("gfortran") '()))))
|
||||||
|
|
||||||
(define (needs-pkg-config? thing tarball?)
|
(define (source->dependencies source tarball?)
|
||||||
"Check if the THING contains files indicating a dependency on pkg-config."
|
"SOURCE-DIR->DEPENDENCIES, but for directories and tarballs as indicated
|
||||||
|
by TARBALL?"
|
||||||
(if tarball?
|
(if tarball?
|
||||||
(tarball-needs-pkg-config? thing)
|
(call-with-temporary-directory
|
||||||
(directory-needs-pkg-config? thing)))
|
(lambda (dir)
|
||||||
|
(parameterize ((current-error-port (%make-void-port "rw+")))
|
||||||
|
(system* "tar" "xf" source "-C" dir))
|
||||||
|
(source-dir->dependencies dir)))
|
||||||
|
(source-dir->dependencies source)))
|
||||||
|
|
||||||
(define (needs-knitr? meta)
|
(define (needs-knitr? meta)
|
||||||
(member "knitr" (listify meta "VignetteBuilder")))
|
(member "knitr" (listify meta "VignetteBuilder")))
|
||||||
|
|
@ -575,8 +542,12 @@ from the alist META, which was derived from the R package's DESCRIPTION file."
|
||||||
(git? 'git)
|
(git? 'git)
|
||||||
(hg? 'hg)
|
(hg? 'hg)
|
||||||
(else #f))))
|
(else #f))))
|
||||||
|
(tarball? (not (or git? hg?)))
|
||||||
|
(source-inputs-all (source->dependencies source tarball?))
|
||||||
|
(source-inputs (car source-inputs-all))
|
||||||
|
(source-native-inputs (cadr source-inputs-all))
|
||||||
(sysdepends (append
|
(sysdepends (append
|
||||||
(if (needs-zlib? source (not (or git? hg?))) '("zlib") '())
|
source-inputs
|
||||||
(filter (lambda (name)
|
(filter (lambda (name)
|
||||||
(not (member name invalid-packages)))
|
(not (member name invalid-packages)))
|
||||||
(map string-downcase (listify meta "SystemRequirements")))))
|
(map string-downcase (listify meta "SystemRequirements")))))
|
||||||
|
|
@ -636,10 +607,7 @@ from the alist META, which was derived from the R package's DESCRIPTION file."
|
||||||
,@(maybe-inputs (map transform-sysname sysdepends))
|
,@(maybe-inputs (map transform-sysname sysdepends))
|
||||||
,@(maybe-inputs (map cran-guix-name propagate) 'propagated-inputs)
|
,@(maybe-inputs (map cran-guix-name propagate) 'propagated-inputs)
|
||||||
,@(maybe-inputs
|
,@(maybe-inputs
|
||||||
`(,@(if (needs-fortran? source (not (or git? hg?)))
|
`(,@source-native-inputs
|
||||||
'("gfortran") '())
|
|
||||||
,@(if (needs-pkg-config? source (not (or git? hg?)))
|
|
||||||
'("pkg-config") '())
|
|
||||||
,@(if (needs-knitr? meta)
|
,@(if (needs-knitr? meta)
|
||||||
'("r-knitr") '()))
|
'("r-knitr") '()))
|
||||||
'native-inputs)
|
'native-inputs)
|
||||||
|
|
|
||||||
Reference in a new issue