Subject: Re: [PATCH] WIP patches for the rust importer

From: Martin Becze <[email-masked]>
Date: Fri, 29 Nov 2019 07:59:35 -0800

On 2019-11-28 12:22, Efraim Flashner wrote:
> On Wed, Nov 27, 2019 at 04:36:20PM -0800, [email-masked] wrote:
>>
>> > I'd love to see what you have so far if you want to share
>>
>> Okie Dokie, I posted it and cc'd ya.
>>
>> Also I took a look at your patches.
>> 0001-import-crate-Don-t-include-optional-dependencies.patch should work
>> just fine with my patch. But
>> 0003-import-crate-Honor-versioned-dependencies-when-impor.patch will not
>> work.
>>
>> I took a different route here with the naming. If you are interested take
>> a look take a look at my second patch. (recusive-import-semver) only will
>> add the version number to the name if the crate being imported is not the
>> latest version. I thought this was more inline with the canonical names,
>> but if always adding version number the export symbol is desirable it will
>> simplify things.
>>
> 
> I'll take a look at it in a minute. I figured with the versioned
> requirements we would always want to be specific in version numbers for
> crate dependents so I figured it made sense. Also, if we did want to
> provide an unversioned '-latest' version we could declare an extra
> variable '(define-public rust-libc rust-libc-0.2)' and now rust-libc
> points to rust-libc-0.2.
> 
>> Also I added a function (find-packages-by-name*/direct) to packages.scm
>> which will return the export symbol of a package that already exists. I
>> use this in case there are some non-canocal export name already added.
>>

I added the no-optional-dep logic to the recusive-semver patch
(https://issues.guix.gnu.org/issue/38408), but it seems to break
packages. I'm testing on the recursive importer on "hello-cli". Attach
is the patch to add the logic and the  before and after output for "guix
import crate -r hello-cli". Removing all the optional deps breaks clap
here for some reason which I haven't figured out.

diff --git a/guix/import/crate.scm b/guix/import/crate.scm
index da92c43b8c..355aaa140a 100644
--- a/guix/import/crate.scm
+++ b/guix/import/crate.scm
@@ -2,6 +2,7 @@
 ;;; Copyright © 2016 David Craven <[email-masked]>
 ;;; Copyright © 2019 Ludovic Courtès <[email-masked]>
 ;;; Copyright © 2019 Martin Becze <[email-masked]>
+;;; Copyright © 2019 Efraim Flashner <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -88,6 +89,7 @@
   (id            crate-dependency-id "crate_id")  ;string
   (kind          crate-dependency-kind "kind"     ;'normal | 'dev | 'build
                  string->symbol)
+  (optional      crate-dependency-optional "optional") ; 'true | 'false
   (requirement   crate-dependency-requirement "req")) ;string
 
 (define (lookup-crate name)
@@ -108,12 +110,16 @@ record or #f if it was not found."
 (define (crate-version-dependencies version)
   "Return the list of <crate-dependency> records of VERSION, a
 <crate-version>."
+  (define (optional-dependency? dependency)
+    (eq? (crate-dependency-optional dependency) #t))
+
   (let* ((path (assoc-ref (crate-version-links version) "dependencies"))
          (url  (string-append (%crate-base-url) path)))
     (match (assoc-ref (or (json-fetch url) '()) "dependencies")
       ((? vector? vector)
        (filter (lambda (dep)
-                 (not (eq? (crate-dependency-kind dep) 'dev)))
+                 (not (or (eq? (crate-dependency-kind dep) 'dev)
+                          (optional-dependency? dep))))
                (map json->crate-dependency (vector->list vector))))
       (_
        '()))))