diff mbox series

[bug#57337,v2,2/2] gnu: Add docxbox.

Message ID 20221226145732.1237-3-wz@freeshell.de
State New
Headers show
Series Add docxbox | expand

Commit Message

Wiktor Żelazny Dec. 26, 2022, 2:57 p.m. UTC
* gnu/packages/textutils.scm (docxbox): New variable.
---
 gnu/packages/textutils.scm | 76 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 75 insertions(+), 1 deletion(-)

Comments

Ludovic Courtès Jan. 25, 2023, 10:21 p.m. UTC | #1
Wiktor Żelazny <wz@freeshell.de> skribis:

> * gnu/packages/textutils.scm (docxbox): New variable.

[...]

> +                (snippet '(begin
> +                            (for-each delete-file-recursively
> +                                      '("bin" "vendor/json" "vendor/miniz-cpp"
> +                                        "vendor/tinyxml2"))))))

No need for ‘begin’.

> +      (build-system cmake-build-system)
> +      ;; (native-inputs (list bats)) ; Enable after fixing tests, use bash module
> +      (inputs `(("json-modern-cxx" ,json-modern-cxx)
> +                ("miniz-cpp" ,miniz-cpp)
> +                ("tinyxml2-source" ,(package-source tinyxml2))))

You can write:

  (inputs (list json-modern-cxx miniz-cpp))

and…

> +      (arguments
> +       `(#:phases (modify-phases %standard-phases
> +                    (add-after 'unpack 'unvendor
> +                      (lambda* (#:key inputs #:allow-other-keys)
> +                        (substitute* "CMakeLists.txt"
> +                          (("vendor/miniz-cpp/zip_file.hpp")
> +                           ""))
> +                        (with-directory-excursion "docxbox"
> +                          (substitute* (find-files "." "\\.(cc|h)$")
> +                            (("#include <vendor/json/single_include/")
> +                             "#include <"))
> +                          (substitute* (find-files "." "\\.hpp$")
> +                            (("#include <vendor/miniz-cpp/")
> +                             "#include <")))))
> +                    (add-after 'unpack 'unpack-tinyxml2
> +                      (lambda* (#:key inputs #:allow-other-keys)
> +                        (mkdir-p "vendor/tinyxml2")
> +                        (copy-recursively (assoc-ref inputs "tinyxml2-source")
> +                                          "vendor/tinyxml2")))

… this:

  (arguments
    (list #:phases
          #~(modify-phases …
               (copy-recursively #$(package-source tinyxml2) …)
               …)))

It would be best if it could depend on TinyXML2 directly, rather than
rebuilding it as part of the build process, but I supposed that’s
trickier so we can leave that for later.

Could you send an updated patch, together with the miniz-cpp one?

Thanks in advance!

Ludo’.
Wiktor Żelazny Jan. 28, 2023, 7:50 p.m. UTC | #2
On Wed, Jan 25, 2023 at 11:21:05PM +0100, Ludovic Courtès wrote:

> Could you send an updated patch, together with the miniz-cpp one?

Hi Ludo,

Thanks for reviewing the updated patches. I will work on the
improvements that you’re proposing.

Best regards,

WŻ
diff mbox series

Patch

diff --git a/gnu/packages/textutils.scm b/gnu/packages/textutils.scm
index 151add964e..6c3cb2695b 100644
--- a/gnu/packages/textutils.scm
+++ b/gnu/packages/textutils.scm
@@ -58,6 +58,7 @@  (define-module (gnu packages textutils)
   #:use-module (gnu packages autotools)
   #:use-module (gnu packages base)
   #:use-module (gnu packages compression)
+  #:use-module (gnu packages cpp)
   #:use-module (gnu packages gcc)
   #:use-module (gnu packages golang)
   #:use-module (gnu packages gettext)
@@ -74,7 +75,8 @@  (define-module (gnu packages textutils)
   #:use-module (gnu packages ruby)
   #:use-module (gnu packages slang)
   #:use-module (gnu packages syncthing)
-  #:use-module (gnu packages web))
+  #:use-module (gnu packages web)
+  #:use-module (gnu packages xml))
 
 (define-public dos2unix
   (package
@@ -1522,3 +1524,75 @@  (define-public ack
 easily specify file types, match highlighting, Perl-Compatible Regular
 Expressions, and being faster to type than grep.")
     (license license:artistic2.0)))
+
+(define-public docxbox
+  (let ((commit "7c09cfdfd055fedf72676250eae8f03bb8ef7ed5")
+        (revision "1"))
+    (package
+      (name "docxbox")
+      (version (git-version "0.0.5" revision commit))
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (url "https://github.com/gyselroth/docxbox")
+                      (commit commit)))
+                (file-name (git-file-name name version))
+                (sha256
+                 (base32
+                  "0irccm5siy7k6kjnrmm9pxc4cmc3l30377kqpp6vd6y21nk7yc4w"))
+                (modules '((guix build utils)))
+                (snippet '(begin
+                            (for-each delete-file-recursively
+                                      '("bin" "vendor/json" "vendor/miniz-cpp"
+                                        "vendor/tinyxml2"))))))
+      (build-system cmake-build-system)
+      ;; (native-inputs (list bats)) ; Enable after fixing tests, use bash module
+      (inputs `(("json-modern-cxx" ,json-modern-cxx)
+                ("miniz-cpp" ,miniz-cpp)
+                ("tinyxml2-source" ,(package-source tinyxml2))))
+      (arguments
+       `(#:phases (modify-phases %standard-phases
+                    (add-after 'unpack 'unvendor
+                      (lambda* (#:key inputs #:allow-other-keys)
+                        (substitute* "CMakeLists.txt"
+                          (("vendor/miniz-cpp/zip_file.hpp")
+                           ""))
+                        (with-directory-excursion "docxbox"
+                          (substitute* (find-files "." "\\.(cc|h)$")
+                            (("#include <vendor/json/single_include/")
+                             "#include <"))
+                          (substitute* (find-files "." "\\.hpp$")
+                            (("#include <vendor/miniz-cpp/")
+                             "#include <")))))
+                    (add-after 'unpack 'unpack-tinyxml2
+                      (lambda* (#:key inputs #:allow-other-keys)
+                        (mkdir-p "vendor/tinyxml2")
+                        (copy-recursively (assoc-ref inputs "tinyxml2-source")
+                                          "vendor/tinyxml2")))
+                    (replace 'install
+                      (lambda* (#:key outputs #:allow-other-keys)
+                        (let* ((out (assoc-ref outputs "out"))
+                               (bin (string-append out "/bin")))
+                          (install-file "bin/linux/docxbox" bin)))))
+         #:configure-flags (let* ((out (assoc-ref %outputs "out")))
+                             '("-DCMAKE_CXX_FLAGS=-fpermissive -Wno-error"))
+         ;; Tests depend on a bundled binary in bin/linux/, and even with the
+         ;; binary in place, I could not get them to run. To my understanding,
+         ;; the setup() function in test/functional/_helper.bash is supposed to
+         ;; copy the binary to the test suite directory. However, this does not
+         ;; seem to happen when invoking ./test.sh (make check is not
+         ;; supported), and the script complains about the missing binary in the
+         ;; directory. The fix could be to copy the binary built by the Guix
+         ;; daemon to the test suite directory before invoking ./test.sh, but
+         ;; this is beyond my skills.
+         #:tests? #f))
+      (home-page "https://github.com/gyselroth/docxbox/")
+      (synopsis "Command-line tool for MS Word @file{.docx} templating and
+analysis")
+      (description
+       "@command{docxbox} enables direct and convenient inspection and
+manipulation of XML and media files making up a @file{.docx} file.  The
+capabilities include batch editing, unpacking and indentation for manual
+editing in a text editor and subsequent unindentation and repacking,
+operations on metadata, and diffing")
+      (license license:expat))))