diff options
| -rw-r--r-- | guix/import/hackage.scm | 32 | ||||
| -rw-r--r-- | tests/hackage.scm | 37 |
2 files changed, 52 insertions, 17 deletions
diff --git a/guix/import/hackage.scm b/guix/import/hackage.scm index 2731b4cbee8..bf7e99df18b 100644 --- a/guix/import/hackage.scm +++ b/guix/import/hackage.scm | |||
| @@ -279,13 +279,11 @@ representation of a Cabal file as produced by 'read-cabal'." | |||
| 279 | (license ,(string->license (cabal-package-license cabal)))) | 279 | (license ,(string->license (cabal-package-license cabal)))) |
| 280 | (append hackage-dependencies hackage-native-dependencies)))) | 280 | (append hackage-dependencies hackage-native-dependencies)))) |
| 281 | 281 | ||
| 282 | (define hackage->guix-package | 282 | (define* (hackage->guix-package package-name #:key |
| 283 | (memoize | 283 | (include-test-dependencies? #t) |
| 284 | (lambda* (package-name #:key | 284 | (port #f) |
| 285 | (include-test-dependencies? #t) | 285 | (cabal-environment '())) |
| 286 | (port #f) | 286 | "Fetch the Cabal file for PACKAGE-NAME from hackage.haskell.org, or, if the |
| 287 | (cabal-environment '())) | ||
| 288 | "Fetch the Cabal file for PACKAGE-NAME from hackage.haskell.org, or, if the | ||
| 289 | called with keyword parameter PORT, from PORT. Return the `package' | 287 | called with keyword parameter PORT, from PORT. Return the `package' |
| 290 | S-expression corresponding to that package, or #f on failure. | 288 | S-expression corresponding to that package, or #f on failure. |
| 291 | CABAL-ENVIRONMENT is an alist defining the environment in which the Cabal | 289 | CABAL-ENVIRONMENT is an alist defining the environment in which the Cabal |
| @@ -295,18 +293,22 @@ symbol 'true' or 'false'. The value associated with other keys has to conform | |||
| 295 | to the Cabal file format definition. The default value associated with the | 293 | to the Cabal file format definition. The default value associated with the |
| 296 | keys \"os\", \"arch\" and \"impl\" is \"linux\", \"x86_64\" and \"ghc\" | 294 | keys \"os\", \"arch\" and \"impl\" is \"linux\", \"x86_64\" and \"ghc\" |
| 297 | respectively." | 295 | respectively." |
| 298 | (let ((cabal-meta (if port | 296 | (let ((cabal-meta (if port |
| 299 | (read-cabal (canonical-newline-port port)) | 297 | (read-cabal (canonical-newline-port port)) |
| 300 | (hackage-fetch package-name)))) | 298 | (hackage-fetch package-name)))) |
| 301 | (and=> cabal-meta (compose (cut hackage-module->sexp <> | 299 | (and=> cabal-meta (compose (cut hackage-module->sexp <> |
| 302 | #:include-test-dependencies? | 300 | #:include-test-dependencies? |
| 303 | include-test-dependencies?) | 301 | include-test-dependencies?) |
| 304 | (cut eval-cabal <> cabal-environment))))))) | 302 | (cut eval-cabal <> cabal-environment))))) |
| 303 | |||
| 304 | (define hackage->guix-package/m ;memoized variant | ||
| 305 | (memoize hackage->guix-package)) | ||
| 305 | 306 | ||
| 306 | (define* (hackage-recursive-import package-name . args) | 307 | (define* (hackage-recursive-import package-name . args) |
| 307 | (recursive-import package-name #f | 308 | (recursive-import package-name #f |
| 308 | #:repo->guix-package (lambda (name repo) | 309 | #:repo->guix-package (lambda (name repo) |
| 309 | (apply hackage->guix-package (cons name args))) | 310 | (apply hackage->guix-package/m |
| 311 | (cons name args))) | ||
| 310 | #:guix-name hackage-name->package-name)) | 312 | #:guix-name hackage-name->package-name)) |
| 311 | 313 | ||
| 312 | (define (hackage-package? package) | 314 | (define (hackage-package? package) |
diff --git a/tests/hackage.scm b/tests/hackage.scm index e17851a213b..0efad0638d2 100644 --- a/tests/hackage.scm +++ b/tests/hackage.scm | |||
| @@ -207,8 +207,41 @@ library | |||
| 207 | #:cabal-environment '(("impl" . "ghc-7.8")))) | 207 | #:cabal-environment '(("impl" . "ghc-7.8")))) |
| 208 | 208 | ||
| 209 | (test-assert "hackage->guix-package test 6" | 209 | (test-assert "hackage->guix-package test 6" |
| 210 | (eval-test-with-cabal test-cabal-6 | 210 | (mock |
| 211 | #:cabal-environment '(("impl" . "ghc-7.8")))) | 211 | ((guix import hackage) hackage-fetch |
| 212 | (lambda (name-version) | ||
| 213 | (call-with-input-string test-cabal-6 | ||
| 214 | read-cabal))) | ||
| 215 | (match (hackage->guix-package "foo") | ||
| 216 | (('package | ||
| 217 | ('name "ghc-foo") | ||
| 218 | ('version "1.0.0") | ||
| 219 | ('source | ||
| 220 | ('origin | ||
| 221 | ('method 'url-fetch) | ||
| 222 | ('uri ('string-append | ||
| 223 | "https://hackage.haskell.org/package/foo/foo-" | ||
| 224 | 'version | ||
| 225 | ".tar.gz")) | ||
| 226 | ('sha256 | ||
| 227 | ('base32 | ||
| 228 | (? string? hash))))) | ||
| 229 | ('build-system 'haskell-build-system) | ||
| 230 | ('inputs | ||
| 231 | ('quasiquote | ||
| 232 | (("ghc-b" ('unquote 'ghc-b)) | ||
| 233 | ("ghc-http" ('unquote 'ghc-http)) | ||
| 234 | ("ghc-mtl" ('unquote 'ghc-mtl))))) | ||
| 235 | ('native-inputs | ||
| 236 | ('quasiquote | ||
| 237 | (("ghc-haskell-gi" ('unquote 'ghc-haskell-gi))))) | ||
| 238 | ('home-page "http://test.org") | ||
| 239 | ('synopsis (? string?)) | ||
| 240 | ('description (? string?)) | ||
| 241 | ('license 'bsd-3)) | ||
| 242 | #t) | ||
| 243 | (x | ||
| 244 | (pk 'fail x #f))))) | ||
| 212 | 245 | ||
| 213 | (test-assert "read-cabal test 1" | 246 | (test-assert "read-cabal test 1" |
| 214 | (match (call-with-input-string test-read-cabal-1 read-cabal) | 247 | (match (call-with-input-string test-read-cabal-1 read-cabal) |
