#711 - Make the clang executables configurable
This commit is contained in:
parent
bd5ff5b1e5
commit
54ff573174
@ -1,20 +1,20 @@
|
||||
" Author: Masahiro H https://github.com/mshr-h
|
||||
" Description: clang linter for c files
|
||||
|
||||
" Set this option to change the Clang options for warnings for C.
|
||||
if !exists('g:ale_c_clang_options')
|
||||
" let g:ale_c_clang_options = '-Wall'
|
||||
" let g:ale_c_clang_options = '-std=c99 -Wall'
|
||||
" c11 compatible
|
||||
let g:ale_c_clang_options = '-std=c11 -Wall'
|
||||
endif
|
||||
call ale#Set('c_clang_executable', 'clang')
|
||||
call ale#Set('c_clang_options', '-std=c11 -Wall')
|
||||
|
||||
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)
|
||||
|
||||
" -iquote with the directory the file is in makes #include work for
|
||||
" 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')) . ' '
|
||||
\ . ale#c#IncludeOptions(l:paths)
|
||||
\ . ale#Var(a:buffer, 'c_clang_options') . ' -'
|
||||
@ -23,7 +23,7 @@ endfunction
|
||||
call ale#linter#Define('c', {
|
||||
\ 'name': 'clang',
|
||||
\ 'output_stream': 'stderr',
|
||||
\ 'executable': 'clang',
|
||||
\ 'executable_callback': 'ale_linters#c#clang#GetCommand',
|
||||
\ 'command_callback': 'ale_linters#c#clang#GetCommand',
|
||||
\ 'callback': 'ale#handlers#gcc#HandleGCCFormat',
|
||||
\})
|
||||
|
@ -1,17 +1,20 @@
|
||||
" Author: Tomota Nakamura <https://github.com/tomotanakamura>
|
||||
" Description: clang linter for cpp files
|
||||
|
||||
" Set this option to change the Clang options for warnings for CPP.
|
||||
if !exists('g:ale_cpp_clang_options')
|
||||
let g:ale_cpp_clang_options = '-std=c++14 -Wall'
|
||||
endif
|
||||
call ale#Set('cpp_clang_executable', 'clang++')
|
||||
call ale#Set('cpp_clang_options', '-std=c++14 -Wall')
|
||||
|
||||
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
|
||||
let l:paths = ale#c#FindLocalHeaderPaths(a:buffer)
|
||||
|
||||
" -iquote with the directory the file is in makes #include work for
|
||||
" 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')) . ' '
|
||||
\ . ale#c#IncludeOptions(l:paths)
|
||||
\ . ale#Var(a:buffer, 'cpp_clang_options') . ' -'
|
||||
@ -20,7 +23,7 @@ endfunction
|
||||
call ale#linter#Define('cpp', {
|
||||
\ 'name': 'clang',
|
||||
\ 'output_stream': 'stderr',
|
||||
\ 'executable': 'clang++',
|
||||
\ 'executable_callback': 'ale_linters#cpp#clang#GetCommand',
|
||||
\ 'command_callback': 'ale_linters#cpp#clang#GetCommand',
|
||||
\ 'callback': 'ale#handlers#gcc#HandleGCCFormat',
|
||||
\})
|
||||
|
@ -5,12 +5,20 @@ ALE C Integration *ale-c-options*
|
||||
===============================================================================
|
||||
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*
|
||||
*b:ale_c_clang_options*
|
||||
Type: |String|
|
||||
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*
|
||||
|
||||
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*
|
||||
*b:ale_cpp_clang_options*
|
||||
Type: |String|
|
||||
@ -45,7 +53,7 @@ g:ale_cpp_clang_options *g:ale_cpp_clang_options*
|
||||
|
||||
|
||||
===============================================================================
|
||||
clangcheck *ale-cpp-clangcheck*
|
||||
clangcheck *ale-cpp-clangcheck*
|
||||
|
||||
`clang-check` will be run only when files are saved to disk, so that
|
||||
`compile_commands.json` files can be used. It is recommended to use this
|
||||
@ -55,8 +63,8 @@ Therefore, `clang-check` linter reads the options |g:ale_c_build_dir| and
|
||||
overrides |g:ale_c_build_dir_names|.
|
||||
|
||||
|
||||
g:ale_cpp_clangcheck_options *g:ale_cpp_clangcheck_options*
|
||||
*b:ale_cpp_clangcheck_options*
|
||||
g:ale_cpp_clangcheck_options *g:ale_cpp_clangcheck_options*
|
||||
*b:ale_cpp_clangcheck_options*
|
||||
Type: |String|
|
||||
Default: `''`
|
||||
|
||||
|
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')
|
||||
|
||||
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') . ' '
|
||||
\ . ' -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')
|
||||
|
||||
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') . ' '
|
||||
\ . ' -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')
|
||||
|
||||
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') . ' '
|
||||
\ . ' -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')
|
||||
|
||||
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') . ' '
|
||||
\ . ' -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')
|
||||
|
||||
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') . ' '
|
||||
\ . ' -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')
|
||||
|
||||
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') . ' '
|
||||
\ . ' -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')
|
||||
|
||||
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') . ' '
|
||||
\ . ' -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')
|
||||
|
||||
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') . ' '
|
||||
\ . ' -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')
|
||||
|
||||
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') . ' '
|
||||
\ . ' -I' . ale#Escape(g:dir . '/test_c_projects/git_and_nested_makefiles/include') . ' '
|
||||
\ . ' -'
|
||||
|
Loading…
Reference in New Issue
Block a user