[bug#33215,05/11] guix: Add clojure-utils.

Message ID 871s86hck1.fsf@gmail.com
State New
Headers show
Series
  • build-system: Add 'clojure-build-system'.
Related show

Checks

Context Check Description
cbaines/applying patch success Successfully applied

Commit Message

Alex Vong Oct. 31, 2018, 6:09 a.m. UTC

Comments

Ludovic Courtès Nov. 20, 2018, 9:55 p.m. UTC | #1
Hello!

I’m late to the party but I think there are things worth discussing
here.  Danny, for non-trivial bits, in particular in the (guix …) name
space, I think we should ping people to get more detailed review before
merging.

Alex Vong <alexvong1995@gmail.com> skribis:

> From 857cce37325f01c26f79a6e15e33d7988ea4a0a2 Mon Sep 17 00:00:00 2001
> From: Alex Vong <alexvong1995@gmail.com>
> Date: Sun, 14 Oct 2018 03:09:48 +0800
> Subject: [PATCH 05/11] guix: Add clojure-utils.
>
> * guix/build/clojure-utils.scm: New file.
> * gnu/packages/lisp.scm (clojure)[arguments]: Use it.
> * Makefile.am (MODULES): Add it.

[...]

> +(define-module (guix build clojure-utils)
> +  #:use-module (guix build utils)
> +  #:use-module (ice-9 ftw)
> +  #:use-module (ice-9 regex)
> +  #:use-module (srfi srfi-1)
> +  #:use-module (srfi srfi-26)
> +  #:export (%clojure-regex
> +            define-with-docs
> +            install-doc))
> +
> +(define-syntax-rule (define-with-docs name docs val)
> +  "Create top-level variable named NAME with doc string DOCS and value VAL."
> +  (begin (define name val)
> +         (set-object-property! name 'documentation docs)))

This is not necessarily a bad idea, but in general I’m very much in
favor of consistency: since we don’t use this anywhere else, I’d rather
not have it here either.  We could discuss it separately, but IMO it
shouldn’t be buried in a Clojure patch.

Thus I’d be in favor of using the same style in this file as in the rest
of Guix.

WDYT?

Thanks,
Ludo’.
Alex Vong Nov. 21, 2018, 2:35 p.m. UTC | #2
Hello,

ludo@gnu.org (Ludovic Courtès) writes:

> Hello!
>
> I’m late to the party but I think there are things worth discussing
> here.  Danny, for non-trivial bits, in particular in the (guix …) name
> space, I think we should ping people to get more detailed review before
> merging.
>
> Alex Vong <alexvong1995@gmail.com> skribis:
>
>> From 857cce37325f01c26f79a6e15e33d7988ea4a0a2 Mon Sep 17 00:00:00 2001
>> From: Alex Vong <alexvong1995@gmail.com>
>> Date: Sun, 14 Oct 2018 03:09:48 +0800
>> Subject: [PATCH 05/11] guix: Add clojure-utils.
>>
>> * guix/build/clojure-utils.scm: New file.
>> * gnu/packages/lisp.scm (clojure)[arguments]: Use it.
>> * Makefile.am (MODULES): Add it.
>
> [...]
>
>> +(define-module (guix build clojure-utils)
>> +  #:use-module (guix build utils)
>> +  #:use-module (ice-9 ftw)
>> +  #:use-module (ice-9 regex)
>> +  #:use-module (srfi srfi-1)
>> +  #:use-module (srfi srfi-26)
>> +  #:export (%clojure-regex
>> +            define-with-docs
>> +            install-doc))
>> +
>> +(define-syntax-rule (define-with-docs name docs val)
>> +  "Create top-level variable named NAME with doc string DOCS and value VAL."
>> +  (begin (define name val)
>> +         (set-object-property! name 'documentation docs)))
>
> This is not necessarily a bad idea, but in general I’m very much in
> favor of consistency: since we don’t use this anywhere else, I’d rather
> not have it here either.  We could discuss it separately, but IMO it
> shouldn’t be buried in a Clojure patch.
>
> Thus I’d be in favor of using the same style in this file as in the rest
> of Guix.
>
> WDYT?
>
No problem, I am happy to replace the doc string by a comment
instead. IMO, providing doc string for variables in addition to
procedures is more consistent [in a different way :)] since a procedure
is just a special kind of variable. For example, 'defvar' in Emacs
allows one to specify a doc string.

Besides, I thought it is okay to use custom syntactic form within a
module (as long as it doesn't break other's code). However, I can see
that the way I use it can be confusing since everyone are used to
defining variable via 'define'. Is this what you have in mind when you
wrote that you are in favor of consistency?

> Thanks,
> Ludo’.

Cheers,
Alex
Ludovic Courtès Nov. 21, 2018, 10:12 p.m. UTC | #3
Hi Alex,

Alex Vong <alexvong1995@gmail.com> skribis:

> ludo@gnu.org (Ludovic Courtès) writes:

[...]

>>> +(define-syntax-rule (define-with-docs name docs val)
>>> +  "Create top-level variable named NAME with doc string DOCS and value VAL."
>>> +  (begin (define name val)
>>> +         (set-object-property! name 'documentation docs)))
>>
>> This is not necessarily a bad idea, but in general I’m very much in
>> favor of consistency: since we don’t use this anywhere else, I’d rather
>> not have it here either.  We could discuss it separately, but IMO it
>> shouldn’t be buried in a Clojure patch.
>>
>> Thus I’d be in favor of using the same style in this file as in the rest
>> of Guix.
>>
>> WDYT?
>>
> No problem, I am happy to replace the doc string by a comment
> instead. IMO, providing doc string for variables in addition to
> procedures is more consistent [in a different way :)] since a procedure
> is just a special kind of variable. For example, 'defvar' in Emacs
> allows one to specify a doc string.

Yeah, that’s why I think it’s not necessarily a bad idea in itself, it’s
just something we don’t currently do in Guile Scheme.  :-)

> Besides, I thought it is okay to use custom syntactic form within a
> module (as long as it doesn't break other's code). However, I can see
> that the way I use it can be confusing since everyone are used to
> defining variable via 'define'. Is this what you have in mind when you
> wrote that you are in favor of consistency?

Yes, I think it makes it easier for people to find their way in the code
base and get started hacking it if it has somewhat consistent
conventions.  Of course coding style may vary a bit from module to
module and that’s fine, but overall I think we should try to use the
same “base language” so to speak.

WDYT?

Having said that, I realize I was probably too grumpy when I wrote this,
and I didn’t mention the main point, which is that this Clojure build
system looks really nice to me!  It’ll surely make it easier to add more
Clojure packages—now all we need is an importer to make that even
smoother.  :-)

Thank you,
Ludo’.

Patch

From 857cce37325f01c26f79a6e15e33d7988ea4a0a2 Mon Sep 17 00:00:00 2001
From: Alex Vong <alexvong1995@gmail.com>
Date: Sun, 14 Oct 2018 03:09:48 +0800
Subject: [PATCH 05/11] guix: Add clojure-utils.

* guix/build/clojure-utils.scm: New file.
* gnu/packages/lisp.scm (clojure)[arguments]: Use it.
* Makefile.am (MODULES): Add it.
---
 Makefile.am                  |  2 ++
 gnu/packages/lisp.scm        | 23 +++++--------
 guix/build/clojure-utils.scm | 65 ++++++++++++++++++++++++++++++++++++
 3 files changed, 75 insertions(+), 15 deletions(-)
 create mode 100644 guix/build/clojure-utils.scm

diff --git a/Makefile.am b/Makefile.am
index 8c3df8f39..e2bc4d369 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -12,6 +12,7 @@ 
 # Copyright © 2018 Nils Gillmann <ng0@n0.is>
 # Copyright © 2018 Julien Lepiller <julien@lepiller.eu>
 # Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com>
+# Copyright © 2018 Alex Vong <alexvong1995@gmail.com>
 #
 # This file is part of GNU Guix.
 #
@@ -172,6 +173,7 @@  MODULES =					\
   guix/build/syscalls.scm                       \
   guix/build/gremlin.scm			\
   guix/build/debug-link.scm			\
+  guix/build/clojure-utils.scm			\
   guix/build/emacs-utils.scm			\
   guix/build/java-utils.scm			\
   guix/build/lisp-utils.scm			\
diff --git a/gnu/packages/lisp.scm b/gnu/packages/lisp.scm
index c451aa4c1..ee43e5abf 100644
--- a/gnu/packages/lisp.scm
+++ b/gnu/packages/lisp.scm
@@ -596,6 +596,7 @@  interface.")
          (library-names (match libraries
                           (((library-name _) ...)
                            library-name))))
+
     (package
       (name "clojure")
       (version "1.9.0")
@@ -609,11 +610,13 @@  interface.")
           (base32 "0xjbzcw45z32vsn9pifp7ndysjzqswp5ig0jkjpivigh2ckkdzha"))))
       (build-system ant-build-system)
       (arguments
-       `(#:modules ((guix build ant-build-system)
+       `(#:imported-modules ((guix build clojure-utils)
+                             (guix build guile-build-system)
+                             ,@%ant-build-system-modules)
+         #:modules ((guix build ant-build-system)
+                    (guix build clojure-utils)
                     (guix build java-utils)
                     (guix build utils)
-                    (ice-9 ftw)
-                    (ice-9 regex)
                     (srfi srfi-26))
          #:test-target "test"
          #:phases
@@ -639,18 +642,8 @@  interface.")
                #t))
            (add-after 'build 'build-javadoc ant-build-javadoc)
            (replace 'install (install-jars "./"))
-           (add-after 'install 'install-doc
-             (lambda* (#:key outputs #:allow-other-keys)
-               (let ((doc-dir (string-append (assoc-ref outputs "out")
-                                             "/share/doc/clojure-"
-                                             ,version "/")))
-                 (copy-recursively "doc/clojure" doc-dir)
-                 (for-each (cut install-file <> doc-dir)
-                           (filter (cut string-match
-                                     ".*\\.(html|markdown|md|txt)"
-                                     <>)
-                                   (scandir "./")))
-                 #t)))
+           (add-after 'install-license-files 'install-doc
+             (cut install-doc #:doc-dirs '("doc/clojure/") <...>))
            (add-after 'install-doc 'install-javadoc
              (install-javadoc "target/javadoc/")))))
       (native-inputs libraries)
diff --git a/guix/build/clojure-utils.scm b/guix/build/clojure-utils.scm
new file mode 100644
index 000000000..713dff2d8
--- /dev/null
+++ b/guix/build/clojure-utils.scm
@@ -0,0 +1,65 @@ 
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2018 Alex Vong <alexvong1995@gmail.com>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (guix build clojure-utils)
+  #:use-module (guix build utils)
+  #:use-module (ice-9 ftw)
+  #:use-module (ice-9 regex)
+  #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-26)
+  #:export (%clojure-regex
+            define-with-docs
+            install-doc))
+
+(define-syntax-rule (define-with-docs name docs val)
+  "Create top-level variable named NAME with doc string DOCS and value VAL."
+  (begin (define name val)
+         (set-object-property! name 'documentation docs)))
+
+(define-with-docs %doc-regex
+  "Default regex for matching the base name of top-level documentation files."
+  (format #f
+          "(~a)|(\\.(html|markdown|md|txt)$)"
+          (@@ (guix build guile-build-system)
+              %documentation-file-regexp)))
+
+(define* (install-doc #:key
+                      doc-dirs
+                      (doc-regex %doc-regex)
+                      outputs
+                      #:allow-other-keys)
+  "Install the following to the default documentation directory:
+
+1. Top-level files with base name matching DOC-REGEX.
+2. All files (recursively) inside DOC-DIRS.
+
+DOC-REGEX can be compiled or uncompiled."
+  (let* ((out (assoc-ref outputs "out"))
+         (doc (assoc-ref outputs "doc"))
+         (name-ver (strip-store-file-name out))
+         (dest-dir (string-append (or doc out) "/share/doc/" name-ver "/"))
+         (doc-regex* (if (string? doc-regex)
+                         (make-regexp doc-regex)
+                         doc-regex)))
+    (for-each (cut install-file <> dest-dir)
+              (remove (compose file-exists?
+                               (cut string-append dest-dir <>))
+                      (scandir "./" (cut regexp-exec doc-regex* <>))))
+    (for-each (cut copy-recursively <> dest-dir)
+              doc-dirs)
+    #t))
-- 
2.19.1