From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:470:142:3::10]:35982) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j3hVC-0002Uj-UR for guix-patches@gnu.org; Mon, 17 Feb 2020 09:36:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j3hVB-0008P2-VZ for guix-patches@gnu.org; Mon, 17 Feb 2020 09:36:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:60454) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j3hVB-0008Od-Rz for guix-patches@gnu.org; Mon, 17 Feb 2020 09:36:01 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1j3hVB-0003hG-Ob for guix-patches@gnu.org; Mon, 17 Feb 2020 09:36:01 -0500 Subject: [bug#38408] [PATCH v9 2/8] guix: import: crate: Use semver to resovle module versions Resent-Message-ID: From: Ludovic =?UTF-8?Q?Court=C3=A8s?= References: <7dbe9a73fe56e1116d3207ef3cb9547a32b9a773.1580817140.git.mjbecze@riseup.net> Date: Mon, 17 Feb 2020 15:35:20 +0100 In-Reply-To: <7dbe9a73fe56e1116d3207ef3cb9547a32b9a773.1580817140.git.mjbecze@riseup.net> (Martin Becze's message of "Tue, 4 Feb 2020 07:18:19 -0500") Message-ID: <87y2t17047.fsf@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: Martin Becze Cc: 38408@debbugs.gnu.org, efraim@flashner.co.il, jsoo1@asu.edu Hi Martin & Efraim, Thinking more about it, I=E2=80=99m not sure I fully understand why we need= to pay attention to semver here: Martin Becze skribis: > +(define* (crate->guix-package crate-name #:key version #:allow-other-key= s) > "Fetch the metadata for CRATE-NAME from crates.io, and return the > `package' s-expression corresponding to that package, or #f on failure. > When VERSION is specified, attempt to fetch that version; otherwise fetc= h the > latest version of CRATE-NAME." >=20=20 > + (define (semver-range-contains-string? range version) > + (semver-range-contains? (string->semver-range range) > + (string->semver version))) > + > (define (normal-dependency? dependency) > - (eq? (crate-dependency-kind dependency) 'normal)) > + (or (eq? (crate-dependency-kind dependency) 'build) > + (eq? (crate-dependency-kind dependency) 'normal))) >=20=20 > (define crate > (lookup-crate crate-name)) > @@ -204,21 +218,36 @@ latest version of CRATE-NAME." > (or version > (crate-latest-version crate))) >=20=20 > - (define version* > + (define (find-version crate range) > + "finds the a vesion of a crate that fulfils the semver " > (find (lambda (version) > - (string=3D? (crate-version-number version) > - version-number)) > + (semver-range-contains-string? > + range > + (crate-version-number version))) > (crate-versions crate))) The reason I wonder is that the HTTP API gives us rather precise dependency requirements: --8<---------------cut here---------------start------------->8--- scheme@(guix import crate)> (crate-version-dependencies (car (crate-version= s (lookup-crate "blake2-rfc")))) $8 =3D (#< id: "arrayvec" kind: normal requirement: "^0.4= .6"> #< id: "constant_time_eq" kind: normal requirement: = "^0.1.0"> #< id: "data-encoding" kind: dev requirement: "= ^2.0.0"> #< id: "clippy" kind: normal requirement: "^0.0.= 41">) --8<---------------cut here---------------end--------------->8--- In the example above, the importer could =E2=80=9Cjust=E2=80=9D fetch versi= on 0.4.6 of arrayvec, version 0.1.0 of constant_time_eq, etc., no? It=E2=80=99s an approximation because the caret (^) means more than just th= is, but hopefully it=E2=80=99s a good approximation. Am I missing something? Ludo=E2=80=99.