Subject: [bug#67755] [PATCH v5 8/9] gnu: Add imhex-pattern-language.

From: Sergio Pastor Pérez <[email-masked]>
Date: Tue, 11 Mar 2025 20:15:24 +0100

From: Sergio Pastor Pérez <[email-masked]>

* 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 15bf7db877..2eab13e239 100644
--- a/gnu/packages/hexedit.scm
+++ b/gnu/packages/hexedit.scm
@@ -4,6 +4,7 @@
 ;;; Copyright © 2018, 2020, 2022 Tobias Geerinckx-Rice <[email-masked]>
 ;;; Copyright © 2020 Jakub Kądziołka <[email-masked]>
 ;;; Copyright © 2024 Artyom V. Poptsov <[email-masked]>
+;;; Copyright © 2025 Sergio Pastor Pérez <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -22,17 +23,22 @@
 
 (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 gexp)
   #:use-module (guix utils)
-  #:use-module (guix build-system gnu))
+  #:use-module (guix build-system gnu)
+  #:use-module (guix build-system cmake))
 
 (define-public hexedit
   (package
@@ -137,6 +143,72 @@ (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.37.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 "13mlbclg2r3axv6vz4dsyry5azc6xavcbdkvwan6zyaq9ngk7r3r"))
+       (snippet #~(begin
+                    (use-modules (guix build utils))
+                    (define (delete-files-from-list-recursively . args)
+                      (for-each (lambda (path)
+                                  (delete-file-recursively path)) args))
+                    ;; 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"
+                      (delete-files-from-list-recursively "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.48.1