From 9e8387890044726538a7b5f108efdf6a82d59b00 Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 16 Jul 2017 22:41:15 +0100 Subject: [PATCH] #711 - Make the gcc executables configurable --- ale_linters/c/gcc.vim | 18 ++++----- ale_linters/cpp/gcc.vim | 25 +++++------- doc/ale-c.txt | 8 ++++ doc/ale-cpp.txt | 8 ++++ .../test_c_gcc_command_callbacks.vader | 39 +++++++++++++++++++ .../test_cpp_gcc_command_callbacks.vader | 39 +++++++++++++++++++ test/test_c_import_paths.vader | 24 ++++++++---- 7 files changed, 128 insertions(+), 33 deletions(-) create mode 100644 test/command_callback/test_c_gcc_command_callbacks.vader create mode 100644 test/command_callback/test_cpp_gcc_command_callbacks.vader diff --git a/ale_linters/c/gcc.vim b/ale_linters/c/gcc.vim index c988b30f..4b241e37 100644 --- a/ale_linters/c/gcc.vim +++ b/ale_linters/c/gcc.vim @@ -1,20 +1,20 @@ " Author: w0rp " Description: gcc linter for c files -" Set this option to change the GCC options for warnings for C. -if !exists('g:ale_c_gcc_options') - " let g:ale_c_gcc_options = '-Wall' - " let g:ale_c_gcc_options = '-std=c99 -Wall' - " c11 compatible - let g:ale_c_gcc_options = '-std=c11 -Wall' -endif +call ale#Set('c_gcc_executable', 'gcc') +call ale#Set('c_gcc_options', '-std=c11 -Wall') + +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) " -iquote with the directory the file is in makes #include work for " headers in the same directory. - return 'gcc -S -x c -fsyntax-only ' + 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) \ . ale#Var(a:buffer, 'c_gcc_options') . ' -' @@ -23,7 +23,7 @@ endfunction call ale#linter#Define('c', { \ 'name': 'gcc', \ 'output_stream': 'stderr', -\ 'executable': 'gcc', +\ 'executable_callback': 'ale_linters#c#gcc#GetExecutable', \ 'command_callback': 'ale_linters#c#gcc#GetCommand', \ 'callback': 'ale#handlers#gcc#HandleGCCFormat', \}) diff --git a/ale_linters/cpp/gcc.vim b/ale_linters/cpp/gcc.vim index 69b69e4f..40dffc98 100644 --- a/ale_linters/cpp/gcc.vim +++ b/ale_linters/cpp/gcc.vim @@ -1,27 +1,20 @@ " Author: geam " Description: gcc linter for cpp files +" +call ale#Set('cpp_gcc_executable', 'gcc') +call ale#Set('cpp_gcc_options', '-std=c++14 -Wall') -" Set this option to change the GCC options for warnings for C. -if !exists('g:ale_cpp_gcc_options') - let s:version = ale#handlers#gcc#ParseGCCVersion(systemlist('gcc --version')) - - if !empty(s:version) && ale#semver#GreaterOrEqual(s:version, [4, 9, 0]) - " Use c++14 support in 4.9 and above. - let g:ale_cpp_gcc_options = '-std=c++14 -Wall' - else - " Use c++1y in older versions. - let g:ale_cpp_gcc_options = '-std=c++1y -Wall' - endif - - unlet! s:version -endif +function! ale_linters#cpp#gcc#GetExecutable(buffer) abort + return ale#Var(a:buffer, 'cpp_gcc_executable') +endfunction function! ale_linters#cpp#gcc#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 'gcc -S -x c++ -fsyntax-only ' + return ale#Escape(ale_linters#cpp#gcc#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_gcc_options') . ' -' @@ -30,7 +23,7 @@ endfunction call ale#linter#Define('cpp', { \ 'name': 'g++', \ 'output_stream': 'stderr', -\ 'executable': 'g++', +\ 'executable_callback': 'ale_linters#cpp#gcc#GetExecutable', \ 'command_callback': 'ale_linters#cpp#gcc#GetCommand', \ 'callback': 'ale#handlers#gcc#HandleGCCFormat', \}) diff --git a/doc/ale-c.txt b/doc/ale-c.txt index 41c33c96..2572d885 100644 --- a/doc/ale-c.txt +++ b/doc/ale-c.txt @@ -43,6 +43,14 @@ g:ale_c_cppcheck_options *g:ale_c_cppcheck_options* =============================================================================== gcc *ale-c-gcc* +g:ale_c_gcc_executable *g:ale_c_gcc_executable* + *b:ale_c_gcc_executable* + Type: |String| + Default: `'gcc'` + + This variable can be changed to use a different executable for gcc. + + g:ale_c_gcc_options *g:ale_c_gcc_options* *b:ale_c_gcc_options* Type: |String| diff --git a/doc/ale-cpp.txt b/doc/ale-cpp.txt index f5e7863b..b84b5e2e 100644 --- a/doc/ale-cpp.txt +++ b/doc/ale-cpp.txt @@ -148,6 +148,14 @@ g:ale_cpp_cpplint_options *g:ale_cpp_cpplint_options* =============================================================================== gcc *ale-cpp-gcc* +g:ale_cpp_gcc_executable *g:ale_cpp_gcc_executable* + *b:ale_cpp_gcc_executable* + Type: |String| + Default: `'gcc'` + + This variable can be changed to use a different executable for gcc. + + g:ale_cpp_gcc_options *g:ale_cpp_gcc_options* *b:ale_cpp_gcc_options* Type: |String| diff --git a/test/command_callback/test_c_gcc_command_callbacks.vader b/test/command_callback/test_c_gcc_command_callbacks.vader new file mode 100644 index 00000000..8038f410 --- /dev/null +++ b/test/command_callback/test_c_gcc_command_callbacks.vader @@ -0,0 +1,39 @@ +Before: + Save g:ale_c_gcc_executable + Save g:ale_c_gcc_options + + unlet! g:ale_c_gcc_executable + unlet! b:ale_c_gcc_executable + unlet! g:ale_c_gcc_options + unlet! b:ale_c_gcc_options + + runtime ale_linters/c/gcc.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_gcc_executable + unlet! b:ale_c_gcc_options + call ale#linter#Reset() + +Execute(The executable should be configurable): + AssertEqual 'gcc', ale_linters#c#gcc#GetExecutable(bufnr('')) + + let b:ale_c_gcc_executable = 'foobar' + + AssertEqual 'foobar', ale_linters#c#gcc#GetExecutable(bufnr('')) + +Execute(The executable should be used in the command): + AssertEqual + \ ale#Escape('gcc') . b:command_tail, + \ ale_linters#c#gcc#GetCommand(bufnr('')) + + let b:ale_c_gcc_executable = 'foobar' + + AssertEqual + \ ale#Escape('foobar') . b:command_tail, + \ ale_linters#c#gcc#GetCommand(bufnr('')) diff --git a/test/command_callback/test_cpp_gcc_command_callbacks.vader b/test/command_callback/test_cpp_gcc_command_callbacks.vader new file mode 100644 index 00000000..9ab4d5cb --- /dev/null +++ b/test/command_callback/test_cpp_gcc_command_callbacks.vader @@ -0,0 +1,39 @@ +Before: + Save g:ale_cpp_gcc_executable + Save g:ale_cpp_gcc_options + + unlet! g:ale_cpp_gcc_executable + unlet! b:ale_cpp_gcc_executable + unlet! g:ale_cpp_gcc_options + unlet! b:ale_cpp_gcc_options + + runtime ale_linters/cpp/gcc.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_gcc_executable + unlet! b:ale_cpp_gcc_options + call ale#linter#Reset() + +Execute(The executable should be configurable): + AssertEqual 'gcc', ale_linters#cpp#gcc#GetExecutable(bufnr('')) + + let b:ale_cpp_gcc_executable = 'foobar' + + AssertEqual 'foobar', ale_linters#cpp#gcc#GetExecutable(bufnr('')) + +Execute(The executable should be used in the command): + AssertEqual + \ ale#Escape('gcc') . b:command_tail, + \ ale_linters#cpp#gcc#GetCommand(bufnr('')) + + let b:ale_cpp_gcc_executable = 'foobar' + + AssertEqual + \ ale#Escape('foobar') . b:command_tail, + \ ale_linters#cpp#gcc#GetCommand(bufnr('')) diff --git a/test/test_c_import_paths.vader b/test/test_c_import_paths.vader index ae6375f5..862ec151 100644 --- a/test/test_c_import_paths.vader +++ b/test/test_c_import_paths.vader @@ -37,7 +37,8 @@ Execute(The C GCC handler should include 'include' directories for projects with call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c') AssertEqual - \ 'gcc -S -x c -fsyntax-only ' + \ ale#Escape('gcc') + \ . ' -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') . ' ' \ . ' -' @@ -49,7 +50,8 @@ Execute(The C GCC handler should include 'include' directories for projects with call ale#test#SetFilename('test_c_projects/configure_project/subdir/file.c') AssertEqual - \ 'gcc -S -x c -fsyntax-only ' + \ ale#Escape('gcc') + \ . ' -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') . ' ' \ . ' -' @@ -61,7 +63,8 @@ Execute(The C GCC handler should include root directories for projects with .h f call ale#test#SetFilename('test_c_projects/h_file_project/subdir/file.c') AssertEqual - \ 'gcc -S -x c -fsyntax-only ' + \ ale#Escape('gcc') + \ . ' -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') . ' ' \ . ' -' @@ -73,7 +76,8 @@ Execute(The C GCC handler should include root directories for projects with .hpp call ale#test#SetFilename('test_c_projects/hpp_file_project/subdir/file.c') AssertEqual - \ 'gcc -S -x c -fsyntax-only ' + \ ale#Escape('gcc') + \ . ' -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') . ' ' \ . ' -' @@ -137,7 +141,8 @@ Execute(The C++ GCC handler should include 'include' directories for projects wi call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.cpp') AssertEqual - \ 'gcc -S -x c++ -fsyntax-only ' + \ ale#Escape('gcc') + \ . ' -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') . ' ' \ . ' -' @@ -149,7 +154,8 @@ Execute(The C++ GCC handler should include 'include' directories for projects wi call ale#test#SetFilename('test_c_projects/configure_project/subdir/file.cpp') AssertEqual - \ 'gcc -S -x c++ -fsyntax-only ' + \ ale#Escape('gcc') + \ . ' -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') . ' ' \ . ' -' @@ -161,7 +167,8 @@ Execute(The C++ GCC handler should include root directories for projects with .h call ale#test#SetFilename('test_c_projects/h_file_project/subdir/file.cpp') AssertEqual - \ 'gcc -S -x c++ -fsyntax-only ' + \ ale#Escape('gcc') + \ . ' -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') . ' ' \ . ' -' @@ -173,7 +180,8 @@ Execute(The C++ GCC handler should include root directories for projects with .h call ale#test#SetFilename('test_c_projects/hpp_file_project/subdir/file.cpp') AssertEqual - \ 'gcc -S -x c++ -fsyntax-only ' + \ ale#Escape('gcc') + \ . ' -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') . ' ' \ . ' -'