all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Paul Pogonyshev <pogonyshev@gmail.com>
To: Emacs developers <emacs-devel@gnu.org>
Subject: Recursive byte-compilation
Date: Sat, 22 Feb 2020 16:17:59 +0100	[thread overview]
Message-ID: <CAG7BpaqnGqDnjAOr5ZXvPhpVNWnD6ONRZV16iE4bUzet=WP1VQ@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2670 bytes --]

In a certain tool I'm having a situation where I need to install a package
while byte-compiling a file. Since installing a package also involves
byte-compilation, it results in byte-compilation invoked when inside
another byte-compilation. It seems to work _mostly_ fine, but still there
are quirks.

Here is a short program that I created to emulate this scenario:

    (eval-when-compile
      (let ((default-directory (expand-file-name "/tmp/myprivatelib/")))
        (make-directory default-directory t)
        (with-temp-file "thelib.el"
          (insert "(defun im-a-library-function ()\n"
                  "  (trigger-a-warning-here-1))\n"
                  "(provide 'thelib)\n"))
        (byte-compile-file "thelib.el")))

    (defun blabla ()
      (trigger-a-warning-here-2))

To test, run from the command line (having saved it as `main.el'):

    $ emacs --batch --eval "(print (byte-compile-file \"main.el\"))"

The "program" is deliberately written to issue byte-compilation warnings.
First quirk is that the path for outer file (i.e. `main.el') is written
fully, because it is apparently found from `/tmp/myprivatelib':

    In end of data:
    thelib.el:4:1: Warning: the function ‘trigger-a-warning-here-1’ is not
known
       to be defined.

    In end of data:
    ~/test/nested-compilation/main.el:12:1: Warning: the function
       ‘trigger-a-warning-here-2’ is not known to be defined.

    t

If, for a test, you remove the `(byte-compile-file "thelib.el")' form, file
path becomes just `main.el', as expected. In other words, *presence of
inner byte-compilation can affect output of outer*, which doesn't look
correct to me.

Another, more important problem is that the outer byte-compilation will
fail if inner one fails (just e.g. remove a paren from "(provide
'thelib)\n" string):

    In toplevel form:
    thelib.el:3:1: Error: End of file during parsing

    In end of data:
    ~/test/nested-compilation/main.el:12:1: Warning: the function
       ‘trigger-a-warning-here-2’ is not known to be defined.

    nil

It feels wrong, because byte-compilation of `main.el' itself _was
successful_. What did fail was a different and only tangentially related
byte-compilation of `thelib.el'.

Is there a way to completely "insulate" the outer invocation of
`byte-compile-...' from the inner? I.e. maybe my simple program above (and
the real tool) can be just expanded to avoid such problems, while keeping
recursive byte-compilation behavior?

If no, would Emacs be interested in resolving such an issue or would it be
deemed too special and unimportant?

Paul

[-- Attachment #2: Type: text/html, Size: 3623 bytes --]

             reply	other threads:[~2020-02-22 15:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-22 15:17 Paul Pogonyshev [this message]
2020-02-22 19:47 ` Recursive byte-compilation Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAG7BpaqnGqDnjAOr5ZXvPhpVNWnD6ONRZV16iE4bUzet=WP1VQ@mail.gmail.com' \
    --to=pogonyshev@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.