Subject: [PATCH v4 7/8] gnu: Add imhex-pattern-language.

From: Sergio Pastor Pérez <[email-masked]>
Date: Tue, 27 Aug 2024 00:01:09 +0200

* gnu/packages/hexedit.scm (imhex-pattern-language): New variable.

Change-Id: I641bebed0bea9b2c8aca87f54d0fb457064a07d7
---
 gnu/packages/hexedit.scm | 74 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 73 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/hexedit.scm b/gnu/packages/hexedit.scm
index 668699a28c..e5f58fcce0 100644
--- a/gnu/packages/hexedit.scm
+++ b/gnu/packages/hexedit.scm
@@ -22,15 +22,20 @@
 
 (define-module (gnu packages hexedit)
   #:use-module ((guix licenses) #:prefix license:)
+  #:use-module (guix gexp)
   #:use-module (guix packages)
   #:use-module (gnu packages)
   #:use-module (gnu packages autotools)
   #:use-module (gnu packages compression)
   #:use-module (gnu packages man)
+  #:use-module (gnu packages cpp)
+  #:use-module (gnu packages gcc)
+  #:use-module (gnu packages python)
   #:use-module (gnu packages ncurses)
   #:use-module (guix download)
   #:use-module (guix git-download)
-  #:use-module (guix build-system gnu))
+  #:use-module (guix build-system gnu)
+  #:use-module (guix build-system cmake))
 
 (define-public hexedit
   (package
@@ -94,6 +99,73 @@ (define-public ht
     (home-page "https://hte.sourceforge.net/")
     (license license:gpl2)))
 
+;; NOTE: `imhex-pattern-language' should improve it's build system to be used
+;; easily outside of ImHex. It should update it's shared library install target
+;; to deploy the header files and it should create the pertinent
+;; 'libpl-config.cmake' and 'libpl-config-version.cmake' files.
+(define-public imhex-pattern-language
+  (package
+    (name "imhex-pattern-language")
+    (version "1.35.4")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/WerWolv/PatternLanguage")
+                    (commit (string-append "ImHex-v" version))
+                    (recursive? #t)))
+              (file-name (git-file-name name version))
+              (sha256
+               (base32
+                "0riphslp3rca6z6f5zfvsisdh94apijfi03s7yap1vjnf6i93pks"))
+              (snippet
+               #~(begin
+                   (use-modules (guix build utils))
+                   ;; NOTE: the `throwing-ptr' hasn't been updated in 6 years and
+                   ;; the testsuite expects to use an outdated version of Conan,
+                   ;; since this library if not interesting to have it in Guix
+                   ;; it will remain bundled.
+                   ;; NOTE: `libwolf' does not have an install target. Until the
+                   ;; maintainers create one, it will be bundled.
+                   (with-directory-excursion "external"
+                     (for-each (lambda (path)
+                                 (delete-file-recursively path))
+                               '("nlohmann_json" "cli11")))))))
+    (build-system cmake-build-system)
+    (arguments
+     (list
+      #:configure-flags
+      ''("-DLIBPL_SHARED_LIBRARY=ON"
+         "-DLIBPL_ENABLE_TESTS=ON"
+
+         "-DUSE_SYSTEM_NLOHMANN_JSON=ON"
+         "-DUSE_SYSTEM_CLI11=ON"
+         ;; NOTE: the `fmt' package is vendored since it needs
+         ;; a specific commit. Until there is a compatible
+         ;; release, there is no interest in creating a Guix
+         ;; package for it.
+         "-DUSE_SYSTEM_FMT=OFF")
+      #:phases
+      #~(modify-phases %standard-phases
+          (add-after 'unpack 'fix-rel-paths
+            (lambda _
+              (substitute* "tests/include/test_patterns/test_pattern_format.hpp"
+                (("../tests/files/export/")
+                 "../source/tests/files/export/"))))
+          (add-after 'build 'build-tests
+            (lambda _
+              (invoke "make" "pattern_language_tests" "plcli")))
+          (add-before 'check 'plcli-integration-tests
+            (lambda _
+              (with-directory-excursion "../source"
+                (invoke "python3"
+                        "tests/integration/integration.py"
+                        "../build/cli/plcli")))))))
+    (native-inputs (list cli11 gcc-14 nlohmann-json python))
+    (home-page "https://imhex.werwolv.net")
+    (synopsis "The Pattern Language used by the ImHex Hex Editor")
+    (description "The Pattern Language used by the ImHex Hex Editor.")
+    (license license:lgpl2.1)))
+
 (define-public bvi
   (package
     (name "bvi")
-- 
2.45.2