unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#35859] [PATCH] hackage import: Setup.hs generation and revision support
@ 2019-05-22 20:11 Robert Vollmert
  2019-05-23  8:50 ` [bug#35859] line ending fix Robert Vollmert
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Robert Vollmert @ 2019-05-22 20:11 UTC (permalink / raw)
  To: 35859

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

These patches are on top of

https://debbugs.gnu.org/cgi/bugreport.cgi?bug=35812 (fix cabal tests)
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=35846 (braced properties)

- substitute missing Setup.hs and remove manual per-package workarounds
- handle hackage metadata revisions

I believe the code works, but some may not be the most idiomatic scheme
code. Particularly around building the quoted argument list and returning
a pair of cabal data and hash.


[-- Attachment #2: 0001-gnu-ghc-easy-plot-remove-superfluous-Setup.hs-rename.patch --]
[-- Type: application/octet-stream, Size: 1289 bytes --]

From 44c8df36d718940bcb1081e17dad17e2df42dd78 Mon Sep 17 00:00:00 2001
From: Robert Vollmert <rob@vllmrt.net>
Date: Fri, 17 May 2019 16:28:44 +0200
Subject: [PATCH 1/5] gnu: ghc-easy-plot: remove superfluous Setup.hs rename
 step

haskell-build-system already uses whichever of Setup.hs and
Setup.lhs exists.

* gnu/packages/haskell.scm (ghc-easy-plot): don't rename
Setup.lhs to Setup.hs
---
 gnu/packages/haskell.scm | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/gnu/packages/haskell.scm b/gnu/packages/haskell.scm
index 61c6119322..c40581a8cd 100644
--- a/gnu/packages/haskell.scm
+++ b/gnu/packages/haskell.scm
@@ -8063,10 +8063,6 @@ interface for statistics based on hmatrix and GSL.")
         (base32 "18kndgvdj2apjpfga6fp7m16y1gx8zrwp3c5vfj03sx4v6jvciqk"))))
     (build-system haskell-build-system)
     (propagated-inputs `(("gnuplot" ,gnuplot)))
-    (arguments
-     `(#:phases (modify-phases %standard-phases
-                  (add-after 'unpack 'fix-setup-suffix
-                    (lambda _ (rename-file "Setup.lhs" "Setup.hs") #t)))))
     (home-page "https://hub.darcs.net/scravy/easyplot")
     (synopsis "Haskell plotting library based on gnuplot")
     (description "This package provides a plotting library for
-- 
2.21.0


[-- Attachment #3: 0002-guix-haskell-build-system-correct-haddock-phase-docu.patch --]
[-- Type: application/octet-stream, Size: 958 bytes --]

From 59fa86edcda6769bd5d9fb90342302a26e231e65 Mon Sep 17 00:00:00 2001
From: Robert Vollmert <rob@vllmrt.net>
Date: Fri, 17 May 2019 18:58:55 +0200
Subject: [PATCH 2/5] guix: haskell-build-system: correct haddock phase
 documentation

* guix/build/haskell-build-system.scm (haddock): Correct docstring
---
 guix/build/haskell-build-system.scm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/guix/build/haskell-build-system.scm b/guix/build/haskell-build-system.scm
index 23d97e6602..5c5b32322b 100644
--- a/guix/build/haskell-build-system.scm
+++ b/guix/build/haskell-build-system.scm
@@ -260,7 +260,7 @@ given Haskell package."
   #t)
 
 (define* (haddock #:key outputs haddock? haddock-flags #:allow-other-keys)
-  "Run the test suite of a given Haskell package."
+  "Generate haddock documentation of a given Haskell package."
   (when haddock?
     (run-setuphs "haddock" haddock-flags))
   #t)
-- 
2.21.0


[-- Attachment #4: 0003-guix-haskell-build-system-generate-Setup.hs-if-not-e.patch --]
[-- Type: application/octet-stream, Size: 1721 bytes --]

From 9c2c8202f490a20340e2db5522a5813f0dd7183f Mon Sep 17 00:00:00 2001
From: Robert Vollmert <rob@vllmrt.net>
Date: Fri, 17 May 2019 16:26:31 +0200
Subject: [PATCH 3/5] guix: haskell-build-system: generate Setup.hs if not
 exists

The default Setup.hs is boilerplate that is frequently left out of
source packages, causing build failure for package definitions as
generated by `guix import hackage`. Compare
<https://github.com/phadej/time-compat/issues/4>

* guix/build/haskell-build-system.scm: Generate Setup.hs if missing,
after unpack phase.
---
 guix/build/haskell-build-system.scm | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/guix/build/haskell-build-system.scm b/guix/build/haskell-build-system.scm
index 5c5b32322b..0c648e510f 100644
--- a/guix/build/haskell-build-system.scm
+++ b/guix/build/haskell-build-system.scm
@@ -275,9 +275,21 @@ given Haskell package."
       (_ (error "Could not find a Cabal file to patch."))))
   #t)
 
+(define* (generate-setup #:rest empty)
+  "Generate boilerplate Setup.hs if missing."
+  (when (not (or (file-exists? "Setup.hs")
+                 (file-exists? "Setup.lhs")))
+    (format #t "generating missing Setup.hs~%")
+    (with-output-to-file "Setup.hs"
+      (lambda ()
+        (format #t "import Distribution.Simple~%")
+        (format #t "main = defaultMain~%"))))
+  #t)
+
 (define %standard-phases
   (modify-phases gnu:%standard-phases
     (add-after 'unpack 'patch-cabal-file patch-cabal-file)
+    (add-after 'unpack 'generate-setup generate-setup)
     (delete 'bootstrap)
     (add-before 'configure 'setup-compiler setup-compiler)
     (add-before 'install 'haddock haddock)
-- 
2.21.0


[-- Attachment #5: 0004-gnu-haskell-leave-Setup.hs-generation-to-build-syste.patch --]
[-- Type: application/octet-stream, Size: 3481 bytes --]

From 77952a3fe2fdbe027552149eef9d676b828b9e92 Mon Sep 17 00:00:00 2001
From: Robert Vollmert <rob@vllmrt.net>
Date: Fri, 17 May 2019 16:29:08 +0200
Subject: [PATCH 4/5] gnu: haskell: leave Setup.hs generation to build system

Remove explicit Setup.hs generation from the configure step
now that haskell-build-system does it.

* gnu/packages/haskell.scm (ghc-foundation, ghc-inline-c,
ghc-inline-c-cpp, ghc-rio): Don't generate Setup.hs
---
 gnu/packages/haskell.scm | 42 ----------------------------------------
 1 file changed, 42 deletions(-)

diff --git a/gnu/packages/haskell.scm b/gnu/packages/haskell.scm
index c40581a8cd..f12371f3ce 100644
--- a/gnu/packages/haskell.scm
+++ b/gnu/packages/haskell.scm
@@ -9688,16 +9688,6 @@ packages.")
         (base32
          "1q43y8wfj0wf9gdq2kzphwjwq6m5pvryy1lqgk954aq5z3ks1lsf"))))
     (build-system haskell-build-system)
-    (arguments
-     `(#:phases
-       (modify-phases %standard-phases
-         (add-after 'unpack 'add-setup-script
-           (lambda _
-             ;; The usual "Setup.hs" script is missing from the source.
-             (with-output-to-file "Setup.hs"
-               (lambda ()
-                 (format #t "import Distribution.Simple~%")
-                 (format #t "main = defaultMain~%"))))))))
     (inputs `(("ghc-basement" ,ghc-basement)))
     (home-page "https://github.com/haskell-foundation/foundation")
     (synopsis "Alternative prelude with batteries and no dependencies")
@@ -10575,16 +10565,6 @@ widths to the Char type.")
         (base32
          "064h8a4hp53a479d3ak0vmqbx8hi0cpg7zn4wp23rjy26dka8p7g"))))
     (build-system haskell-build-system)
-    (arguments
-     `(#:phases
-       (modify-phases %standard-phases
-         (add-after 'unpack 'add-setup-script
-           (lambda _
-             ;; The usual "Setup.hs" script is missing from the source.
-             (with-output-to-file "Setup.hs"
-               (lambda ()
-                 (format #t "import Distribution.Simple~%")
-                 (format #t "main = defaultMain~%"))))))))
     (inputs
      `(("ghc-exceptions" ,ghc-exceptions)
        ("ghc-hashable" ,ghc-hashable)
@@ -11107,17 +11087,6 @@ DOS/Windows paths and markup languages (such as XML).")
         (base32
          "0vbfrsqsi7mdziqsnj68bsqlwbqxxhvrmy9rv6w8z18d1m8w3n6h"))))
     (build-system haskell-build-system)
-    (arguments
-     `(#:phases
-       (modify-phases %standard-phases
-         (add-after 'unpack 'create-Setup.hs
-           (lambda _
-             (with-output-to-file "Setup.hs"
-               (lambda _
-                 (display "\
-import Distribution.Simple
-main = defaultMain")))
-             #t)))))
     (inputs
      `(("ghc-ansi-wl-pprint" ,ghc-ansi-wl-pprint)
        ("ghc-cryptohash" ,ghc-cryptohash)
@@ -11251,17 +11220,6 @@ handling wrong.")
         (base32
          "1rk7fmpkmxw9hhwr8df29kadnf0ybnwj64ggdbnsdrpfyhnkisci"))))
     (build-system haskell-build-system)
-    (arguments
-     `(#:phases
-       (modify-phases %standard-phases
-         (add-after 'unpack 'create-Setup.hs
-           (lambda _
-             (with-output-to-file "Setup.hs"
-               (lambda _
-                 (display "\
-import Distribution.Simple
-main = defaultMain")))
-             #t)))))
     (inputs
      `(("ghc-inline-c" ,ghc-inline-c)
        ("ghc-safe-exceptions" ,ghc-safe-exceptions)))
-- 
2.21.0


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

From 3b899cfd69dbc19fa542a0a790bee124868058ca 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 383702f2be..97105eb154 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
@@ -640,13 +641,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)
@@ -840,6 +842,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
@@ -858,7 +861,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..fe0c6d13e4 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 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 (canonical-newline-port 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 (canonical-newline-port 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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-05-24 15:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-22 20:11 [bug#35859] [PATCH] hackage import: Setup.hs generation and revision support Robert Vollmert
2019-05-23  8:50 ` [bug#35859] line ending fix Robert Vollmert
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

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).