Subject: bug#38613: Disabling bytecompilation on a list of files.

From: Brett Gilio <[email-masked]>
Date: Sun, 15 Dec 2019 16:26:09 -0600

Leo Prikler <[email-masked]> writes:

> Hey Brett.
>
> Am Dienstag, den 14.12.2019, 13:45 -0600 schrieb Brett Gilio:
>> Just forwarding along an idea discussed between Leo Prikler, Tobias,
>> and I on IRC.
> Thanks for the mention ;)

Any time! :)

>
>> Obviously just outright deleting the phase responsible for
>> bytecompilation is not the _best_ solution. So what Leo and I
>> proposed
>> was adding a #:no-bytecomp which takes a list of REGEXP or files that
>> will be excluded from the in-place byte-compilation.
>> 
>> I wanted to float this idea by those of us who use the
>> emacs-build-system regularly.
> I actually came up with an alternative solution, that I already hinted
> at in IRC.  0001 implements a function to disable byte compilation for
> a single file, 0002 applies this to the package in question.  I'm not
> quite sure why the files are not writable and wonder, whether the chmod
> should be added into 0001, but keeping it out of it should hopefully
> prevent abuse.

I am not sure why the file permissions are needing to be set either. On
a git checkout it looks to me like they are the same as the others. I
wonder if it might have something to do with the rename-file method
moving the themes? Idk.

>
> It's rather late and this is just a proof of concept.  I haven't fully
> evaluated the impact this will have on Guix (specifically in the amount
> of rebuilds it will cause).  Also beware of my somewhat ill-formed
> commit messages.  After painfully checking each of the themes for this
> bug however (on my machine, YMMV), I did update the comment for what
> it's worth.

>
> Regards,
> Leo
>
> From 365f5c02876b51cf566224f60cd6d4c6b7023d66 Mon Sep 17 00:00:00 2001
> From: Leo Prikler <[email-masked]>
> Date: Sun, 15 Dec 2019 00:45:08 +0100
> Subject: [PATCH 1/3] guix: emacs-utils: Add emacs-batch-disable-compilation.
>
> * guix/build/emacs-utils.scm (emacs-batch-disable-compilation):
> New procedure.
> ---
>  guix/build/emacs-utils.scm | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/guix/build/emacs-utils.scm b/guix/build/emacs-utils.scm
> index fdacd30dd6..2aa63c3363 100644
> --- a/guix/build/emacs-utils.scm
> +++ b/guix/build/emacs-utils.scm
> @@ -23,6 +23,7 @@
>    #:export (%emacs
>              emacs-batch-eval
>              emacs-batch-edit-file
> +            emacs-batch-disable-compilation
>              emacs-generate-autoloads
>              emacs-byte-compile-directory
>              emacs-substitute-sexps
> @@ -50,6 +51,12 @@
>            (string-append "--visit=" file)
>            (format #f "--eval=~S" expr)))
>  
> +(define (emacs-batch-disable-compilation file)
> +  (emacs-batch-edit-file file
> +    '(progn
> +      (add-file-local-variable 'no-byte-compile t)
> +      (basic-save-buffer))))
> +
>  (define (emacs-generate-autoloads name directory)
>    "Generate autoloads for Emacs package NAME placed in DIRECTORY."
>    (let* ((file (string-append directory "/" name "-autoloads.el"))
> -- 
> 2.24.0
>
>
> From 3f376828d8970c0751b86aef0b49e256ee09287e Mon Sep 17 00:00:00 2001
> From: Leo Prikler <[email-masked]>
> Date: Sun, 15 Dec 2019 00:49:26 +0100
> Subject: [PATCH 2/3] gnu: emacs-doom-themes: Only disable breaking
>  compilations.
>
> * gnu/packages/emacs-xyz.scm (emacs-doom-themes) [phases]:
> <build>: Undelete it.
> <disable-breaking-compilation>: New phase.
> ---
>  gnu/packages/emacs-xyz.scm | 23 ++++++++++++++++++-----
>  1 file changed, 18 insertions(+), 5 deletions(-)
>
> diff --git a/gnu/packages/emacs-xyz.scm b/gnu/packages/emacs-xyz.scm
> index 505594aa0d..1c06a9122d 100644
> --- a/gnu/packages/emacs-xyz.scm
> +++ b/gnu/packages/emacs-xyz.scm
> @@ -19803,6 +19803,10 @@ contrast and few colors.")
>        (arguments
>         `(#:tests? #t
>           #:test-command '("ert-runner")
> +         #:modules ((guix build emacs-build-system)
> +                    (guix build utils)
> +                    (guix build emacs-utils)
> +                    (srfi srfi-1))
>           #:phases
>           (modify-phases %standard-phases
>             (add-after 'unpack 'move-themes
> @@ -19813,12 +19817,21 @@ contrast and few colors.")
>                             (rename-file f (basename f)))
>                           (find-files "./themes" ".*\\.el$"))
>                 #t))
> -           ;; XXX: There is a byte-code overflow issue in the latest
> -           ;; checkout which affects byte-compilation for several theme
> -           ;; files. The easiest way to work around this is to disable
> -           ;; byte-compilation until the issue is resolved.
> +           ;; There is a byte-code overflow issue in the latest checkout
> +           ;; which affects byte-compilation for several (read `most') theme
> +           ;; files.  In order to cope with this issue, we disable
> +           ;; byte-compilation until it is resolved.
>             ;; <https://github.com/hlissner/emacs-doom-themes/issues/314>
> -           (delete 'build))))
> +           (add-after 'move-themes 'disable-breaking-compilation
> +             (lambda _
> +               (for-each (lambda (file)
> +                           (chmod file #o600)
> +                           (emacs-batch-disable-compilation file))
> +                         (cons "doom-themes-ext-neotree.el"
> +                               (lset-difference string-contains
> +                                                (find-files "." ".*-theme.el")
> +                                                '("snazzy" "tomorrow-day"))))
> +               #t)))))
>        (synopsis "Wide collection of color themes for Emacs")
>        (description "Emacs-doom-themes contains numerous popular color themes for
>  Emacs that integrate with major modes like Org-mode.")

Honestly, it looks fine enough to me. At least for a draft. Does anybody
have any objections or feel an urge for a need for addition of something
else? I think this feature is going to be useful, especially for
allowing workarounds in cases like this which will certainly pop up
again in the future.

-- 
Brett M. Gilio
Homepage -- https://scm.pw/
GNU Guix -- https://guix.gnu.org/