#711 - Make the clang executables configurable
This commit is contained in:
parent
bd5ff5b1e5
commit
54ff573174
7 changed files with 134 additions and 28 deletions
|
@ -1,20 +1,20 @@
|
||||||
" Author: Masahiro H https://github.com/mshr-h
|
" Author: Masahiro H https://github.com/mshr-h
|
||||||
" Description: clang linter for c files
|
" Description: clang linter for c files
|
||||||
|
|
||||||
" Set this option to change the Clang options for warnings for C.
|
call ale#Set('c_clang_executable', 'clang')
|
||||||
if !exists('g:ale_c_clang_options')
|
call ale#Set('c_clang_options', '-std=c11 -Wall')
|
||||||
" let g:ale_c_clang_options = '-Wall'
|
|
||||||
" let g:ale_c_clang_options = '-std=c99 -Wall'
|
function! ale_linters#c#clang#GetExecutable(buffer) abort
|
||||||
" c11 compatible
|
return ale#Var(a:buffer, 'c_clang_executable')
|
||||||
let g:ale_c_clang_options = '-std=c11 -Wall'
|
endfunction
|
||||||
endif
|
|
||||||
|
|
||||||
function! ale_linters#c#clang#GetCommand(buffer) abort
|
function! ale_linters#c#clang#GetCommand(buffer) abort
|
||||||
let l:paths = ale#c#FindLocalHeaderPaths(a:buffer)
|
let l:paths = ale#c#FindLocalHeaderPaths(a:buffer)
|
||||||
|
|
||||||
" -iquote with the directory the file is in makes #include work for
|
" -iquote with the directory the file is in makes #include work for
|
||||||
" headers in the same directory.
|
" headers in the same directory.
|
||||||
return 'clang -S -x c -fsyntax-only '
|
return ale#Escape(ale_linters#c#clang#GetExecutable(a:buffer))
|
||||||
|
\ . ' -S -x c -fsyntax-only '
|
||||||
\ . '-iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h')) . ' '
|
\ . '-iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h')) . ' '
|
||||||
\ . ale#c#IncludeOptions(l:paths)
|
\ . ale#c#IncludeOptions(l:paths)
|
||||||
\ . ale#Var(a:buffer, 'c_clang_options') . ' -'
|
\ . ale#Var(a:buffer, 'c_clang_options') . ' -'
|
||||||
|
@ -23,7 +23,7 @@ endfunction
|
||||||
call ale#linter#Define('c', {
|
call ale#linter#Define('c', {
|
||||||
\ 'name': 'clang',
|
\ 'name': 'clang',
|
||||||
\ 'output_stream': 'stderr',
|
\ 'output_stream': 'stderr',
|
||||||
\ 'executable': 'clang',
|
\ 'executable_callback': 'ale_linters#c#clang#GetCommand',
|
||||||
\ 'command_callback': 'ale_linters#c#clang#GetCommand',
|
\ 'command_callback': 'ale_linters#c#clang#GetCommand',
|
||||||
\ 'callback': 'ale#handlers#gcc#HandleGCCFormat',
|
\ 'callback': 'ale#handlers#gcc#HandleGCCFormat',
|
||||||
\})
|
\})
|
||||||
|
|
|
@ -1,17 +1,20 @@
|
||||||
" Author: Tomota Nakamura <https://github.com/tomotanakamura>
|
" Author: Tomota Nakamura <https://github.com/tomotanakamura>
|
||||||
" Description: clang linter for cpp files
|
" Description: clang linter for cpp files
|
||||||
|
|
||||||
" Set this option to change the Clang options for warnings for CPP.
|
call ale#Set('cpp_clang_executable', 'clang++')
|
||||||
if !exists('g:ale_cpp_clang_options')
|
call ale#Set('cpp_clang_options', '-std=c++14 -Wall')
|
||||||
let g:ale_cpp_clang_options = '-std=c++14 -Wall'
|
|
||||||
endif
|
function! ale_linters#cpp#clang#GetExecutable(buffer) abort
|
||||||
|
return ale#Var(a:buffer, 'cpp_clang_executable')
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! ale_linters#cpp#clang#GetCommand(buffer) abort
|
function! ale_linters#cpp#clang#GetCommand(buffer) abort
|
||||||
let l:paths = ale#c#FindLocalHeaderPaths(a:buffer)
|
let l:paths = ale#c#FindLocalHeaderPaths(a:buffer)
|
||||||
|
|
||||||
" -iquote with the directory the file is in makes #include work for
|
" -iquote with the directory the file is in makes #include work for
|
||||||
" headers in the same directory.
|
" headers in the same directory.
|
||||||
return 'clang++ -S -x c++ -fsyntax-only '
|
return ale#Escape(ale_linters#cpp#clang#GetExecutable(a:buffer))
|
||||||
|
\ . ' -S -x c++ -fsyntax-only '
|
||||||
\ . '-iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h')) . ' '
|
\ . '-iquote ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h')) . ' '
|
||||||
\ . ale#c#IncludeOptions(l:paths)
|
\ . ale#c#IncludeOptions(l:paths)
|
||||||
\ . ale#Var(a:buffer, 'cpp_clang_options') . ' -'
|
\ . ale#Var(a:buffer, 'cpp_clang_options') . ' -'
|
||||||
|
@ -20,7 +23,7 @@ endfunction
|
||||||
call ale#linter#Define('cpp', {
|
call ale#linter#Define('cpp', {
|
||||||
\ 'name': 'clang',
|
\ 'name': 'clang',
|
||||||
\ 'output_stream': 'stderr',
|
\ 'output_stream': 'stderr',
|
||||||
\ 'executable': 'clang++',
|
\ 'executable_callback': 'ale_linters#cpp#clang#GetCommand',
|
||||||
\ 'command_callback': 'ale_linters#cpp#clang#GetCommand',
|
\ 'command_callback': 'ale_linters#cpp#clang#GetCommand',
|
||||||
\ 'callback': 'ale#handlers#gcc#HandleGCCFormat',
|
\ 'callback': 'ale#handlers#gcc#HandleGCCFormat',
|
||||||
\})
|
\})
|
||||||
|
|
|
@ -5,12 +5,20 @@ ALE C Integration *ale-c-options*
|
||||||
===============================================================================
|
===============================================================================
|
||||||
clang *ale-c-clang*
|
clang *ale-c-clang*
|
||||||
|
|
||||||
|
g:ale_c_clang_executable *g:ale_c_clang_executable*
|
||||||
|
*b:ale_c_clang_executable*
|
||||||
|
Type: |String|
|
||||||
|
Default: `'clang'`
|
||||||
|
|
||||||
|
This variable can be changed to use a different executable for clang.
|
||||||
|
|
||||||
|
|
||||||
g:ale_c_clang_options *g:ale_c_clang_options*
|
g:ale_c_clang_options *g:ale_c_clang_options*
|
||||||
*b:ale_c_clang_options*
|
*b:ale_c_clang_options*
|
||||||
Type: |String|
|
Type: |String|
|
||||||
Default: `'-std=c11 -Wall'`
|
Default: `'-std=c11 -Wall'`
|
||||||
|
|
||||||
This variable can be change to modify flags given to clang.
|
This variable can be changed to modify flags given to clang.
|
||||||
|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
|
|
|
@ -36,6 +36,14 @@ g:ale_c_build_dir *g:ale_c_build_dir*
|
||||||
===============================================================================
|
===============================================================================
|
||||||
clang *ale-cpp-clang*
|
clang *ale-cpp-clang*
|
||||||
|
|
||||||
|
g:ale_cpp_clang_executable *g:ale_cpp_clang_executable*
|
||||||
|
*b:ale_cpp_clang_executable*
|
||||||
|
Type: |String|
|
||||||
|
Default: `'clang++'`
|
||||||
|
|
||||||
|
This variable can be changed to use a different executable for clang.
|
||||||
|
|
||||||
|
|
||||||
g:ale_cpp_clang_options *g:ale_cpp_clang_options*
|
g:ale_cpp_clang_options *g:ale_cpp_clang_options*
|
||||||
*b:ale_cpp_clang_options*
|
*b:ale_cpp_clang_options*
|
||||||
Type: |String|
|
Type: |String|
|
||||||
|
|
39
test/command_callback/test_c_clang_command_callbacks.vader
Normal file
39
test/command_callback/test_c_clang_command_callbacks.vader
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
Before:
|
||||||
|
Save g:ale_c_clang_executable
|
||||||
|
Save g:ale_c_clang_options
|
||||||
|
|
||||||
|
unlet! g:ale_c_clang_executable
|
||||||
|
unlet! b:ale_c_clang_executable
|
||||||
|
unlet! g:ale_c_clang_options
|
||||||
|
unlet! b:ale_c_clang_options
|
||||||
|
|
||||||
|
runtime ale_linters/c/clang.vim
|
||||||
|
|
||||||
|
let b:command_tail = ' -S -x c -fsyntax-only -iquote'
|
||||||
|
\ . ' ' . ale#Escape(getcwd())
|
||||||
|
\ . ' -std=c11 -Wall -'
|
||||||
|
|
||||||
|
After:
|
||||||
|
Restore
|
||||||
|
unlet! b:command_tail
|
||||||
|
unlet! b:ale_c_clang_executable
|
||||||
|
unlet! b:ale_c_clang_options
|
||||||
|
call ale#linter#Reset()
|
||||||
|
|
||||||
|
Execute(The executable should be configurable):
|
||||||
|
AssertEqual 'clang', ale_linters#c#clang#GetExecutable(bufnr(''))
|
||||||
|
|
||||||
|
let b:ale_c_clang_executable = 'foobar'
|
||||||
|
|
||||||
|
AssertEqual 'foobar', ale_linters#c#clang#GetExecutable(bufnr(''))
|
||||||
|
|
||||||
|
Execute(The executable should be used in the command):
|
||||||
|
AssertEqual
|
||||||
|
\ ale#Escape('clang') . b:command_tail,
|
||||||
|
\ ale_linters#c#clang#GetCommand(bufnr(''))
|
||||||
|
|
||||||
|
let b:ale_c_clang_executable = 'foobar'
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ ale#Escape('foobar') . b:command_tail,
|
||||||
|
\ ale_linters#c#clang#GetCommand(bufnr(''))
|
39
test/command_callback/test_cpp_clang_command_callbacks.vader
Normal file
39
test/command_callback/test_cpp_clang_command_callbacks.vader
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
Before:
|
||||||
|
Save g:ale_cpp_clang_executable
|
||||||
|
Save g:ale_cpp_clang_options
|
||||||
|
|
||||||
|
unlet! g:ale_cpp_clang_executable
|
||||||
|
unlet! b:ale_cpp_clang_executable
|
||||||
|
unlet! g:ale_cpp_clang_options
|
||||||
|
unlet! b:ale_cpp_clang_options
|
||||||
|
|
||||||
|
runtime ale_linters/cpp/clang.vim
|
||||||
|
|
||||||
|
let b:command_tail = ' -S -x c++ -fsyntax-only -iquote'
|
||||||
|
\ . ' ' . ale#Escape(getcwd())
|
||||||
|
\ . ' -std=c++14 -Wall -'
|
||||||
|
|
||||||
|
After:
|
||||||
|
Restore
|
||||||
|
unlet! b:command_tail
|
||||||
|
unlet! b:ale_cpp_clang_executable
|
||||||
|
unlet! b:ale_cpp_clang_options
|
||||||
|
call ale#linter#Reset()
|
||||||
|
|
||||||
|
Execute(The executable should be configurable):
|
||||||
|
AssertEqual 'clang++', ale_linters#cpp#clang#GetExecutable(bufnr(''))
|
||||||
|
|
||||||
|
let b:ale_cpp_clang_executable = 'foobar'
|
||||||
|
|
||||||
|
AssertEqual 'foobar', ale_linters#cpp#clang#GetExecutable(bufnr(''))
|
||||||
|
|
||||||
|
Execute(The executable should be used in the command):
|
||||||
|
AssertEqual
|
||||||
|
\ ale#Escape('clang++') . b:command_tail,
|
||||||
|
\ ale_linters#cpp#clang#GetCommand(bufnr(''))
|
||||||
|
|
||||||
|
let b:ale_cpp_clang_executable = 'foobar'
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ ale#Escape('foobar') . b:command_tail,
|
||||||
|
\ ale_linters#cpp#clang#GetCommand(bufnr(''))
|
|
@ -85,7 +85,8 @@ Execute(The C Clang handler should include 'include' directories for projects wi
|
||||||
call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c')
|
call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ 'clang -S -x c -fsyntax-only '
|
\ ale#Escape('clang')
|
||||||
|
\ . ' -S -x c -fsyntax-only '
|
||||||
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/makefile_project/subdir') . ' '
|
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/makefile_project/subdir') . ' '
|
||||||
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/makefile_project/include') . ' '
|
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/makefile_project/include') . ' '
|
||||||
\ . ' -'
|
\ . ' -'
|
||||||
|
@ -97,7 +98,8 @@ Execute(The C Clang handler should include 'include' directories for projects wi
|
||||||
call ale#test#SetFilename('test_c_projects/h_file_project/subdir/file.c')
|
call ale#test#SetFilename('test_c_projects/h_file_project/subdir/file.c')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ 'clang -S -x c -fsyntax-only '
|
\ ale#Escape('clang')
|
||||||
|
\ . ' -S -x c -fsyntax-only '
|
||||||
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/h_file_project/subdir') . ' '
|
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/h_file_project/subdir') . ' '
|
||||||
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/h_file_project') . ' '
|
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/h_file_project') . ' '
|
||||||
\ . ' -'
|
\ . ' -'
|
||||||
|
@ -109,7 +111,8 @@ Execute(The C Clang handler should include root directories for projects with .h
|
||||||
call ale#test#SetFilename('test_c_projects/h_file_project/subdir/file.c')
|
call ale#test#SetFilename('test_c_projects/h_file_project/subdir/file.c')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ 'clang -S -x c -fsyntax-only '
|
\ ale#Escape('clang')
|
||||||
|
\ . ' -S -x c -fsyntax-only '
|
||||||
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/h_file_project/subdir') . ' '
|
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/h_file_project/subdir') . ' '
|
||||||
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/h_file_project') . ' '
|
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/h_file_project') . ' '
|
||||||
\ . ' -'
|
\ . ' -'
|
||||||
|
@ -121,7 +124,8 @@ Execute(The C Clang handler should include root directories for projects with .h
|
||||||
call ale#test#SetFilename('test_c_projects/hpp_file_project/subdir/file.c')
|
call ale#test#SetFilename('test_c_projects/hpp_file_project/subdir/file.c')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ 'clang -S -x c -fsyntax-only '
|
\ ale#Escape('clang')
|
||||||
|
\ . ' -S -x c -fsyntax-only '
|
||||||
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/hpp_file_project/subdir') . ' '
|
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/hpp_file_project/subdir') . ' '
|
||||||
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/hpp_file_project') . ' '
|
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/hpp_file_project') . ' '
|
||||||
\ . ' -'
|
\ . ' -'
|
||||||
|
@ -181,7 +185,8 @@ Execute(The C++ Clang handler should include 'include' directories for projects
|
||||||
call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.cpp')
|
call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.cpp')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ 'clang++ -S -x c++ -fsyntax-only '
|
\ ale#Escape('clang++')
|
||||||
|
\ . ' -S -x c++ -fsyntax-only '
|
||||||
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/makefile_project/subdir') . ' '
|
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/makefile_project/subdir') . ' '
|
||||||
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/makefile_project/include') . ' '
|
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/makefile_project/include') . ' '
|
||||||
\ . ' -'
|
\ . ' -'
|
||||||
|
@ -193,7 +198,8 @@ Execute(The C++ Clang handler should include 'include' directories for projects
|
||||||
call ale#test#SetFilename('test_c_projects/configure_project/subdir/file.cpp')
|
call ale#test#SetFilename('test_c_projects/configure_project/subdir/file.cpp')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ 'clang++ -S -x c++ -fsyntax-only '
|
\ ale#Escape('clang++')
|
||||||
|
\ . ' -S -x c++ -fsyntax-only '
|
||||||
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/configure_project/subdir') . ' '
|
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/configure_project/subdir') . ' '
|
||||||
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/configure_project/include') . ' '
|
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/configure_project/include') . ' '
|
||||||
\ . ' -'
|
\ . ' -'
|
||||||
|
@ -205,7 +211,8 @@ Execute(The C++ Clang handler should include root directories for projects with
|
||||||
call ale#test#SetFilename('test_c_projects/h_file_project/subdir/file.cpp')
|
call ale#test#SetFilename('test_c_projects/h_file_project/subdir/file.cpp')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ 'clang++ -S -x c++ -fsyntax-only '
|
\ ale#Escape('clang++')
|
||||||
|
\ . ' -S -x c++ -fsyntax-only '
|
||||||
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/h_file_project/subdir') . ' '
|
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/h_file_project/subdir') . ' '
|
||||||
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/h_file_project') . ' '
|
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/h_file_project') . ' '
|
||||||
\ . ' -'
|
\ . ' -'
|
||||||
|
@ -217,7 +224,8 @@ Execute(The C++ Clang handler should include root directories for projects with
|
||||||
call ale#test#SetFilename('test_c_projects/hpp_file_project/subdir/file.cpp')
|
call ale#test#SetFilename('test_c_projects/hpp_file_project/subdir/file.cpp')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ 'clang++ -S -x c++ -fsyntax-only '
|
\ ale#Escape('clang++')
|
||||||
|
\ . ' -S -x c++ -fsyntax-only '
|
||||||
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/hpp_file_project/subdir') . ' '
|
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/hpp_file_project/subdir') . ' '
|
||||||
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/hpp_file_project') . ' '
|
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/hpp_file_project') . ' '
|
||||||
\ . ' -'
|
\ . ' -'
|
||||||
|
@ -237,7 +245,8 @@ Execute(The C++ Clang handler shoud use the include directory based on the .git
|
||||||
call ale#test#SetFilename('test_c_projects/git_and_nested_makefiles/src/file.cpp')
|
call ale#test#SetFilename('test_c_projects/git_and_nested_makefiles/src/file.cpp')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ 'clang++ -S -x c++ -fsyntax-only '
|
\ ale#Escape('clang++')
|
||||||
|
\ . ' -S -x c++ -fsyntax-only '
|
||||||
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/git_and_nested_makefiles/src') . ' '
|
\ . '-iquote ' . ale#Escape(g:dir . '/test_c_projects/git_and_nested_makefiles/src') . ' '
|
||||||
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/git_and_nested_makefiles/include') . ' '
|
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/git_and_nested_makefiles/include') . ' '
|
||||||
\ . ' -'
|
\ . ' -'
|
||||||
|
|
Reference in a new issue