[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: New Flymake rewrite in emacs-26
From: |
João Távora |
Subject: |
Re: New Flymake rewrite in emacs-26 |
Date: |
Wed, 11 Oct 2017 01:07:19 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.0.60 (gnu/linux) |
Noam Postavsky <address@hidden> writes:
> I've also hardly ever used flymake, so this may be nonsense, but maybe
> you could run 'make --just-print foo.o' to get the exact shell
> commands for compiling foo.c. This would bypass any need to know
> details of compilation beyond figuring out the target name from the
> source.
Thanks for the idea. Certainly not nonsense, but also not a silver
bullet, since Makefiles can invoke gcc in arbitrary ways that fool a
guesser. Still, it’s probably decent in a fair amount of cases, and I’m
giving it a go to see if it works with Emacs sources and perhaps some
other GNU projects. I attach my flag-guessing function at the end.
First, my idea is to cache the result of these flags contingent on the
Makefile’s location and mtime. This, I think, is doable. Then I use a
regexp to extract the gcc invocation from the output.
The regexp is very poor but does the job. For the src/fringe.c file the
regexp is
"gcc[[:space:]]+\\(\\(?:-.*\\)*\\)/path/to/fringe.c"
This indeed matches Make’s output and gets me something like this for
the match group 1
-c -Demacs -I. -I. -I../lib -I../lib -isystem /usr/include/freetype2
-isystem /usr/include/alsa -pthread -isystem /usr/include/librsvg-2.0
-isystem /usr/include/gdk-pixbuf-2.0 -isystem /usr/include/libpng16
-isystem /usr/include/cairo -isystem /usr/include/glib-2.0 -isystem
/usr/lib/x86_64-linux-gnu/glib-2.0/include -isystem
/usr/include/pixman-1 -isystem /usr/include/freetype2 -isystem
/usr/include/libpng16 -isystem /usr/include/libpng16 -isystem
/usr/include/libxml2 -isystem /usr/include/dbus-1.0 -isystem
/usr/lib/x86_64-linux-gnu/dbus-1.0/include -pthread -isystem
/usr/include/glib-2.0 -isystem
/usr/lib/x86_64-linux-gnu/glib-2.0/include -isystem
/usr/include/glib-2.0 -isystem
/usr/lib/x86_64-linux-gnu/glib-2.0/include -isystem
/usr/include/freetype2 -isystem /usr/include/freetype2 -isystem
/usr/include/freetype2 -MMD -MF
deps//home/capitaomorte/Source/Emacs/emacs-26/src/fringe.d -MP -isystem
/usr/include/p11-kit-1 -fno-common -W -Wabi -Waddress
[... elided many many -W flags]
-Wno-type-limits -Wno-unused-parameter -Wno-format-nonliteral -g3 -O2
Unfortunately, not all flags make sense for flymake, like the -M family
of flags. Ideally, i’d need a way to parse this big string of flags back
into, say, an alist, and cherry pick the -I, -D, and -W flags from that
set. But I’m afraid split-string will insufficiently deal with escaped
spaces in the output.
Any ideas?
João
PS: My WIP follows
(defvar-local flymake--gcc-cached-flags nil)
(defun flymake-gcc-guess-gcc-flags (&optional trash-cache)
(interactive "P")
(unless (executable-find "make")
(error "Cannot find a suitable make"))
(when trash-cache
(setq flymake--gcc-cached-flags nil))
(catch 'retval
(when-let* ((makefile-dir
(locate-dominating-file default-directory "Makefile"))
(makefile (expand-file-name "Makefile" makefile-dir))
(mtime (file-attribute-modification-time
(file-attributes makefile))))
(cond
((equal (list makefile mtime)
(cdr flymake--gcc-cached-flags))
(when (called-interactively-p 'interactive)
(message "cached hit for flags for this buffer: %s"
(car flymake--gcc-cached-flags)))
(throw 'retval (car flymake--gcc-cached-flags)))
(t
(when-let*
((blob (shell-command-to-string
(format "make -B -C %s -f %s --just-print %s.o"
makefile-dir
makefile
(file-name-sans-extension (buffer-file-name)))))
(match (string-match
(format "gcc[[:space:]]+\\(\\(?:-.*\\)*\\)%s"
(buffer-file-name))
blob))
(flags (split-string (match-string 1 blob) nil t "[[:space:]]")))
(setq flymake--gcc-cached-flags (list flags makefile mtime))
(when (called-interactively-p 'interactive)
(message "cached miss for flags for this buffer: %s" flags))
(throw 'retval flags))))
(when (called-interactively-p 'interactive)
(message "Couldn’t guess flags for this buffer :-(")))))
- Re: New Flymake rewrite in emacs-26, (continued)
Re: New Flymake rewrite in emacs-26, João Távora, 2017/10/10
- Re: New Flymake rewrite in emacs-26, Eli Zaretskii, 2017/10/10
- Re: New Flymake rewrite in emacs-26, João Távora, 2017/10/10
- Re: New Flymake rewrite in emacs-26, Eli Zaretskii, 2017/10/10
- Re: New Flymake rewrite in emacs-26, João Távora, 2017/10/10
- Re: New Flymake rewrite in emacs-26, Eli Zaretskii, 2017/10/10
- Re: New Flymake rewrite in emacs-26, João Távora, 2017/10/10
- Re: New Flymake rewrite in emacs-26, Noam Postavsky, 2017/10/10
- Re: New Flymake rewrite in emacs-26,
João Távora <=
- Re: New Flymake rewrite in emacs-26, Noam Postavsky, 2017/10/10
- Re: New Flymake rewrite in emacs-26, Eli Zaretskii, 2017/10/11
- Re: New Flymake rewrite in emacs-26, Noam Postavsky, 2017/10/11
- Re: New Flymake rewrite in emacs-26, João Távora, 2017/10/11
Re: New Flymake rewrite in emacs-26, Eli Zaretskii, 2017/10/11
Re: New Flymake rewrite in emacs-26, João Távora, 2017/10/11
Re: New Flymake rewrite in emacs-26, Eli Zaretskii, 2017/10/11
Re: New Flymake rewrite in emacs-26, João Távora, 2017/10/11
Re: New Flymake rewrite in emacs-26, Romanos Skiadas, 2017/10/11
Re: New Flymake rewrite in emacs-26, guillaume papin, 2017/10/11