unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Robert Vollmert <rob@vllmrt.net>
To: 35859@debbugs.gnu.org
Subject: [bug#35859] line ending fix
Date: Thu, 23 May 2019 10:50:51 +0200	[thread overview]
Message-ID: <5222A8B7-DF2B-4EC3-8E88-B3A3A546DF75@vllmrt.net> (raw)
In-Reply-To: <72F268CC-5FB7-421C-B6F7-B47EAAB823C1@vllmrt.net>

[-- Attachment #1: Type: text/plain, Size: 73 bytes --]

Updated patch to deal with CRLF line endings when computing cabal hash.


[-- Attachment #2: 0005-guix-import-hackage-handle-hackage-revisions.patch --]
[-- Type: application/octet-stream, Size: 7881 bytes --]

From ee2300e5605745a71e77c0972aebc21e826c581a Mon Sep 17 00:00:00 2001
From: Robert Vollmert <rob@vllmrt.net>
Date: Fri, 17 May 2019 22:52:24 +0200
Subject: [PATCH 5/5] guix: import: hackage: handle hackage revisions

Hackage packages can have metadata revision (cabal-file only)
that aren't reflected in the source archive. haskell-build-system
has support for this, but previously `guix import hackage` would
create a definition based on the new cabal file but building using
the old cabal file.

Compare https://debbugs.gnu.org/cgi/bugreport.cgi?bug=35750.

* guix/import/cabal.scm: Parse `x-revision:` property.
* guix/import/hackage.scm: Compute hash of cabal file, and write
cabal-revision build system arguments.
---
 guix/import/cabal.scm   |  7 +++--
 guix/import/hackage.scm | 61 ++++++++++++++++++++++++++++++-----------
 2 files changed, 50 insertions(+), 18 deletions(-)

diff --git a/guix/import/cabal.scm b/guix/import/cabal.scm
index 3028ed2882..312927a573 100644
--- a/guix/import/cabal.scm
+++ b/guix/import/cabal.scm
@@ -40,6 +40,7 @@
             cabal-package?
             cabal-package-name
             cabal-package-version
+            cabal-package-revision
             cabal-package-license
             cabal-package-home-page
             cabal-package-source-repository
@@ -638,13 +639,14 @@ If #f use the function 'port-filename' to obtain it."
 ;; information of the Cabal file, but only the ones we currently are
 ;; interested in.
 (define-record-type <cabal-package>
-  (make-cabal-package name version license home-page source-repository
+  (make-cabal-package name version revision license home-page source-repository
                       synopsis description
                       executables lib test-suites
                       flags eval-environment custom-setup)
   cabal-package?
   (name   cabal-package-name)
   (version cabal-package-version)
+  (revision cabal-package-revision)
   (license cabal-package-license)
   (home-page cabal-package-home-page)
   (source-repository cabal-package-source-repository)
@@ -838,6 +840,7 @@ See the manual for limitations.")))))))
   (define (cabal-evaluated-sexp->package evaluated-sexp)
     (let* ((name (lookup-join evaluated-sexp "name"))
            (version (lookup-join evaluated-sexp "version"))
+           (revision (lookup-join evaluated-sexp "x-revision"))
            (license (lookup-join evaluated-sexp "license"))
            (home-page (lookup-join evaluated-sexp "homepage"))
            (home-page-or-hackage
@@ -856,7 +859,7 @@ See the manual for limitations.")))))))
            (custom-setup (match (make-cabal-section evaluated-sexp 'custom-setup)
                            ((x) x)
                            (_ #f))))
-      (make-cabal-package name version license home-page-or-hackage
+      (make-cabal-package name version revision license home-page-or-hackage
                           source-repository synopsis description executables lib
                           test-suites flags eval-environment custom-setup)))
 
diff --git a/guix/import/hackage.scm b/guix/import/hackage.scm
index 5b80a7ea1d..0bd9034087 100644
--- a/guix/import/hackage.scm
+++ b/guix/import/hackage.scm
@@ -117,9 +117,15 @@ version is returned."
           (#f name)
           (m (match:substring m 1)))))))
 
-(define (hackage-fetch name-version)
-  "Return the Cabal file for the package NAME-VERSION, or #f on failure.  If
-the version part is omitted from the package name, then return the latest
+(define (read-cabal-and-hash port)
+  (let-values (((port get-hash) (open-sha256-input-port port)))
+    (cons
+      (read-cabal (canonical-newline-port port))
+      (bytevector->nix-base32-string (get-hash)))))
+
+(define (hackage-fetch-and-hash name-version)
+  "Return the Cabal file and hash for the package NAME-VERSION, or #f on failure.
+If the version part is omitted from the package name, then return the latest
 version."
   (guard (c ((and (http-get-error? c)
                   (= 404 (http-get-error-code c)))
@@ -127,10 +133,18 @@ version."
     (let-values (((name version) (package-name->name+version name-version)))
       (let* ((url (hackage-cabal-url name version))
              (port (http-fetch url))
-             (result (read-cabal (canonical-newline-port port))))
+             (result (read-cabal-and-hash port)))
         (close-port port)
         result))))
 
+(define (hackage-fetch name-version)
+  "Return the Cabal file for the package NAME-VERSION, or #f on failure.  If
+the version part is omitted from the package name, then return the latest
+version."
+  (match (hackage-fetch-and-hash name-version)
+         ((cabal . hash) cabal)
+         (_              #f)))
+
 (define string->license
   ;; List of valid values from
   ;; https://www.haskell.org
@@ -196,15 +210,19 @@ package being processed and is used to filter references to itself."
                                    (cons own-name ghc-standard-libraries))))
           dependencies))
 
-(define* (hackage-module->sexp cabal #:key (include-test-dependencies? #t))
+(define* (hackage-module->sexp cabal cabal-hash #:key (include-test-dependencies? #t))
   "Return the `package' S-expression for a Cabal package.  CABAL is the
-representation of a Cabal file as produced by 'read-cabal'."
+representation of a Cabal file as produced by 'read-cabal'. CABAL-HASH is
+the hash of the Cabal file."
 
   (define name
     (cabal-package-name cabal))
 
   (define version
     (cabal-package-version cabal))
+
+  (define revision
+    (cabal-package-revision cabal))
   
   (define source-url
     (hackage-source-url name version))
@@ -250,9 +268,17 @@ representation of a Cabal file as produced by 'read-cabal'."
                    (list 'quasiquote inputs))))))
   
   (define (maybe-arguments)
-    (if (not include-test-dependencies?)
-        '((arguments `(#:tests? #f)))
-        '()))
+    (define testargs (if (not include-test-dependencies?)
+                       '(#:tests? #f)
+                       '()))
+    (define revargs  (if (not (string-null? revision))
+                       `(#:cabal-revision (,revision ,cabal-hash))
+                       '()))
+    (define args (append testargs revargs))
+    (if (not (nil? args))
+      (let ((qargs `(,'quasiquote ,args)))
+        `((arguments ,qargs)))
+      '()))
 
   (let ((tarball (with-store store
                    (download-to-store store source-url))))
@@ -293,13 +319,16 @@ symbol 'true' or 'false'.  The value associated with other keys has to conform
 to the Cabal file format definition.  The default value associated with the
 keys \"os\", \"arch\" and \"impl\" is \"linux\", \"x86_64\" and \"ghc\"
 respectively."
-   (let ((cabal-meta (if port
-                         (read-cabal (canonical-newline-port port))
-                         (hackage-fetch package-name))))
-     (and=> cabal-meta (compose (cut hackage-module->sexp <>
-                                     #:include-test-dependencies?
-                                     include-test-dependencies?)
-                                (cut eval-cabal <> cabal-environment))))))
+   (match
+     (if port (read-cabal-and-hash port)
+              (hackage-fetch-and-hash package-name))
+     ((cabal-meta . cabal-hash)
+      (and=> cabal-meta (compose (cut hackage-module->sexp <>
+                                      cabal-hash
+                                      #:include-test-dependencies?
+                                      include-test-dependencies?)
+                                 (cut eval-cabal <> cabal-environment))))
+     (_ #f))))
 
 (define hackage->guix-package
   (memoize hackage->guix-package-impl))
-- 
2.21.0


  reply	other threads:[~2019-05-23  8:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-22 20:11 [bug#35859] [PATCH] hackage import: Setup.hs generation and revision support Robert Vollmert
2019-05-23  8:50 ` Robert Vollmert [this message]
2019-05-23 13:27 ` [bug#35859] fixed patch set, including test fixes Robert Vollmert
2019-05-24 14:56 ` [bug#35859] fixes bug in patch 0003 Robert Vollmert
2019-05-24 14:58 ` [bug#35859] improves output in patch 0010 Robert Vollmert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5222A8B7-DF2B-4EC3-8E88-B3A3A546DF75@vllmrt.net \
    --to=rob@vllmrt.net \
    --cc=35859@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).