Subject: Re: [bug#44191] gnu: Add kristall

From: Nicolò Balzarotti <[email-masked]>
Date: Sun, 25 Oct 2020 17:47:01 +0100

Hi Chris!

Thanks for the review.

I tried, but:
1. breeze is a different package from the ones in the repo (url is
https://github.com/Alexhuszagh/BreezeStyleSheets).  It does not seems to
be compiled, I can try to package it.
2. there are files in lib/cmark that are not present in the cmark
distribution (thei are .h files generated by their .h.in), so I cannot
extract our cmark source directly
   - I tried keeping those files, but build fails [[failed-build]].  Not sure if it's
   a patched version or if it's an older one.  But I can investigate
   probably
3. Should I do the same for fonts file? It depends on Noto (that we have
in the store) and on OpenMoji (I can package it)

Just for reference, I attached the current WIP package definition
([[current-package-definition]] which is getting complex.  Is there a
better way to achieve the "delete a folder, but keep some file"?)

Thanks!
Nicolò

#+name: failed-build
#+begin_example 
../src/renderers/markdownrenderer.cpp: In function ‘QString extractNodeText(const cmark_node&)’:
../src/renderers/markdownrenderer.cpp:102:48: error: ‘const cmark_node {aka const struct cmark_node}’ has no member named ‘data’
     return QString::fromUtf8((char const*)node.data, node.len);
                                                ^~~~
../src/renderers/markdownrenderer.cpp:102:59: error: ‘const cmark_node {aka const struct cmark_node}’ has no member named ‘len’
     return QString::fromUtf8((char const*)node.data, node.len);
                                                           ^~~
../src/renderers/markdownrenderer.cpp: In function ‘void renderNode(RenderState&, const cmark_node&, QTextCharFormat)’:
../src/renderers/markdownrenderer.cpp:262:67: error: invalid cast from type ‘const cmark_chunk’ to type ‘char*’
         QUrl absolute_url = QString::fromUtf8((char*)node.as.link.url);
#+end_example

#+name: current-package-definition
#+begin_src scheme
(define-public kristall
  ;; Fixes to the build system applied after the latest tag
  ;; Use tagged release when updating
  (let ((commit "b684f94f1af9a19c1a6fd70d72097a13b75e1ca6")
        (revision "1"))
    (package
      (name "kristall")
      (version (string-append "0.3-" revision "." (string-take commit 7)))
      (source
       (origin
         (method git-fetch)
         (uri (git-reference
               (url "https://github.com/MasterQ32/kristall")
               (commit commit)))
         (file-name (git-file-name name version))
         (sha256
          (base32
           "0kbn98pn8iplqkg7gxx4nysvgsn1621z95ynfr2f9jhsfsgz4r0z"))
         (modules '((guix build utils) (ice-9 match)))
         (snippet
          '(begin
             ;; /gnu/store/qy99msdihnam407659xdqdb4p99f0ava-font-google-noto-20171025/share/fonts/truetype/NotoColorEmoji.ttf
             ;; Remove bundled programs.
             ;; kristall requires some files in the cmark dir that are not
             ;; available in cmark sources.  Move it away from the directory
             ;; and then back in
             (with-directory-excursion "lib"
               (let ((files-to-keep '(("cmark/cmark.pri" "cmark.pri")
                                      ("cmark/src/config.h" "config.h")
                                      ("cmark/src/cmark.h" "cmark.h")
                                      ("cmark/src/cmark_export.h" "cmark_export.h")
                                      ("cmark/src/cmark_version.h" "cmark_version.h"))))
                 ;; Copy away files to keep
                 (map (match-lambda ((src . (dest)) (rename-file src dest)))
                      files-to-keep)
                 ;; Delete extra (bundled) files
                 (map (lambda (dir) (delete-file-recursively dir))
                      '("cmark" ;; "BreezeStyleSheets"
                        ))
                 ;; Put files to keep back in their original place
                 (mkdir-p "cmark/src")
                 (map (match-lambda ((dest . (src)) (rename-file src dest)))
                      files-to-keep)))
             ;; Remove bundled fonts
             (delete-file-recursively "fonts")
             #t))))
      (build-system gnu-build-system)
      (arguments
       `(#:modules ((guix build gnu-build-system)
                    (guix build qt-utils)
                    (guix build utils))
         #:imported-modules (,@%gnu-build-system-modules
                             (guix build qt-utils))
         #:make-flags
         (list (string-append "PREFIX=" %output))
         #:phases
         (modify-phases %standard-phases
           (delete 'configure)          ; no ./configure script
           (delete 'check)              ; no check target
           (add-after 'unpack 'replace-bundled-libs
             (lambda* (#:key inputs #:allow-other-keys)
               (let ((cmark (assoc-ref inputs "cmark-sources"))
                     ;; (breeze (assoc-ref inputs "breeze-sources"))
                     )
                 ;; (invoke "tar" "-xf" breeze "-C" "./lib/")
                 ;; (rename-file "./lib/breeze-5.19.5" "./lib/BreezeStyleSheets")
                 (invoke "tar" "-xf" cmark "-C" "./lib/cmark" "--strip-components" "1")
                 #t)))
           (add-before 'build 'set-program-version
             ;; runs git describe --tags by default
             (lambda _
               ;; configure.ac relies on ‘git --describe’ to get the version.
               ;; Patch it to just return the real version number directly.
               (substitute* "src/kristall.pro"
                 (("(KRISTALL_VERSION=).*" _ match)
                  (string-append match ,version "\n")))))
           (add-after 'install 'wrap-program
             (lambda* (#:key outputs #:allow-other-keys)
               (let ((out (assoc-ref outputs "out")))
                 (wrap-qt-program out "kristall"))
               #t)))))
      (inputs
       `(("breeze-sources" ,(package-source breeze-assets))
         ("cmark-sources" ,(package-source cmark))
         ("openssl" ,openssl)
         ("qtbase" ,qtbase)
         ("qtmultimedia" ,qtmultimedia)
         ("qtsvg" ,qtsvg)))
      (home-page "https://github.com/MasterQ32/kristall")
      (synopsis "Small-internet graphical client")
      (description "Graphical small-internet client with with many features
including multi-protocol support (gemini, http, https, gopher, finger),
bookmarks, TSL certificates management, outline generation, tabbed interface
and more.")
      (license license:gpl3))))
#+end_src

Christopher Baines <[email-masked]> writes:

> Nicolò Balzarotti <[email-masked]> writes:
>
>> Hi guix!
>>
>> This patch adds kristall, a qt browser for gemini and gopher.
>>
>> There were some problems with the latest tagged version (V0.3), such as
>> directories that had to be created manually before install.  I preferred
>> to use the latest commit (as the author still does not know when a new
>> release will happen).  Let me know if it's fine.
>>
>> Without the wrap-qt-program icons were missing.
>>
>> guix lint reports no warnings.
>
> Hey!
>
> Thanks for the patch.
>
> I've had a quick look, and spotted one thing. The Git repository
> includes lib/BreezeStyleSheets and lib/cmark, which are both packaged
> for Guix (I'm unsure about luis-l-gist). It would be good to look at
> removing/not using the copied code from kristall and using the Guix
> packages instead.
>
> Does that make sense?
>
> Thanks,
>
> Chris