8

This often trips me up when building Linux kernels. I'll kick of a compile and after a while I realise it's not completed. What's usually happened is because the default config has changed it's waiting for user input in the compilation window. For example I find the compilation window stalled on the following:

-*- mode: compilation; default-directory: "~/lsrc/kvm/kernel-v8.build/" -*-
Compilation started at Tue Nov 25 10:34:20

cd /home/alex/lsrc/kvm/kernel-v8.build && ARCH=arm64 make -j9
  GEN     ./Makefile
scripts/kconfig/conf --silentoldconfig Kconfig
*
* Restart config...
*
*
* File systems
*
Second extended fs support (EXT2_FS) [Y/n/m/?] y
  Ext2 extended attributes (EXT2_FS_XATTR) [N/y/?] n
  Ext2 execute in place support (EXT2_FS_XIP) [N/y/?] n
Ext3 journalling file system support (EXT3_FS) [Y/n/m/?] y
  Default to 'data=ordered' in ext3 (EXT3_DEFAULTS_TO_ORDERED) [N/y/?] n
  Ext3 extended attributes (EXT3_FS_XATTR) [N/y/?] n
The Extended 4 (ext4) filesystem (EXT4_FS) [Y/n/m/?] y
  Ext4 POSIX Access Control Lists (EXT4_FS_POSIX_ACL) [N/y/?] n
  Ext4 Security Labels (EXT4_FS_SECURITY) [N/y/?] n
  EXT4 debugging support (EXT4_DEBUG) [N/y/?] n
JBD (ext3) debugging support (JBD_DEBUG) [N/y/?] n
JBD2 (ext4) debugging support (JBD2_DEBUG) [N/y/?] n
Reiserfs support (REISERFS_FS) [N/m/y/?] n
JFS filesystem support (JFS_FS) [N/m/y/?] n
XFS filesystem support (XFS_FS) [N/m/y/?] n
GFS2 file system support (GFS2_FS) [N/m/y/?] n
Btrfs filesystem support (BTRFS_FS) [N/m/y/?] n
NILFS2 file system support (NILFS2_FS) [N/m/y/?] n
Dnotify support (DNOTIFY) [Y/n/?] y
Inotify support for userspace (INOTIFY_USER) [Y/n/?] y
Filesystem wide access notification (FANOTIFY) [Y/n/?] y
  fanotify permissions checking (FANOTIFY_ACCESS_PERMISSIONS) [Y/n/?] y
Quota support (QUOTA) [N/y/?] n
Kernel automounter version 4 support (also supports v3) (AUTOFS4_FS) [N/m/y/?] n
FUSE (Filesystem in Userspace) support (FUSE_FS) [Y/n/m/?] y
  Character device in Userspace support (CUSE) [Y/n/m/?] y
Overlay filesystem support (OVERLAY_FS) [N/m/y/?] (NEW) 

It would be useful if I could detect this programatically so I could flag a notification in my mode-line. Any idea how I could detect this?

0

1 Answer 1

6

Emacs cannot detect why a child process is waiting. It might wait because it is calling read() on stdin, but it might just as well just perform an expensive computation while optimizing C code.

However, what you can detect is whether the compilation process has written a prompt. Compilation Mode runs compilation-filter-hook whenever it has inserted output from the compilation process into the compilation buffer. You are free to add your own functions to it.

For instance, you could write a function that searches for a particular prompt in the output, and emits a warning:

(defun my-compilation-mode-warn-about-prompt ()
  (save-excursion
    (let ((re '(rx "[" (one-or-more (any "n" "N" "m" "M" "Y" "y") "/") "?]"
                   (optional " (NEW)") (zero-or-more whitespace) buffer-end)))
      (when (re-search-backward re nil 'no-error)
        (lwarn 'emacs :warning "Compilation process in %s seems stalled!"
               (buffer-name))))))

(add-hook 'compilation-filter-hook
          #'my-compilation-mode-warn-about-prompt)

This will popup a warning buffer whenever the compilation process prints a prompt at the end of the buffer. The prompt is recognized by looking for variations of the [Y/n/?] part. I use rx to write a readable regular expression.

This should handle the case where the compilation process prints a prompt and then waits for input. In this case, the prompt will be the last text inserted into the buffer.

It might cause some false-positives (I didn't try), but since it's only a warning, these should be tolerable.

4
  • I've added an example output to my question.
    – stsquad
    Nov 25, 2014 at 10:44
  • @stsquad I updated my answer accordingly. I hope it helps.
    – user227
    Nov 25, 2014 at 13:52
  • I think you may have an unbalanced brace there.
    – stsquad
    Nov 25, 2014 at 14:43
  • @stsquad Oh, sorry, seems that it didn't make it through the copy-pasta channel. Fixed.
    – user227
    Nov 25, 2014 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.