From c47b5fd4b8f9b7c08774e631dae60ca51c23e7c9 Mon Sep 17 00:00:00 2001 From: roel0 Date: Mon, 19 Mar 2018 21:55:59 +0100 Subject: Automatically determine build flags by parsing 'make -n' output #1167 --- ale_linters/c/clang.vim | 11 +++++++++-- ale_linters/c/gcc.vim | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) (limited to 'ale_linters') diff --git a/ale_linters/c/clang.vim b/ale_linters/c/clang.vim index 76803056..25d93715 100644 --- a/ale_linters/c/clang.vim +++ b/ale_linters/c/clang.vim @@ -3,20 +3,27 @@ call ale#Set('c_clang_executable', 'clang') call ale#Set('c_clang_options', '-std=c11 -Wall') +call ale#Set('c_gcc_parse_makefile', 0) function! ale_linters#c#clang#GetExecutable(buffer) abort return ale#Var(a:buffer, 'c_clang_executable') endfunction function! ale_linters#c#clang#GetCommand(buffer) abort - let l:paths = ale#c#FindLocalHeaderPaths(a:buffer) +let l:cflags = [] + if g:ale_c_parse_makefile + let l:cflags = join(ale#c#ParseMakefile(a:buffer), ' ') + endif + if empty(l:cflags) + let l:cflags = ale#c#IncludeOptions(ale#c#FindLocalHeaderPaths(a:buffer)) + endif " -iquote with the directory the file is in makes #include work for " headers in the same directory. return ale#Escape(ale_linters#c#clang#GetExecutable(a:buffer)) \ . ' -S -x c -fsyntax-only ' \ . '-iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h')) . ' ' - \ . ale#c#IncludeOptions(l:paths) + \ . l:cflags . ' ' \ . ale#Var(a:buffer, 'c_clang_options') . ' -' endfunction diff --git a/ale_linters/c/gcc.vim b/ale_linters/c/gcc.vim index 4b241e37..3ad243a3 100644 --- a/ale_linters/c/gcc.vim +++ b/ale_linters/c/gcc.vim @@ -3,20 +3,27 @@ call ale#Set('c_gcc_executable', 'gcc') call ale#Set('c_gcc_options', '-std=c11 -Wall') +call ale#Set('c_parse_makefile', 0) function! ale_linters#c#gcc#GetExecutable(buffer) abort return ale#Var(a:buffer, 'c_gcc_executable') endfunction function! ale_linters#c#gcc#GetCommand(buffer) abort - let l:paths = ale#c#FindLocalHeaderPaths(a:buffer) + let l:cflags = [] + if g:ale_c_parse_makefile + let l:cflags = join(ale#c#ParseMakefile(a:buffer), ' ') + endif + if empty(l:cflags) + let l:cflags = ale#c#IncludeOptions(ale#c#FindLocalHeaderPaths(a:buffer)) + endif " -iquote with the directory the file is in makes #include work for " headers in the same directory. return ale#Escape(ale_linters#c#gcc#GetExecutable(a:buffer)) \ . ' -S -x c -fsyntax-only ' \ . '-iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h')) . ' ' - \ . ale#c#IncludeOptions(l:paths) + \ . l:cflags . ' ' \ . ale#Var(a:buffer, 'c_gcc_options') . ' -' endfunction -- cgit v1.2.3 From 3fb7efa2c6d249ccc5b69036dbeda690c7459515 Mon Sep 17 00:00:00 2001 From: roel0 Date: Tue, 20 Mar 2018 11:56:46 +0100 Subject: Added some unit tests and fixed some linting errors for automatic makefile parsing in C #1167 --- ale_linters/c/clang.vim | 10 ++++++---- ale_linters/c/gcc.vim | 8 +++++--- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'ale_linters') diff --git a/ale_linters/c/clang.vim b/ale_linters/c/clang.vim index 25d93715..74279b7c 100644 --- a/ale_linters/c/clang.vim +++ b/ale_linters/c/clang.vim @@ -3,7 +3,7 @@ call ale#Set('c_clang_executable', 'clang') call ale#Set('c_clang_options', '-std=c11 -Wall') -call ale#Set('c_gcc_parse_makefile', 0) +call ale#Set('c_clang_parse_makefile', 0) function! ale_linters#c#clang#GetExecutable(buffer) abort return ale#Var(a:buffer, 'c_clang_executable') @@ -11,11 +11,13 @@ endfunction function! ale_linters#c#clang#GetCommand(buffer) abort let l:cflags = [] - if g:ale_c_parse_makefile - let l:cflags = join(ale#c#ParseMakefile(a:buffer), ' ') + if g:ale_c_clang_parse_makefile + let l:cflags = join(ale#c#ParseMakefile(a:buffer), ' ') . ' ' endif if empty(l:cflags) let l:cflags = ale#c#IncludeOptions(ale#c#FindLocalHeaderPaths(a:buffer)) + else + let l:cflags .= ' ' endif " -iquote with the directory the file is in makes #include work for @@ -23,7 +25,7 @@ let l:cflags = [] return ale#Escape(ale_linters#c#clang#GetExecutable(a:buffer)) \ . ' -S -x c -fsyntax-only ' \ . '-iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h')) . ' ' - \ . l:cflags . ' ' + \ . l:cflags \ . ale#Var(a:buffer, 'c_clang_options') . ' -' endfunction diff --git a/ale_linters/c/gcc.vim b/ale_linters/c/gcc.vim index 3ad243a3..3199fe8a 100644 --- a/ale_linters/c/gcc.vim +++ b/ale_linters/c/gcc.vim @@ -3,7 +3,7 @@ call ale#Set('c_gcc_executable', 'gcc') call ale#Set('c_gcc_options', '-std=c11 -Wall') -call ale#Set('c_parse_makefile', 0) +call ale#Set('c_gcc_parse_makefile', 0) function! ale_linters#c#gcc#GetExecutable(buffer) abort return ale#Var(a:buffer, 'c_gcc_executable') @@ -11,11 +11,13 @@ endfunction function! ale_linters#c#gcc#GetCommand(buffer) abort let l:cflags = [] - if g:ale_c_parse_makefile + if g:ale_c_gcc_parse_makefile let l:cflags = join(ale#c#ParseMakefile(a:buffer), ' ') endif if empty(l:cflags) let l:cflags = ale#c#IncludeOptions(ale#c#FindLocalHeaderPaths(a:buffer)) + else + let l:cflags .= ' ' endif " -iquote with the directory the file is in makes #include work for @@ -23,7 +25,7 @@ function! ale_linters#c#gcc#GetCommand(buffer) abort return ale#Escape(ale_linters#c#gcc#GetExecutable(a:buffer)) \ . ' -S -x c -fsyntax-only ' \ . '-iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h')) . ' ' - \ . l:cflags . ' ' + \ . l:cflags \ . ale#Var(a:buffer, 'c_gcc_options') . ' -' endfunction -- cgit v1.2.3 From 38953c46266706541569f6f89c19ef8af59d36f5 Mon Sep 17 00:00:00 2001 From: roel0 Date: Tue, 20 Mar 2018 12:37:53 +0100 Subject: Clang parser shoud fallback on old method if parsing fails #1167 --- ale_linters/c/clang.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ale_linters') diff --git a/ale_linters/c/clang.vim b/ale_linters/c/clang.vim index 74279b7c..366cf2d2 100644 --- a/ale_linters/c/clang.vim +++ b/ale_linters/c/clang.vim @@ -12,7 +12,7 @@ endfunction function! ale_linters#c#clang#GetCommand(buffer) abort let l:cflags = [] if g:ale_c_clang_parse_makefile - let l:cflags = join(ale#c#ParseMakefile(a:buffer), ' ') . ' ' + let l:cflags = join(ale#c#ParseMakefile(a:buffer), ' ') endif if empty(l:cflags) let l:cflags = ale#c#IncludeOptions(ale#c#FindLocalHeaderPaths(a:buffer)) -- cgit v1.2.3 From 18d0aeb1a0cca2b749c3d2232f853fcaddcdb56b Mon Sep 17 00:00:00 2001 From: roel0 Date: Tue, 20 Mar 2018 21:49:31 +0100 Subject: * Shell commands should by called async with the help of a command chain * The makefile parser unit test should only test the cflag parser itself #1167 --- ale_linters/c/clang.vim | 14 ++++++++------ ale_linters/c/gcc.vim | 12 +++++++----- 2 files changed, 15 insertions(+), 11 deletions(-) (limited to 'ale_linters') diff --git a/ale_linters/c/clang.vim b/ale_linters/c/clang.vim index 366cf2d2..01e92476 100644 --- a/ale_linters/c/clang.vim +++ b/ale_linters/c/clang.vim @@ -3,16 +3,15 @@ call ale#Set('c_clang_executable', 'clang') call ale#Set('c_clang_options', '-std=c11 -Wall') -call ale#Set('c_clang_parse_makefile', 0) function! ale_linters#c#clang#GetExecutable(buffer) abort return ale#Var(a:buffer, 'c_clang_executable') endfunction -function! ale_linters#c#clang#GetCommand(buffer) abort -let l:cflags = [] - if g:ale_c_clang_parse_makefile - let l:cflags = join(ale#c#ParseMakefile(a:buffer), ' ') +function! ale_linters#c#clang#GetCommand(buffer, output) abort + let l:cflags = [] + if !empty(a:output) + let l:cflags = join(ale#c#ParseMakefile(a:buffer, join(a:output, '\n')), ' ') endif if empty(l:cflags) let l:cflags = ale#c#IncludeOptions(ale#c#FindLocalHeaderPaths(a:buffer)) @@ -33,6 +32,9 @@ call ale#linter#Define('c', { \ 'name': 'clang', \ 'output_stream': 'stderr', \ 'executable_callback': 'ale_linters#c#clang#GetExecutable', -\ 'command_callback': 'ale_linters#c#clang#GetCommand', +\ 'command_chain': [ +\ {'callback': 'ale#c#ParseMakefile', 'output_stream': 'stdout'}, +\ {'callback': 'ale_linters#c#clang#GetCommand'} +\ ], \ 'callback': 'ale#handlers#gcc#HandleGCCFormat', \}) diff --git a/ale_linters/c/gcc.vim b/ale_linters/c/gcc.vim index 3199fe8a..155c5dd2 100644 --- a/ale_linters/c/gcc.vim +++ b/ale_linters/c/gcc.vim @@ -3,16 +3,15 @@ call ale#Set('c_gcc_executable', 'gcc') call ale#Set('c_gcc_options', '-std=c11 -Wall') -call ale#Set('c_gcc_parse_makefile', 0) function! ale_linters#c#gcc#GetExecutable(buffer) abort return ale#Var(a:buffer, 'c_gcc_executable') endfunction -function! ale_linters#c#gcc#GetCommand(buffer) abort +function! ale_linters#c#gcc#GetCommand(buffer, output) abort let l:cflags = [] - if g:ale_c_gcc_parse_makefile - let l:cflags = join(ale#c#ParseMakefile(a:buffer), ' ') + if !empty(a:output) + let l:cflags = join(ale#c#ParseCFlags(a:buffer, join(a:output, '\n')), ' ') endif if empty(l:cflags) let l:cflags = ale#c#IncludeOptions(ale#c#FindLocalHeaderPaths(a:buffer)) @@ -33,6 +32,9 @@ call ale#linter#Define('c', { \ 'name': 'gcc', \ 'output_stream': 'stderr', \ 'executable_callback': 'ale_linters#c#gcc#GetExecutable', -\ 'command_callback': 'ale_linters#c#gcc#GetCommand', +\ 'command_chain': [ +\ {'callback': 'ale#c#ParseMakefile', 'output_stream': 'stdout'}, +\ {'callback': 'ale_linters#c#gcc#GetCommand'} +\ ], \ 'callback': 'ale#handlers#gcc#HandleGCCFormat', \}) -- cgit v1.2.3 From 69237a7e57a67e37e8dcd0c3d97b4a6ffda5929a Mon Sep 17 00:00:00 2001 From: roel0 Date: Wed, 21 Mar 2018 20:44:35 +0100 Subject: Added additional unit tests + adapted review comments #1167 --- ale_linters/c/clang.vim | 12 ++---------- ale_linters/c/gcc.vim | 12 ++---------- 2 files changed, 4 insertions(+), 20 deletions(-) (limited to 'ale_linters') diff --git a/ale_linters/c/clang.vim b/ale_linters/c/clang.vim index 01e92476..ddec4fcb 100644 --- a/ale_linters/c/clang.vim +++ b/ale_linters/c/clang.vim @@ -9,15 +9,7 @@ function! ale_linters#c#clang#GetExecutable(buffer) abort endfunction function! ale_linters#c#clang#GetCommand(buffer, output) abort - let l:cflags = [] - if !empty(a:output) - let l:cflags = join(ale#c#ParseMakefile(a:buffer, join(a:output, '\n')), ' ') - endif - if empty(l:cflags) - let l:cflags = ale#c#IncludeOptions(ale#c#FindLocalHeaderPaths(a:buffer)) - else - let l:cflags .= ' ' - endif + let l:cflags = ale#c#GetCFlags(a:buffer, a:output) " -iquote with the directory the file is in makes #include work for " headers in the same directory. @@ -33,7 +25,7 @@ call ale#linter#Define('c', { \ 'output_stream': 'stderr', \ 'executable_callback': 'ale_linters#c#clang#GetExecutable', \ 'command_chain': [ -\ {'callback': 'ale#c#ParseMakefile', 'output_stream': 'stdout'}, +\ {'callback': 'ale#c#GetMakeCommand', 'output_stream': 'stdout'}, \ {'callback': 'ale_linters#c#clang#GetCommand'} \ ], \ 'callback': 'ale#handlers#gcc#HandleGCCFormat', diff --git a/ale_linters/c/gcc.vim b/ale_linters/c/gcc.vim index 155c5dd2..98563952 100644 --- a/ale_linters/c/gcc.vim +++ b/ale_linters/c/gcc.vim @@ -9,15 +9,7 @@ function! ale_linters#c#gcc#GetExecutable(buffer) abort endfunction function! ale_linters#c#gcc#GetCommand(buffer, output) abort - let l:cflags = [] - if !empty(a:output) - let l:cflags = join(ale#c#ParseCFlags(a:buffer, join(a:output, '\n')), ' ') - endif - if empty(l:cflags) - let l:cflags = ale#c#IncludeOptions(ale#c#FindLocalHeaderPaths(a:buffer)) - else - let l:cflags .= ' ' - endif + let l:cflags = ale#c#GetCFlags(a:buffer, a:output) " -iquote with the directory the file is in makes #include work for " headers in the same directory. @@ -33,7 +25,7 @@ call ale#linter#Define('c', { \ 'output_stream': 'stderr', \ 'executable_callback': 'ale_linters#c#gcc#GetExecutable', \ 'command_chain': [ -\ {'callback': 'ale#c#ParseMakefile', 'output_stream': 'stdout'}, +\ {'callback': 'ale#c#GetMakeCommand', 'output_stream': 'stdout'}, \ {'callback': 'ale_linters#c#gcc#GetCommand'} \ ], \ 'callback': 'ale#handlers#gcc#HandleGCCFormat', -- cgit v1.2.3