[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] scratch/flymake-refactor-cleaner-for-emacs-26 a506cc6 25/3
From: |
Jo�o T�vora |
Subject: |
[Emacs-diffs] scratch/flymake-refactor-cleaner-for-emacs-26 a506cc6 25/39: Fix three Flymake bugs when checking C header files |
Date: |
Mon, 2 Oct 2017 20:12:25 -0400 (EDT) |
branch: scratch/flymake-refactor-cleaner-for-emacs-26
commit a506cc6ab4f0e8e360aad27d645f2ba4a716b630
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Fix three Flymake bugs when checking C header files
The first of these problems is longstanding: if an error-less B.h is
included from error-ridden A.h, flymake's legacy parser will panic
(and disable itself) since it sees a non-zero exit for a clean file.
To fix this, recommend returning 'true' in the documentation for the
check-syntax target.
Another problem was introduced by the parser rewrite. For error
patterns spanning more than one line, point may be left in the middle
of a line and thus render other patterns useless. Those patterns were
written for the old line-by-line parser. To make them useful again,
move to the beginning of line in those situations.
The third problem was also longstanding and happened on newer GCC's:
The "In file included from" prefix confused
flymake-proc-get-real-file-name. Fix this.
Also updated flymake--diag-region to fallback to highlighting a full
line less often.
Add automatic tests to check this.
* lisp/progmodes/flymake-proc.el
(flymake-proc--diagnostics-for-pattern): Fix bug when patterns
accidentally spans more than one line. Don't create
diagnostics without error messages.
(flymake-proc-real-file-name-considering-includes): New
helper.
(flymake-proc-allowed-file-name-masks): Use it.
* lisp/progmodes/flymake.el (flymake-diag-region): Make COL
argument explicitly optional. Only fall back to full line in extreme
cases.
* test/lisp/progmodes/flymake-tests.el
(included-c-header-files): New test.
(different-diagnostic-types): Update.
* test/lisp/progmodes/flymake-resources/Makefile
(check-syntax): Always return success (0) error code.
(CC_OPTS): Add -Wextra
* test/lisp/progmodes/flymake-resources/errors-and-warnings.c
(main): Rewrite comments.
* test/lisp/progmodes/flymake-resources/errors-and-warnings.c:
Include some dummy header files.
* test/lisp/progmodes/flymake-resources/no-problems.h: New file.
* test/lisp/progmodes/flymake-resources/some-problems.h: New file.
* doc/misc/flymake.texi (Example---Configuring a tool called
via make): Recommend adding "|| true" to the check-syntax target.
---
doc/misc/flymake.texi | 4 +--
lisp/progmodes/flymake-proc.el | 33 ++++++++++++++++++----
lisp/progmodes/flymake.el | 22 +++++++++------
test/lisp/progmodes/flymake-resources/Makefile | 4 +--
.../flymake-resources/errors-and-warnings.c | 15 ++++++----
.../lisp/progmodes/flymake-resources/no-problems.h | 1 +
.../progmodes/flymake-resources/some-problems.h | 5 ++++
test/lisp/progmodes/flymake-tests.el | 20 +++++++++++++
8 files changed, 81 insertions(+), 23 deletions(-)
diff --git a/doc/misc/flymake.texi b/doc/misc/flymake.texi
index 1bc416f..01849b7 100644
--- a/doc/misc/flymake.texi
+++ b/doc/misc/flymake.texi
@@ -492,7 +492,7 @@ our case this target might look like this:
@verbatim
check-syntax:
- gcc -o /dev/null -S ${CHK_SOURCES}
+ gcc -o /dev/null -S ${CHK_SOURCES} || true
@end verbatim
@noindent
@@ -504,7 +504,7 @@ Automake variable @code{COMPILE}:
@verbatim
check-syntax:
- $(COMPILE) -o /dev/null -S ${CHK_SOURCES}
+ $(COMPILE) -o /dev/null -S ${CHK_SOURCES} || true
@end verbatim
@node Flymake Implementation
diff --git a/lisp/progmodes/flymake-proc.el b/lisp/progmodes/flymake-proc.el
index 5751162..9413ff4 100644
--- a/lisp/progmodes/flymake-proc.el
+++ b/lisp/progmodes/flymake-proc.el
@@ -66,7 +66,10 @@
:type 'integer)
(defcustom flymake-proc-allowed-file-name-masks
- '(("\\.\\(?:c\\(?:pp\\|xx\\|\\+\\+\\)?\\|CC\\)\\'"
flymake-proc-simple-make-init)
+ '(("\\.\\(?:c\\(?:pp\\|xx\\|\\+\\+\\)?\\|CC\\)\\'"
+ flymake-proc-simple-make-init
+ nil
+ flymake-proc-real-file-name-considering-includes)
("\\.xml\\'" flymake-proc-xml-init)
("\\.html?\\'" flymake-proc-xml-init)
("\\.cs\\'" flymake-proc-simple-make-init)
@@ -419,12 +422,25 @@ Create parent directories as needed."
(condition-case-unless-debug err
(cl-loop
with (regexp file-idx line-idx col-idx message-idx) = pattern
- while (search-forward-regexp regexp nil t)
+ while (and
+ (search-forward-regexp regexp nil t)
+ ;; If the preceding search spanned more than one line,
+ ;; move to the start of the line we ended up in. This
+ ;; preserves the usefulness of the patterns in
+ ;; `flymake-proc-err-line-patterns', which were
+ ;; written primarily for flymake's original
+ ;; line-by-line parsing and thus never spanned
+ ;; multiple lines.
+ (if (/= (line-number-at-pos (match-beginning 0))
+ (line-number-at-pos))
+ (goto-char (line-beginning-position))
+ t))
for fname = (and file-idx (match-string file-idx))
for message = (and message-idx (match-string message-idx))
for line-string = (and line-idx (match-string line-idx))
- for line-number = (and line-string
- (string-to-number line-string))
+ for line-number = (or (and line-string
+ (string-to-number line-string))
+ 1)
for col-string = (and col-idx (match-string col-idx))
for col-number = (and col-string
(string-to-number col-string))
@@ -436,7 +452,7 @@ Create parent directories as needed."
fname)))
for buffer = (and full-file
(find-buffer-visiting full-file))
- if (eq buffer (process-buffer proc))
+ if (and (eq buffer (process-buffer proc)) message)
collect (with-current-buffer buffer
(pcase-let ((`(,beg . ,end)
(flymake-diag-region line-number col-number)))
@@ -1030,6 +1046,13 @@ Use CREATE-TEMP-F for creating temp copy."
'("\\.\\(?:c\\(?:pp\\|xx\\|\\+\\+\\)?\\|CC\\)\\'")
"[ \t]*#[ \t]*include[ \t]*\"\\([[:word:]0-9/\\_.]*%s\\)\""))
+(defun flymake-proc-real-file-name-considering-includes (scraped)
+ (flymake-proc-get-real-file-name
+ (let ((case-fold-search t))
+ (replace-regexp-in-string "^in file included from[ \t*]"
+ ""
+ scraped))))
+
;;;; .java/make specific
(defun flymake-proc-simple-make-java-init ()
(flymake-proc-simple-make-init-impl
'flymake-proc-create-temp-with-folder-structure nil nil "Makefile"
'flymake-proc-get-make-cmdline))
diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el
index 01acb2a..e5b1e2c 100644
--- a/lisp/progmodes/flymake.el
+++ b/lisp/progmodes/flymake.el
@@ -247,9 +247,10 @@ verify FILTER, sort them by COMPARE (using KEY)."
(define-obsolete-face-alias 'flymake-warnline 'flymake-warning "26.1")
(define-obsolete-face-alias 'flymake-errline 'flymake-error "26.1")
-(defun flymake-diag-region (line col)
+(defun flymake-diag-region (line &optional col)
"Compute region (BEG . END) corresponding to LINE and COL.
-Or nil if the region is invalid."
+If COL is nil, return a region just for LINE.
+Return nil if the region is invalid."
(condition-case-unless-debug _err
(let ((line (min (max line 1)
(line-number-at-pos (point-max) 'absolute))))
@@ -266,13 +267,18 @@ Or nil if the region is invalid."
(if (eq (point) beg)
(line-beginning-position 2)
(point)))))
- (if col
- (let* ((beg (progn (forward-char (1- col)) (point)))
+ (if (and col (cl-plusp col))
+ (let* ((beg (progn (forward-char (1- col))
+ (point)))
(sexp-end (ignore-errors (end-of-thing 'sexp)))
- (end (or sexp-end
- (fallback-eol beg))))
- (cons (if sexp-end beg (fallback-bol))
- end))
+ (end (or (and sexp-end
+ (not (= sexp-end beg))
+ sexp-end)
+ (ignore-errors (goto-char (1+ beg)))))
+ (safe-end (or end
+ (fallback-eol beg))))
+ (cons (if end beg (fallback-bol))
+ safe-end))
(let* ((beg (fallback-bol))
(end (fallback-eol beg)))
(cons beg end))))))
diff --git a/test/lisp/progmodes/flymake-resources/Makefile
b/test/lisp/progmodes/flymake-resources/Makefile
index 0f3f397..4944075 100644
--- a/test/lisp/progmodes/flymake-resources/Makefile
+++ b/test/lisp/progmodes/flymake-resources/Makefile
@@ -1,6 +1,6 @@
# Makefile for flymake tests
-CC_OPTS = -Wall
+CC_OPTS = -Wall -Wextra
## Recent gcc (e.g. 4.8.2 on RHEL7) can automatically colorize their output,
## which can confuse flymake. Set GCC_COLORS to disable that.
@@ -8,6 +8,6 @@ CC_OPTS = -Wall
## normally use flymake, so it seems like just avoiding the issue
## in this test is fine. Set flymake-log-level to 3 to investigate.
check-syntax:
- GCC_COLORS= $(CC) $(CC_OPTS) ${CHK_SOURCES}
+ GCC_COLORS= $(CC) $(CC_OPTS) ${CHK_SOURCES} || true
# eof
diff --git a/test/lisp/progmodes/flymake-resources/errors-and-warnings.c
b/test/lisp/progmodes/flymake-resources/errors-and-warnings.c
index 6454dd2..1d38bd6 100644
--- a/test/lisp/progmodes/flymake-resources/errors-and-warnings.c
+++ b/test/lisp/progmodes/flymake-resources/errors-and-warnings.c
@@ -1,10 +1,13 @@
- int main()
+/* Flymake should notice an error on the next line, since
+ that file has at least one warning.*/
+#include "some-problems.h"
+/* But not this one */
+#include "no-problems.h"
+
+int main()
{
- char c = 1000;
+ char c = 1000; /* a note and a warning */
int bla;
- /* The following line should have one warning and one error. The
- warning spans the full line because gcc (at least 6.3.0) points
- places the error at the =, which isn't a sexp.*/
- char c; if (bla == (void*)3);
+ char c; if (bla == (void*)3); /* an error, and two warnings */
return c;
}
diff --git a/test/lisp/progmodes/flymake-resources/no-problems.h
b/test/lisp/progmodes/flymake-resources/no-problems.h
new file mode 100644
index 0000000..19ddc61
--- /dev/null
+++ b/test/lisp/progmodes/flymake-resources/no-problems.h
@@ -0,0 +1 @@
+typedef int no_problems;
diff --git a/test/lisp/progmodes/flymake-resources/some-problems.h
b/test/lisp/progmodes/flymake-resources/some-problems.h
new file mode 100644
index 0000000..165d8dd
--- /dev/null
+++ b/test/lisp/progmodes/flymake-resources/some-problems.h
@@ -0,0 +1,5 @@
+#include <stdio.h>
+
+strange;
+
+sint main();
diff --git a/test/lisp/progmodes/flymake-tests.el
b/test/lisp/progmodes/flymake-tests.el
index fa77a9a..222c8f1 100644
--- a/test/lisp/progmodes/flymake-tests.el
+++ b/test/lisp/progmodes/flymake-tests.el
@@ -122,14 +122,34 @@ SEVERITY-PREDICATE is used to setup
(flymake-tests--with-flymake
("errors-and-warnings.c")
(flymake-goto-next-error)
+ (should (eq 'flymake-error (face-at-point)))
+ (flymake-goto-next-error)
(should (eq 'flymake-note (face-at-point)))
(flymake-goto-next-error)
(should (eq 'flymake-warning (face-at-point)))
(flymake-goto-next-error)
+ (should (eq 'flymake-error (face-at-point)))
+ (flymake-goto-next-error)
+ (should (eq 'flymake-warning (face-at-point)))
+ (flymake-goto-next-error)
+ (should (eq 'flymake-warning (face-at-point)))
+ (let ((flymake-wrap-around nil))
+ (should-error (flymake-goto-next-error nil nil t))) ))
+
+(ert-deftest included-c-header-files ()
+ "Test inclusion of .h header files."
+ (skip-unless (and (executable-find "gcc") (executable-find "make")))
+ (flymake-tests--with-flymake
+ ("some-problems.h")
+ (flymake-goto-next-error)
(should (eq 'flymake-warning (face-at-point)))
(flymake-goto-next-error)
(should (eq 'flymake-error (face-at-point)))
(let ((flymake-wrap-around nil))
+ (should-error (flymake-goto-next-error nil nil t))) )
+ (flymake-tests--with-flymake
+ ("no-problems.h")
+ (let ((flymake-wrap-around nil))
(should-error (flymake-goto-next-error nil nil t))) ))
(defmacro flymake-tests--assert-set (set
- [Emacs-diffs] scratch/flymake-refactor-cleaner-for-emacs-26 a458e1a 26/39: Treat flymake errors as just another type of diagnostic, (continued)
- [Emacs-diffs] scratch/flymake-refactor-cleaner-for-emacs-26 a458e1a 26/39: Treat flymake errors as just another type of diagnostic, Jo�o T�vora, 2017/10/02
- [Emacs-diffs] scratch/flymake-refactor-cleaner-for-emacs-26 4ae24d7 20/39: Flymake's flymake-proc.el backend slightly easier to debug, Jo�o T�vora, 2017/10/02
- [Emacs-diffs] scratch/flymake-refactor-cleaner-for-emacs-26 4d6d56d 27/39: Remove old flymake-display-err-menu-for-current-line, it's useless, Jo�o T�vora, 2017/10/02
- [Emacs-diffs] scratch/flymake-refactor-cleaner-for-emacs-26 ef67227 29/39: Explicitly add a(n empty) keymap for Flymake, Jo�o T�vora, 2017/10/02
- [Emacs-diffs] scratch/flymake-refactor-cleaner-for-emacs-26 2b735b4 08/39: New Flymake variable flymake-diagnostic-types-alist and much cleanup, Jo�o T�vora, 2017/10/02
- [Emacs-diffs] scratch/flymake-refactor-cleaner-for-emacs-26 2971cd0 38/39: Minimal tweak as an attempt to future-proof Flymake API, Jo�o T�vora, 2017/10/02
- [Emacs-diffs] scratch/flymake-refactor-cleaner-for-emacs-26 c1661fc 36/39: Hook Flymake onto proper checkdoc and byte-compile interfaces, Jo�o T�vora, 2017/10/02
- [Emacs-diffs] scratch/flymake-refactor-cleaner-for-emacs-26 38fdbd6 34/39: Capitalize "Flymake" in docstrings and comments, Jo�o T�vora, 2017/10/02
- [Emacs-diffs] scratch/flymake-refactor-cleaner-for-emacs-26 b80d29d 39/39: Start rewriting Flymake manual, Jo�o T�vora, 2017/10/02
- [Emacs-diffs] scratch/flymake-refactor-cleaner-for-emacs-26 b4099cb 18/39: New Flymake API variable flymake-diagnostic-functions, Jo�o T�vora, 2017/10/02
- [Emacs-diffs] scratch/flymake-refactor-cleaner-for-emacs-26 a506cc6 25/39: Fix three Flymake bugs when checking C header files,
Jo�o T�vora <=
- [Emacs-diffs] scratch/flymake-refactor-cleaner-for-emacs-26 de4e13a 17/39: More Flymake cleanup before advancing to backend redesign, Jo�o T�vora, 2017/10/02
- [Emacs-diffs] scratch/flymake-refactor-cleaner-for-emacs-26 fd9e32c 15/39: Flymake highlights GCC info/notes as detected by flymake-proc.el, Jo�o T�vora, 2017/10/02
- [Emacs-diffs] scratch/flymake-refactor-cleaner-for-emacs-26 be9dd4c 32/39: Improve use of flymake-no-changes-timeout, Jo�o T�vora, 2017/10/02
- [Emacs-diffs] scratch/flymake-refactor-cleaner-for-emacs-26 8f0f9cc 28/39: Flymake uses some new fringe bitmaps, Jo�o T�vora, 2017/10/02
- [Emacs-diffs] scratch/flymake-refactor-cleaner-for-emacs-26 3ecfe98 35/39: Tweak Flymake autoloads and dependencies, Jo�o T�vora, 2017/10/02
- [Emacs-diffs] scratch/flymake-refactor-cleaner-for-emacs-26 26ac964 23/39: A couple of Flymake backends for emacs-lisp-mode, Jo�o T�vora, 2017/10/02
- [Emacs-diffs] scratch/flymake-refactor-cleaner-for-emacs-26 fbc6359 31/39: Flymake variable flymake-diagnostic-functions now a special hook, Jo�o T�vora, 2017/10/02
- [Emacs-diffs] scratch/flymake-refactor-cleaner-for-emacs-26 4a110bf 22/39: Fancy Flymake mode-line construct displays status, Jo�o T�vora, 2017/10/02
- [Emacs-diffs] scratch/flymake-refactor-cleaner-for-emacs-26 fc30b6b 19/39: Simplify Flymake logging and erroring, Jo�o T�vora, 2017/10/02
- [Emacs-diffs] scratch/flymake-refactor-cleaner-for-emacs-26 6a5e6ad 05/39: Flymake diagnostics now apply to arbitrary buffer regions, Jo�o T�vora, 2017/10/02