是否有一种简单的/自动化的方法,可以在linux内核源代码树中的文件上写入文件时,配置flycheck或flymake来显示错误注释?假设我正在处理fs/proc/cmdline.c,那么我想让flycheck从两个目录下运行,并执行"make fs/proc/cmdline.o“,然后对结果进行注释。假定ARCH和CROSS_COMPILE是外部设置的。
发布于 2015-04-20 12:51:38
我一直在考虑自己做这件事-这是我得到的:
您需要找到内核源代码树的基础,因此寻找Makefile的默认Makefile处理会适得其反。我们将添加自己的文件,用于定位源库和包装普通内核makefile:
将文件flymake.mk添加到内核源代码树的基础上(根据您自己的交叉编译需要进行配置):
ARCH=mips
CROSS_COMPILE=mips-linux-gnu-
export ARCH
export CROSS_COMPILE
.PHONY: check-syntax
check-syntax:
make -f Makefile $(patsubst %_flymake.o,%.o,$(patsubst %.c,%.o,$(CHK_SOURCES)))要点是去掉"_flymake.c“,只编译真正的文件,并将文件构建为real,而不仅仅是语法。这避免了我们意外地创建file_flymake.o。
我们需要说服flymake寻找flymake.mk并对其运行check-syntax --将这些添加到.emacs中:
;; Build a custom command-line using flymake.mk
(defun flymake-get-kernel-make-cmdline (source base-dir)
(list "make"
(list "-s"
"-f"
"flymake.mk"
"-C"
base-dir
(concat "CHK_SOURCES=" source)
"SYNTAX_CHECK_MODE=1"
"check-syntax")))
;; Search for flymake.mk to locate kernel tree base
(defun flymake-kernel-make-init ()
(flymake-simple-make-init-impl 'flymake-create-temp-inplace t t "flymake.mk" 'flymake-get-kernel-make-cmdline))
;; Register against .c files under /linux/ or /kernel/
;; Since the list is parsed in order use `push`
(push '(".+/\\(linux\\|kernel\\)/.+\\.c$" flymake-kernel-make-init) flymake-allowed-file-name-masks)限制:
source_flymake.c (请确保在运行已保存的文件之前忽略flymake )。我有一个按键,有力地重新运行飞制。push行)-我不知道足够的flymake允许它作为一次过覆盖单个缓冲区。头、临时和外部模块的限制可以通过修补内核Makefile本身来克服,现在我想避免这种情况。
发布于 2015-04-22 17:13:41
类似于Gregs flymake片段,这里是我想出的一个用于防蝇的代码片段:
(defun utils/flycheck-search-linux-makefile ()
"Search for linux top `Makefile' "
(labels
((find-makefile-file-r (path)
(let* ((parent (file-name-directory path))
(file (concat parent "Makefile")))
(cond
((file-exists-p file)
(progn
(with-temp-buffer
(insert-file-contents file)
(if (string-match "VERSION = [0-9]+[[:space:]]*PATCHLEVEL" (buffer-string))
(throw 'found-it parent)
(find-makefile-file-r (directory-file-name parent))
))))
((equal path parent) (throw 'found-it nil))
(t (find-makefile-file-r (directory-file-name parent)))))))
(if (buffer-file-name)
(catch 'found-it
(find-makefile-file-r (buffer-file-name)))
(error "buffer is not visiting a file"))))
(flycheck-define-checker utils/flycheck-linux-makefile-checker
"Linux source checker"
:command
(
"make" "C=1" "-C" (eval (utils/flycheck-search-linux-makefile))
(eval (concat (file-name-sans-extension (file-relative-name buffer-file-name (utils/flycheck-search-linux-makefile))) ".o"))
)
:error-patterns
((error line-start
(message "In file included from") " " (file-name) ":" line ":"
column ":"
line-end)
(info line-start (file-name) ":" line ":" column
": note: " (message) line-end)
(warning line-start (file-name) ":" line ":" column
": warning: " (message) line-end)
(error line-start (file-name) ":" line ":" column
": " (or "fatal error" "error") ": " (message) line-end))
:error-filter
(lambda (errors)
(let ((errors (flycheck-sanitize-errors errors)))
(dolist (err errors)
(let* ((fn (flycheck-error-filename err))
(rn0 (file-relative-name fn default-directory)) ; flycheck-fix-error-filename converted to absolute, revert
(rn1 (expand-file-name rn0 (utils/flycheck-search-linux-makefile))) ; make absolute relative to "make -C dir"
(ef (file-relative-name rn1 default-directory)) ; relative to source
)
(setf (flycheck-error-filename err) ef)
)))
errors)
:modes (c-mode c++-mode)
)
(defun utils/flycheck-mode-hook ()
"Flycheck mode hook."
(make-variable-buffer-local 'flycheck-linux-makefile)
(setq flycheck-linux-makefile (utils/flycheck-search-linux-makefile))
(if flycheck-linux-makefile
(flycheck-select-checker 'utils/flycheck-linux-makefile-checker))
)
(add-hook 'flycheck-mode-hook 'utils/flycheck-mode-hook)不是完美的,而是有用的。
发布于 2016-03-11 21:24:41
我正在使用一个flymake.mk makefile,如
## case 2: called within docker and cross env
ifeq (${_FLYMAKE_WRAPPED},)
_c_sources := $(filter %.c,$(CHK_SOURCES))
_h_sources := $(filter %.h,$(CHK_SOURCES))
_make_wrapped = $(MAKE) \
kbuild-file=$(abspath $(firstword ${MAKEFILE_LIST})) \
_FLYMAKE_WRAPPED=$1 _FLYMAKE_TYPE=$2 M=$(dir $*) $3
check-syntax: $(addprefix .check-syntax_,${_c_sources} ${_h_sources})
$(addprefix .check-syntax_,${_c_sources} ${_h_sources}):.check-syntax_%:
+$(call _make_wrapped,2,c)
## case 3: checking the files
else ifeq (${_FLYMAKE_WRAPPED},2)
-include $(dir ${CHK_SOURCES})/Makefile
-include $(dir ${CHK_SOURCES})/Kbuild
# Reset object/module list
obj-y :=
obj-m :=
lib-y :=
lib-m :=
always :=
targets :=
subdir-y :=
subdir-m :=
__build: check-syntax
.PHONY: check-syntax
clean_checkflags = $(filter-out -M% -g% -Wp,-M%,$1)
check-syntax: ${CHK_SOURCES}
$(CC) $(call clean_checkflags,$(c_flags)) -c -o /dev/null -S $<
endif它既可以处理头文件,也可以使用临时的flymake文件。
https://stackoverflow.com/questions/29709967
复制相似问题