Subject: [PATCH v2 4/4] gnu: lua-cqueues: Refactor package definition.

From: Bruno Victal <[email-masked]>
Date: Thu, 31 Aug 2023 16:03:42 +0100

* gnu/packages/lua.scm (make-lua-cqueues): Use G-Expressions.
Drop obsolete phases.
---
 gnu/packages/lua.scm | 149 ++++++++++++++++---------------------------
 1 file changed, 56 insertions(+), 93 deletions(-)

diff --git a/gnu/packages/lua.scm b/gnu/packages/lua.scm
index e68cbc69e8..f0db08fd4f 100644
--- a/gnu/packages/lua.scm
+++ b/gnu/packages/lua.scm
@@ -485,108 +485,71 @@ (define-public lua5.2-sec
   (make-lua-sec "lua5.2-sec" lua-5.2))
 
 (define (make-lua-cqueues name lua lua-ossl)
-  (package
-    (name name)
-    (version "20200726")
-    (source (origin
-              (method git-fetch)
-              (uri (git-reference
-                    (url "https://github.com/wahern/cqueues")
-                    (commit (string-append "rel-" version))))
-              (file-name (git-file-name name version))
-              (sha256
-               (base32
-                "17gwqndlga6gnishgs6wk8cvgwzanddr42yikkg2xd4nanhcg8z9"))))
-    (build-system gnu-build-system)
-    (arguments
-     `(#:modules ((guix build gnu-build-system)
-                  (guix build utils)
-                  (ice-9 string-fun))
-       #:make-flags
-       (let ((out (assoc-ref %outputs "out"))
-             (lua-api-version ,(version-major+minor (package-version lua))))
-         (list ,(string-append "CC=" (cc-for-target))
-               (string-append "LUA_APIS=" lua-api-version)))
-       #:phases
-       (modify-phases %standard-phases
-         (delete 'configure)
-         (delete 'check)
-         (replace 'install
-           (lambda* (#:key make-flags outputs #:allow-other-keys)
-             (let ((out (assoc-ref outputs "out")))
-               (apply invoke "make" "install"
-                      (append make-flags
-                              (list (string-append "DESTDIR=" out)
-                                    "prefix="))))))
-         (add-after 'install 'check
-           (lambda* (#:key inputs outputs make-flags #:allow-other-keys)
-             (let*
-                 ((lua-version ,(version-major+minor (package-version lua)))
-                  (env-suffix (if (equal? lua-version "5.1")
-                                  ""
-                                  (string-append
-                                   "_"
-                                   (string-replace-substring lua-version "." "_"))))
-
-                  (lua-ossl (assoc-ref inputs "lua-ossl"))
-                  (out (assoc-ref outputs "out"))
-
-                  (lua-cpath (lambda (p)
-                               (string-append p "/lib/lua/" lua-version "/?.so")))
-                  (lua-path (lambda (p)
-                              (string-append p "/share/lua/" lua-version "/?.lua"))))
-               ;; The test suite sets Lua-version-specific search-path variables
-               ;; when available so we must do the same, as these take
-               ;; precedence over the generic "LUA_CPATH" and "LUA_PATH"
-               (setenv (string-append "LUA_CPATH" env-suffix)
-                       (string-append
-                        (string-join (map lua-cpath (list out lua-ossl)) ";")
-                        ";;"))
-               (setenv (string-append "LUA_PATH" env-suffix)
-                       (string-append
-                        (string-join (map lua-path (list out lua-ossl)) ";")
-                        ";;"))
-
-               ;; Skip regression tests we expect to fail
-               (with-directory-excursion "regress"
-                 (for-each (lambda (f)
-                             (rename-file f (string-append f ".skip")))
-                           (append
-                            ;; Regression tests that require network
-                            ;; connectivity
+  (let ((lua-api-version (version-major+minor (package-version lua))))
+    (package
+      (name name)
+      (version "20200726")
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (url "https://github.com/wahern/cqueues")
+                      (commit (string-append "rel-" version))))
+                (file-name (git-file-name name version))
+                (sha256
+                 (base32
+                  "17gwqndlga6gnishgs6wk8cvgwzanddr42yikkg2xd4nanhcg8z9"))))
+      (build-system gnu-build-system)
+      (arguments
+       (list
+        #:make-flags
+        #~(list #$(string-append "CC=" (cc-for-target))
+                #$(string-append "LUA_APIS=" lua-api-version)
+                (string-append "prefix=" #$output))
+        #:phases
+        #~(modify-phases %standard-phases
+            (add-after 'unpack 'remove-luajit-tests
+              (lambda _
+                ;; Regression tests that require LuaJIT.
+                (unless (string-prefix? "luajit" #$(package-name lua))
+                  (with-directory-excursion "regress"
+                    (for-each delete-file
+                              '("44-resolvers-gc.lua"
+                                "51-join-defunct-thread.lua"
+                                "73-starttls-buffering.lua"
+                                "87-alpn-disappears.lua"))))))
+            (add-after 'unpack 'remove-networking-tests
+              (lambda _
+                ;; Regression tests that require network connectivity.
+                (with-directory-excursion "regress"
+                  (for-each delete-file
                             '("22-client-dtls.lua"
                               "30-starttls-completion.lua"
                               "62-noname.lua"
-                              "153-dns-resolvers.lua")
-
-                            ;; Regression tests that require LuaJIT
-                            '("44-resolvers-gc.lua"
-                              "51-join-defunct-thread.lua"
-                              "73-starttls-buffering.lua"
-                              "87-alpn-disappears.lua")
-
-                            ;; Regression tests that require Lua 5.3
-                            (if (not (equal? lua-version "5.3"))
-                                '("152-thread-integer-passing.lua")
-                                '()))))
-
-               (apply invoke "make" "check" make-flags)))))))
-    (native-inputs
-     (list m4))
-    (inputs
-     (list lua openssl))
-    (propagated-inputs
-     (list lua-ossl))
-    (home-page "https://25thandclement.com/~william/projects/cqueues.html")
-    (synopsis "Event loop for Lua using continuation queues")
-    (description "The cqueues extension module for Lua implements an event loop
+                              "153-dns-resolvers.lua")))))
+            (add-after 'unpack 'remove-lua5.3-test
+              (lambda _
+                ;; Regression tests that require Lua 5.3 or higher.
+                (unless #$(version>=? lua-api-version "5.3")
+                  (delete-file "regress/152-thread-integer-passing.lua"))))
+            (delete 'configure))))
+      (native-inputs
+       (list m4))
+      (inputs
+       (list lua openssl))
+      (propagated-inputs
+       (list lua-ossl))
+      (home-page "https://25thandclement.com/~william/projects/cqueues.html")
+      (synopsis "Event loop for Lua using continuation queues")
+      (description "The cqueues extension module for Lua implements an event loop
 that operates through the yielding and resumption of coroutines.  It is designed
 to be non-intrusive, composable, and embeddable within existing applications.")
-    (license license:expat)))
+      (license license:expat))))
 
 (define-public lua-cqueues
   (make-lua-cqueues "lua-cqueues" lua lua-ossl))
 
+;; Note: cqueues principally targets Lua 5.2 and above.
+;; <https://25thandclement.com/~william/projects/cqueues.pdf>
 (define-public lua5.1-cqueues
   (make-lua-cqueues "lua5.1-cqueues" lua-5.1 lua5.1-ossl))
 
-- 
2.40.1