import: opam: Use dune-build-system when possible.

* guix/import/opam.scm (opam->guix-package): Detect when dune can be used.
This commit is contained in:
Julien Lepiller 2019-04-03 20:19:24 +02:00
parent 3e159dd0a4
commit 7b1c7ecdfb
No known key found for this signature in database
GPG Key ID: 43111F4520086A0C
1 changed files with 48 additions and 32 deletions

View File

@ -247,9 +247,23 @@ path to the repository."
(url-dict (metadata-ref opam-content "url"))
(source-url (metadata-ref url-dict "src"))
(requirements (metadata-ref opam-content "depends"))
(dependencies (dependency-list->names requirements))
(dependencies (filter
(lambda (name)
(not (member name '("dune" "jbuilder"))))
(dependency-list->names requirements)))
(native-dependencies (depends->native-inputs requirements))
(inputs (dependency-list->inputs (depends->inputs requirements)))
(native-inputs (dependency-list->inputs (depends->native-inputs requirements))))
(native-inputs (dependency-list->inputs
;; Do not add dune nor jbuilder since they are
;; implicit inputs of the dune-build-system.
(filter
(lambda (name)
(not (member name '("dune" "jbuilder"))))
native-dependencies))))
;; If one of these are required at build time, it means we
;; can use the much nicer dune-build-system.
(let ((use-dune? (or (member "dune" native-dependencies)
(member "jbuilder" native-dependencies))))
(call-with-temporary-output-file
(lambda (temp port)
(and (url-fetch source-url temp)
@ -264,7 +278,9 @@ path to the repository."
(method url-fetch)
(uri ,source-url)
(sha256 (base32 ,(guix-hash-url temp)))))
(build-system ocaml-build-system)
(build-system ,(if use-dune?
'dune-build-system
'ocaml-build-system))
,@(if (null? inputs)
'()
`((inputs ,(list 'quasiquote inputs))))
@ -279,7 +295,7 @@ path to the repository."
(synopsis ,(metadata-ref opam-content "synopsis"))
(description ,(metadata-ref opam-content "description"))
(license #f))
dependencies))))))
dependencies)))))))
(define (opam-recursive-import package-name)
(recursive-import package-name #f