Subject: Re: bug#32769: Packaging Next browser (Common Lisp) [work in progress]

From: Andy Patterson <[email-masked]>
Date: Mon, 15 Oct 2018 02:05:05 -0400

Hi Pierre,

On Sun, 14 Oct 2018 10:27:46 +0200
Pierre Neidhardt <[email-masked]> wrote:

> I won't have time this weekend, so you can go ahead.  Otherwise I'll
> do it next week.

I investigated the problem and I think the build-program procedure is
ok.  It has the option to specify which dependencies you want (maybe
that's what you used?), and I think that's the right option.

You said that you'd tried passing "next" in some way - in this case the
system that the executable will depend on is "next-gtk".  There's a
couple of things here - firstly we need a system for "next" and a
separate one for "next/gtk".  The other is that the resulting systems
will be normalized, so we'll end up with "next-gtk" as the system that
we want to use a dependency for the next-browser executable.

I made these changes and found that I still had problems building
next.  I managed to figure out that it's because next exercises some
less common asd options which makes the bundle that it outputs not
conform to the expectations of the build system.  We'll have to make
some changes to accommodate that, but for now, here's a patch that makes
next build.

I wasn't able to really test whether or not it works - it throws an
exception whenever I press a key.  I was able to find out that its
*active-buffer* variable is nil, which it expects not to be.  If you
want to debug the problems, I recommend doing something like 

$ guix environment --ad-hoc sbcl sbcl-slynk:image next-browser:lib &&
slynk.image
* (slynk:create-server :port 4545)

and then connecting from sly.  You might also pass
(sb-ext:enable-debugger) to the entry program if you prefer that
interface but I haven't tried.  You can then run

|> (asdf:load-system 'next-gtk)
|> (next:start)

to get started.

Hoping that helps,

--
Andy

From 452bb2919ab1db6d819973d655407b1a335b2741 Mon Sep 17 00:00:00 2001
From: Andy Patterson <[email-masked]>
Date: Mon, 15 Oct 2018 01:59:25 -0400
Subject: [PATCH] gnu: next-browser: Fix the build.

* gnu/packages/web-browsers.scm (next-browser-core): New variable.
(next-browser): Inherit from next-browser-core.
---
 gnu/packages/lisp.scm         |  1 +
 gnu/packages/web-browsers.scm | 59 ++++++++++++++++++++++++-----------
 2 files changed, 42 insertions(+), 18 deletions(-)

diff --git a/gnu/packages/lisp.scm b/gnu/packages/lisp.scm
index fcd3156a7..1b390b66d 100644
--- a/gnu/packages/lisp.scm
+++ b/gnu/packages/lisp.scm
@@ -30,6 +30,7 @@
   #:use-module ((guix licenses) #:prefix license:)
   #:use-module (guix packages)
   #:use-module (guix download)
+  #:use-module (guix hg-download)
   #:use-module (guix git-download)
   #:use-module (guix utils)
   #:use-module (guix build-system gnu)
diff --git a/gnu/packages/web-browsers.scm b/gnu/packages/web-browsers.scm
index 0df9180d7..c6844c868 100644
--- a/gnu/packages/web-browsers.scm
+++ b/gnu/packages/web-browsers.scm
@@ -25,6 +25,7 @@
 (define-module (gnu packages web-browsers)
   #:use-module ((guix licenses) #:prefix license:)
   #:use-module (guix packages)
+  #:use-module (guix utils)
   #:use-module (gnu packages)
   #:use-module (gnu packages compression)
   #:use-module (gnu packages databases)
@@ -324,10 +325,10 @@ access.")
 GUI.  It is based on PyQt5 and QtWebKit.")
     (license license:gpl3+)))
 
-(define-public next-browser
+(define-public next-browser-core
   (let ((commit "ccc289b44610ada4ae9c875910af7720e85b546b"))
     (package
-      (name "next-browser")
+      (name "next-browser-core")
       (version (git-version "0.0.8" "1" commit))
       (source (origin
                 (method git-fetch)
@@ -338,11 +339,11 @@ GUI.  It is based on PyQt5 and QtWebKit.")
                  (search-patches "next-fix-duplicate-function.patch"))
                 (sha256
                  (base32
-                  "1pcpb274zb0qm26rrglgcgzg2d2v7j2aja5685swwyq9rcqlbdf4"))))
+                  "0rccs9w49p577l12kgykccxrjkr03rf1cfz9mvxbjzc8g82dya2k"))
+                (file-name (git-file-name name version))))
       (build-system asdf-build-system/sbcl)
       ;; TODO: Move Common Lisp libraries to "native-inputs"?
       ;; TODO: Does runtime depends on gsettings-desktop-schemas and glib-networking?
-      (outputs '("out" "lib"))
       (inputs
        `(("alexandria" ,sbcl-alexandria)
          ("cl-strings" ,sbcl-cl-strings)
@@ -352,26 +353,48 @@ GUI.  It is based on PyQt5 and QtWebKit.")
          ("cl-sqlite" ,sbcl-cl-sqlite)
          ("parenscript" ,sbcl-parenscript)
          ("cl-json" ,sbcl-cl-json)
-         ("unix-opts" ,sbcl-unix-opts)
-         ("cl-cffi-gtk" ,sbcl-cl-cffi-gtk)
-         ("cl-webkit" ,sbcl-cl-webkit)
-         ("lparallel" ,sbcl-lparallel)))
+         ("unix-opts" ,sbcl-unix-opts)))
       (arguments
        `( ;; #:tests? #f
          #:asd-file "next/next.asd"
-         #:asd-system-name "next/gtk"
-         #:phases
-         (modify-phases %standard-phases
-           (add-after 'create-symlinks 'build-program
-             (lambda* (#:key outputs #:allow-other-keys)
-               (build-program
-                (string-append (assoc-ref outputs "out") "/bin/next-browser")
-                outputs
-                #:entry-program '((next:start) 0)))))
-         ))
+         #:asd-system-name "next"))
       (home-page "http://next.atlas.engineer/")
       (synopsis "Emacs-inspired web browser in extensible in Common Lisp")
       (description "Next is a keyboard-oriented, extensible web-browser inspired
 by Emacs and designed for power users.  The application has familiar
 key-bindings, is fully configurable and extensible in Lisp.")
       (license license:expat))))
+
+(define-public next-browser
+  (package
+    (inherit next-browser-core)
+    (name "next-browser")
+    (outputs '("out" "lib"))
+    (inputs
+     `(("next" ,next-browser-core)
+       ("cl-cffi-gtk" ,sbcl-cl-cffi-gtk)
+       ("cl-webkit" ,sbcl-cl-webkit)
+       ("lparallel" ,sbcl-lparallel)))
+    (arguments
+     (substitute-keyword-arguments (package-arguments next-browser-core)
+       ((#:asd-system-name _ #f) "next/gtk")
+       ((#:phases phases '%standard-phases)
+        `(modify-phases ,phases
+           (add-before 'cleanup 'move-bundle
+             (lambda* (#:key outputs #:allow-other-keys)
+               (define lib (assoc-ref outputs "lib"))
+               (define actual-fasl (string-append
+                                    lib
+                                    "/lib/sbcl/next/source/next-gtk.fasl"))
+               (define expected-fasl (string-append
+                                      lib
+                                      "/lib/sbcl/gtk--system.fasl"))
+               (copy-file actual-fasl expected-fasl)
+               #t))
+           (add-after 'create-symlinks 'build-program
+             (lambda* (#:key outputs #:allow-other-keys)
+               (build-program
+                (string-append (assoc-ref outputs "out") "/bin/next-browser")
+                outputs
+                #:entry-program '((next:start) 0)
+                #:dependencies '("next-gtk"))))))))))
-- 
2.19.1