import: opam: Replace "_" with "-" in imported names.

* guix/import/opam.scm (ocaml-name->guix-name): Replace "_" with "-".
(opam->guix-packages): Add upstream name when we cannot guess it
properly.
This commit is contained in:
Julien Lepiller 2019-02-01 16:16:25 +01:00
parent 0f4432c620
commit beee37ecdb
No known key found for this signature in database
GPG Key ID: 43111F4520086A0C
1 changed files with 22 additions and 9 deletions

View File

@ -127,12 +127,17 @@ path to the repository."
(lambda _ (lambda _
(peg:tree (match-pattern records (get-string-all (current-input-port))))))) (peg:tree (match-pattern records (get-string-all (current-input-port)))))))
(define (substitute-char str what with)
(string-join (string-split str what) with))
(define (ocaml-name->guix-name name) (define (ocaml-name->guix-name name)
(cond (substitute-char
((equal? name "ocamlfind") "ocaml-findlib") (cond
((string-prefix? "ocaml" name) name) ((equal? name "ocamlfind") "ocaml-findlib")
((string-prefix? "conf-" name) (substring name 5)) ((string-prefix? "ocaml" name) name)
(else (string-append "ocaml-" name)))) ((string-prefix? "conf-" name) (substring name 5))
(else (string-append "ocaml-" name)))
#\_ "-"))
(define (metadata-ref file lookup) (define (metadata-ref file lookup)
(fold (lambda (record acc) (fold (lambda (record acc)
@ -247,6 +252,10 @@ path to the repository."
,@(if (null? native-inputs) ,@(if (null? native-inputs)
'() '()
`((native-inputs ,(list 'quasiquote native-inputs)))) `((native-inputs ,(list 'quasiquote native-inputs))))
,@(if (equal? name (guix-name->opam-name (ocaml-name->guix-name name)))
'()
`((properties
,(list 'quasiquote `((upstream-name . ,name))))))
(home-page ,(metadata-ref opam-content "homepage")) (home-page ,(metadata-ref opam-content "homepage"))
(synopsis ,(metadata-ref opam-content "synopsis")) (synopsis ,(metadata-ref opam-content "synopsis"))
(description ,(metadata-ref opam-content "description")) (description ,(metadata-ref opam-content "description"))
@ -259,6 +268,11 @@ path to the repository."
(opam->guix-package name)) (opam->guix-package name))
#:guix-name ocaml-name->guix-name)) #:guix-name ocaml-name->guix-name))
(define (guix-name->opam-name name)
(if (string-prefix? "ocaml-" name)
(substring name 6)
name))
(define (guix-package->opam-name package) (define (guix-package->opam-name package)
"Given an OCaml PACKAGE built from OPAM, return the name of the "Given an OCaml PACKAGE built from OPAM, return the name of the
package in OPAM." package in OPAM."
@ -266,10 +280,9 @@ package in OPAM."
(package-properties package) (package-properties package)
'upstream-name)) 'upstream-name))
(name (package-name package))) (name (package-name package)))
(cond (if upstream-name
(upstream-name upstream-name) upstream-name
((string-prefix? "ocaml-" name) (substring name 6)) (guix-name->opam-name name))))
(else name))))
(define (opam-package? package) (define (opam-package? package)
"Return true if PACKAGE is an OCaml package from OPAM" "Return true if PACKAGE is an OCaml package from OPAM"