summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-07-16 21:37:10 +0100
committerw0rp <devw0rp@gmail.com>2017-07-16 21:37:10 +0100
commit54ff57317455994305b8bba085c5db166dc34373 (patch)
tree9db086a17ce56e81aab3f6099cdeedbe9350f540
parentbd5ff5b1e52723c910f083bb4b37bad6a410900d (diff)
downloadale-54ff57317455994305b8bba085c5db166dc34373.zip
#711 - Make the clang executables configurable
-rw-r--r--ale_linters/c/clang.vim18
-rw-r--r--ale_linters/cpp/clang.vim15
-rw-r--r--doc/ale-c.txt10
-rw-r--r--doc/ale-cpp.txt14
-rw-r--r--test/command_callback/test_c_clang_command_callbacks.vader39
-rw-r--r--test/command_callback/test_cpp_clang_command_callbacks.vader39
-rw-r--r--test/test_c_import_paths.vader27
7 files changed, 134 insertions, 28 deletions
diff --git a/ale_linters/c/clang.vim b/ale_linters/c/clang.vim
index 2cecc514..6ad5f122 100644
--- a/ale_linters/c/clang.vim
+++ b/ale_linters/c/clang.vim
@@ -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',
\})
diff --git a/ale_linters/cpp/clang.vim b/ale_linters/cpp/clang.vim
index f70101d3..80f1d941 100644
--- a/ale_linters/cpp/clang.vim
+++ b/ale_linters/cpp/clang.vim
@@ -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',
\})
diff --git a/doc/ale-c.txt b/doc/ale-c.txt
index 54b118f2..57d544db 100644
--- a/doc/ale-c.txt
+++ b/doc/ale-c.txt
@@ -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.
===============================================================================
diff --git a/doc/ale-cpp.txt b/doc/ale-cpp.txt
index 9b745b2a..3e8ce9e1 100644
--- a/doc/ale-cpp.txt
+++ b/doc/ale-cpp.txt
@@ -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: `''`
diff --git a/test/command_callback/test_c_clang_command_callbacks.vader b/test/command_callback/test_c_clang_command_callbacks.vader
new file mode 100644
index 00000000..d6fc8ca6
--- /dev/null
+++ b/test/command_callback/test_c_clang_command_callbacks.vader
@@ -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(''))
diff --git a/test/command_callback/test_cpp_clang_command_callbacks.vader b/test/command_callback/test_cpp_clang_command_callbacks.vader
new file mode 100644
index 00000000..67d6898c
--- /dev/null
+++ b/test/command_callback/test_cpp_clang_command_callbacks.vader
@@ -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(''))
diff --git a/test/test_c_import_paths.vader b/test/test_c_import_paths.vader
index fbc3d563..ae6375f5 100644
--- a/test/test_c_import_paths.vader
+++ b/test/test_c_import_paths.vader
@@ -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') . ' '
\ . ' -'