Subject: [bug#73876] [PATCH v2 2/3] gnu: Add postgresql-libversion.

From: Nicolas Graves <[email-masked]>
Date: Sun, 20 Oct 2024 16:21:34 +0200

* gnu/packages/version-control.scm (postgresql-libversion): New variable.
---
 gnu/packages/version-control.scm | 68 ++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)

diff --git a/gnu/packages/version-control.scm b/gnu/packages/version-control.scm
index b14ec77ff5..00e50a9182 100644
--- a/gnu/packages/version-control.scm
+++ b/gnu/packages/version-control.scm
@@ -1570,6 +1570,74 @@ (define-public python-git-multimail
 repository")
     (license license:gpl2)))
 
+(define-public postgresql-libversion
+  (package
+    (name "postgresql-libversion")
+    (version "2.0.1")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/repology/postgresql-libversion")
+             (commit version)))
+       (file-name (git-file-name name version))
+       (sha256
+        (base32 "0g28dbj0zad62irzv051m4acby974f1ya605xfl48i8g3il9fyny"))))
+    (build-system gnu-build-system)
+    (arguments
+     (list
+      #:make-flags #~(list (string-append "DESTDIR=" (getcwd) "/tmp-out"))
+      #:imported-modules `((guix build union)
+                           ,@%default-gnu-imported-modules)
+      #:modules `(,@%default-gnu-imported-modules
+                   (guix build union)
+                   (ice-9 match))
+      #:phases
+      #~(modify-phases %standard-phases
+          (delete 'configure)
+          (delete 'install)
+          (add-after 'build 'pre-install
+            (lambda args
+              (mkdir "tmp-out")
+              (apply (assoc-ref %standard-phases 'install) args)))
+          (add-after 'pre-install 'install
+            (lambda _
+              (let ((tmp-out (string-append (dirname (getcwd)) "/tmp-out")))
+                (copy-recursively
+                 (dirname
+                  (dirname (car (find-files tmp-out "libversion.so"))))
+                 #$output))))
+          (add-after 'install 'prepare-tests
+            (lambda* (#:key inputs tests? #:allow-other-keys)
+              (if tests?
+                  (let ((pg-data (string-append (getcwd) "/../pg-data"))
+                        (pg-union (string-append (getcwd) "/../pg-union")))
+                    (match inputs
+                      (((names . directories) ...)
+                       (union-build pg-union (cons #$output directories))))
+                    (setenv "PATH" (string-append pg-union "/bin:"
+                                                  (getenv "PATH")))
+                    (invoke "initdb" "-D" pg-data)
+                    (invoke "pg_ctl" "-D" pg-data
+                            "-o" (string-append "-k " pg-data)
+                            "-l" (string-append pg-data "/db.log")
+                            "start")
+                    (setenv "PGHOST" pg-data))
+                  (format #t "prepare-tests phase not run~%"))))
+          (replace 'check
+            (lambda* (#:key tests? #:allow-other-keys)
+              (if tests?
+                  (invoke "make" "installcheck")
+                  (format #t "test suite not run~%")))))))
+    (inputs (list libversion postgresql))
+    (native-inputs (list pkg-config))
+    (home-page "https://github.com/repology/postgresql-libversion")
+    (synopsis "PostgreSQL extension for version string comparison")
+    (description "This package provides a PostgreSQL extension with support
+for version string comparison through @code{libversion}.  It is used to
+experiment with @url{https://repology.org, Repology} database dumps.")
+    (license license:expat)))
+
 (define-public python-ghp-import
   (package
     (name "python-ghp-import")
-- 
2.46.0