Subject: [bug#32431] [PATCH] gnu: clementine: Drop dependency on qtwebkit.

From: Pierre Langlois <[email-masked]>
Date: Tue, 14 Aug 2018 22:32:11 +0100

Hi Leo,

Pierre Langlois writes:

> Leo Famulari writes:
>
>> On Mon, Aug 13, 2018 at 10:12:14PM +0100, Pierre Langlois wrote:
>>> That's strange, it works OK for me. I'm on master, which branch are you
>>> on? IIRC this was the error I was getting when sqlite wasn't built with
>>> FTS3 support, hence the sqlite-with-fts3 package (although I'm not sure
>>> what it is).
>>
>> I'm also working on the master branch, Guix on Debian. I can reproduce
>> the error on commit 9285f8bbae9d71139873430c71b7ca7634bda31b like this:
>>
>> ------
>> $ ./pre-inst-env guix environment --pure --ad-hoc clementine -- clementine
>> 22:30:46.067 INFO  main:315                         Clementine-qt5 1.3.1                     
>> __logging_message__22:30:46.071 WARN  unknown                          QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-leo'
>> __logging_message__22:30:46.083 WARN  unknown                          QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-leo'
>> 22:30:46.091 WARN  Database:275                     Couldn't register FTS3 tokenizer :  QSqlError("1", "Unable to fetch row", "fts3tokenize disabled")
>> 22:30:46.092 DEBUG Database:449                     Applying database schema update 13 from ":/schema/schema-13.sql"
>> 22:30:46.092 ERROR Database:577                     db error:  QSqlError("1", "Unable to fetch row", "unknown tokenizer: unicode")
>> 22:30:46.092 ERROR Database:578                     faulty query:  "CREATE VIRTUAL TABLE songs_fts USING fts3(\n  ftstitle, ftsalbum, ftsartist, ftsalbumartist, ftscomposer, ftsgenre, ftscomment,\n  tokenize=unicode\n)"
>> 22:30:46.092 ERROR Database:579                     bound values:  QMap()
>> __logging_message__22:30:46.092 ERROR unknown                          Unable to update music library database
>> ------
>>
>> If it works for you on GuixSD or another distro, we should go ahead and
>> push the patch, and find out why it doesn't work for me later.
>
> Actually, now I can reproduce the error. I already had a database
> created in my home directory by the previous working installation so I
> didn't see the error. If I remove '.config/Clementine' it crashes the
> same way. I don't think it's because of this patch though, which means
> the problem has probably been there a while :-(, I'll investigate when I
> get the time tonight!

OK, it's working now :-). It was indeed unrelated to qtwebkit so here is
a follow-up patch that fixes the issue. I'm not sure of the details, but
there is a pull request [0] that allows us to patch clementine to fix
this, and on top of this, it allows us to use the generic sqlite! It
seems OpenSUSE have also patched clementine this way.

WDYT?

Thanks,
Pierre

[0]: https://github.com/clementine-player/Clementine/pull/5669

>From 304f288f3be2438fe4ecf536728a6dc5579f04d0 Mon Sep 17 00:00:00 2001
From: Pierre Langlois <[email-masked]>
Date: Tue, 14 Aug 2018 22:17:24 +0100
Subject: [PATCH] gnu: clementine: Fix creating initial database.

It seems a recent version of sqlite broke Clementine's first startup. It turns
out we can patch clementine to fix the problem instead of providing a
different sqlite package:
https://github.com/clementine-player/Clementine/pull/5669

* gnu/packages/databases.scm (sqlite-with-fts3): Remove.
* gnu/packages/music.scm (clementine)[inputs]: Replace sqlite-with-fts3 with
sqlite.
[source][patches]: Add clementine-fix-sqlite.patch.
* gnu/packages/patches/clementine-fix-sqlite.patch: New file.
* gnu/local.mk (dist_patch_DATA): Add it.
---
 gnu/local.mk                                  |  1 +
 gnu/packages/databases.scm                    | 16 +------------
 gnu/packages/music.scm                        |  5 ++--
 .../patches/clementine-fix-sqlite.patch       | 23 +++++++++++++++++++
 4 files changed, 28 insertions(+), 17 deletions(-)
 create mode 100644 gnu/packages/patches/clementine-fix-sqlite.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 15e7beac6..ffcd7eb85 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -611,6 +611,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/clang-runtime-asan-build-fixes.patch	\
   %D%/packages/patches/clang-runtime-esan-build-fixes.patch	\
   %D%/packages/patches/classpath-aarch64-support.patch		\
+  %D%/packages/patches/clementine-fix-sqlite.patch		\
   %D%/packages/patches/clementine-remove-crypto++-dependency.patch	\
   %D%/packages/patches/clementine-use-openssl.patch		\
   %D%/packages/patches/clisp-glibc-2.26.patch			\
diff --git a/gnu/packages/databases.scm b/gnu/packages/databases.scm
index c148ba499..ba3a3233a 100644
--- a/gnu/packages/databases.scm
+++ b/gnu/packages/databases.scm
@@ -27,7 +27,7 @@
 ;;; Copyright © 2017 Alex Vong <[email-masked]>
 ;;; Copyright © 2017, 2018 Ben Woodcroft <[email-masked]>
 ;;; Copyright © 2017 Rutger Helling <[email-masked]>
-;;; Copyright © 2017 Pierre Langlois <[email-masked]>
+;;; Copyright © 2017, 2018 Pierre Langlois <[email-masked]>
 ;;; Copyright © 2015, 2017, 2018 Ricardo Wurmus <[email-masked]>
 ;;; Copyright © 2017 Kristofer Buffington <[email-masked]>
 ;;; Copyright © 2018 Amirouche Boubekki <[email-masked]>
@@ -1069,20 +1069,6 @@ is in the public domain.")
        ((#:configure-flags flags)
         `(cons "--enable-fts5" ,flags))))))
 
-;; This is used by Clementine.
-(define-public sqlite-with-fts3
-  (package (inherit sqlite)
-    (name "sqlite-with-fts3")
-    (arguments
-     (substitute-keyword-arguments (package-arguments sqlite)
-       ((#:configure-flags flags)
-        `(list (string-append "CFLAGS=-O2 -DSQLITE_SECURE_DELETE "
-                              "-DSQLITE_ENABLE_UNLOCK_NOTIFY "
-                              "-DSQLITE_ENABLE_DBSTAT_VTAB "
-                              "-DSQLITE_ENABLE_FTS3 "
-                              "-DSQLITE_ENABLE_FTS3_PARENTHESIS "
-                              "-DSQLITE_ENABLE_FTS3_TOKENIZER")))))))
-
 (define-public tdb
   (package
     (name "tdb")
diff --git a/gnu/packages/music.scm b/gnu/packages/music.scm
index cf1e0f82f..7d4aeff99 100644
--- a/gnu/packages/music.scm
+++ b/gnu/packages/music.scm
@@ -238,7 +238,8 @@ score, keyboard, guitar, drum and controller views.")
                       "tinysvcmdns"))
                     #t))
                 (patches (search-patches "clementine-use-openssl.patch"
-                                         "clementine-remove-crypto++-dependency.patch"))))
+                                         "clementine-remove-crypto++-dependency.patch"
+                                         "clementine-fix-sqlite.patch"))))
       (build-system cmake-build-system)
       (arguments
        '(#:test-target "clementine_test"
@@ -281,7 +282,7 @@ score, keyboard, guitar, drum and controller views.")
          ("pulseaudio" ,pulseaudio)
          ("qtbase" ,qtbase)
          ("qtx11extras" ,qtx11extras)
-         ("sqlite" ,sqlite-with-fts3)
+         ("sqlite" ,sqlite)
          ("sparsehash" ,sparsehash)
          ("taglib" ,taglib)))
       (home-page "http://clementine-player.org")
diff --git a/gnu/packages/patches/clementine-fix-sqlite.patch b/gnu/packages/patches/clementine-fix-sqlite.patch
new file mode 100644
index 000000000..f9d44f907
--- /dev/null
+++ b/gnu/packages/patches/clementine-fix-sqlite.patch
@@ -0,0 +1,23 @@
+Patch downloaded from https://github.com/clementine-player/Clementine/pull/5669 .
+
+diff -ruN clementine-1.3.1.565.gd20c2244a.orig/src/core/database.cpp clementine-1.3.1.565.gd20c2244a/src/core/database.cpp
+--- clementine-1.3.1.565.gd20c2244a.orig/src/core/database.cpp	2018-07-07 23:59:24.018540126 +0200
++++ clementine-1.3.1.565.gd20c2244a/src/core/database.cpp	2018-07-08 00:04:47.991551728 +0200
+@@ -265,6 +265,17 @@
+   StaticInit();
+ 
+   {
++
++#ifdef SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER
++    // In case sqlite>=3.12 is compiled without -DSQLITE_ENABLE_FTS3_TOKENIZER
++    // (generally a good idea  due to security reasons) the fts3 support should be enabled explicitly.
++    QVariant v = db.driver()->handle();
++    if (v.isValid() && qstrcmp(v.typeName(), "sqlite3*") == 0) {
++      sqlite3 *handle = *static_cast<sqlite3**>(v.data());
++      if (handle) sqlite3_db_config(handle, SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, 1, NULL);
++    }
++#endif
++
+     QSqlQuery set_fts_tokenizer(db);
+     set_fts_tokenizer.prepare("SELECT fts3_tokenizer(:name, :pointer)");
+     set_fts_tokenizer.bindValue(":name", "unicode");
-- 
2.18.0