diff --git a/README.md b/README.md index ee5c156..10a5433 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,7 @@ formatting. | Bourne Shell | shell [-n flag](http://linux.die.net/man/1/sh), [shellcheck](https://www.shellcheck.net/) | | C | [cppcheck](http://cppcheck.sourceforge.net), [cpplint](https://github.com/google/styleguide/tree/gh-pages/cpplint), [gcc](https://gcc.gnu.org/), [clang](http://clang.llvm.org/), [clangtidy](http://clang.llvm.org/extra/clang-tidy/) !!, [clang-format](https://clang.llvm.org/docs/ClangFormat.html)| | C++ (filetype cpp) | [clang](http://clang.llvm.org/), [clangcheck](http://clang.llvm.org/docs/ClangCheck.html) !!, [clangtidy](http://clang.llvm.org/extra/clang-tidy/) !!, [cppcheck](http://cppcheck.sourceforge.net), [cpplint](https://github.com/google/styleguide/tree/gh-pages/cpplint) !!, [gcc](https://gcc.gnu.org/), [clang-format](https://clang.llvm.org/docs/ClangFormat.html)| +| CUDA | [nvcc](http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html) | | C# | [mcs](http://www.mono-project.com/docs/about-mono/languages/csharp/) | | Chef | [foodcritic](http://www.foodcritic.io/) | | CMake | [cmakelint](https://github.com/richq/cmake-lint) | diff --git a/ale_linters/cuda/nvcc.vim b/ale_linters/cuda/nvcc.vim new file mode 100644 index 0000000..7aaa5cc --- /dev/null +++ b/ale_linters/cuda/nvcc.vim @@ -0,0 +1,56 @@ +" Author: blahgeek +" Description: NVCC linter for cuda files + +call ale#Set('cuda_nvcc_executable', 'nvcc') +call ale#Set('cuda_nvcc_options', '-std=c++11') + +function! ale_linters#cuda#nvcc#GetExecutable(buffer) abort + return ale#Var(a:buffer, 'cuda_nvcc_executable') +endfunction + +function! ale_linters#cuda#nvcc#GetCommand(buffer) abort + " Unused: use ale#util#nul_file + " let l:output_file = tempname() . '.ii' + " call ale#engine#ManageFile(a:buffer, l:output_file) + + return ale#Escape(ale_linters#cuda#nvcc#GetExecutable(a:buffer)) + \ . ' -cuda ' + \ . ale#c#IncludeOptions(ale#c#FindLocalHeaderPaths(a:buffer)) + \ . ale#Var(a:buffer, 'cuda_nvcc_options') . ' %s' + \ . ' -o ' . g:ale#util#nul_file +endfunction + +function! ale_linters#cuda#nvcc#HandleNVCCFormat(buffer, lines) abort + " Look for lines like the following. + " + " test.cu(8): error: argument of type "void *" is incompatible with parameter of type "int *" + let l:pattern = '\v^([^:\(\)]+):?\(?(\d+)\)?:(\d+)?:?\s*\w*\s*(error|warning): (.+)$' + let l:output = [] + + for l:match in ale#util#GetMatches(a:lines, l:pattern) + + let l:item = { + \ 'lnum': str2nr(l:match[2]), + \ 'type': l:match[4] =~# 'error' ? 'E' : 'W', + \ 'text': l:match[5], + \ 'filename': fnamemodify(l:match[1], ':p'), + \} + + if !empty(l:match[3]) + let l:item.col = str2nr(l:match[3]) + endif + + call add(l:output, l:item) + endfor + + return l:output +endfunction + +call ale#linter#Define('cuda', { +\ 'name': 'nvcc', +\ 'output_stream': 'stderr', +\ 'executable_callback': 'ale_linters#cuda#nvcc#GetExecutable', +\ 'command_callback': 'ale_linters#cuda#nvcc#GetCommand', +\ 'callback': 'ale_linters#cuda#nvcc#HandleNVCCFormat', +\ 'lint_file': 1, +\}) diff --git a/doc/ale-cuda.txt b/doc/ale-cuda.txt new file mode 100644 index 0000000..8cba66f --- /dev/null +++ b/doc/ale-cuda.txt @@ -0,0 +1,25 @@ +=============================================================================== +ALE CUDA Integration *ale-cuda-options* + + +=============================================================================== +NVCC *ale-cuda-nvcc* + +g:ale_cuda_nvcc_executable *g:ale_cuda_nvcc_executable* + *b:ale_cuda_nvcc_executable* + Type: |String| + Default: `'nvcc'` + + This variable can be changed to use a different executable for nvcc. + Currently only nvcc 8.0 is supported. + + +g:ale_cuda_nvcc_options *g:ale_cuda_nvcc_options* + *b:ale_cuda_nvcc_options* + Type: |String| + Default: `'-std=c++11'` + + This variable can be changed to modify flags given to nvcc. + +=============================================================================== + vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale.txt b/doc/ale.txt index 3c02af3..44d9e0f 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -32,6 +32,8 @@ CONTENTS *ale-contents* cpplint.............................|ale-cpp-cpplint| gcc.................................|ale-cpp-gcc| clang-format........................|ale-cpp-clangformat| + cuda..................................|ale-cuda-options| + nvcc................................|ale-cuda-nvcc| css...................................|ale-css-options| prettier............................|ale-css-prettier| stylelint...........................|ale-css-stylelint| @@ -201,6 +203,7 @@ Notes: * Bourne Shell: `shell` (-n flag), `shellcheck` * C: `cppcheck`, `cpplint`!!, `gcc`, `clang`, `clangtidy`!!, `clang-format` * C++ (filetype cpp): `clang`, `clangcheck`!!, `clangtidy`!!, `cppcheck`, `cpplint`!!, `gcc`, `clang-format` +* CUDA: `nvcc`!! * C#: `mcs` * Chef: `foodcritic` * CMake: `cmakelint` diff --git a/test/command_callback/test_cuda_nvcc_command_callbacks.vader b/test/command_callback/test_cuda_nvcc_command_callbacks.vader new file mode 100644 index 0000000..88123e5 --- /dev/null +++ b/test/command_callback/test_cuda_nvcc_command_callbacks.vader @@ -0,0 +1,34 @@ +Before: + Save g:ale_cuda_nvcc_executable + Save g:ale_cuda_nvcc_options + + unlet! g:ale_cuda_nvcc_executable + unlet! b:ale_cuda_nvcc_executable + unlet! g:ale_cuda_nvcc_options + unlet! b:ale_cuda_nvcc_options + + runtime ale_linters/cuda/nvcc.vim + +After: + Restore + unlet! b:ale_cuda_nvcc_executable + unlet! b:ale_cuda_nvcc_options + call ale#linter#Reset() + +Execute(The executable should be configurable): + AssertEqual 'nvcc', ale_linters#cuda#nvcc#GetExecutable(bufnr('')) + + let b:ale_cuda_nvcc_executable = 'foobar' + + AssertEqual 'foobar', ale_linters#cuda#nvcc#GetExecutable(bufnr('')) + +Execute(The executable should be used in the command): + AssertEqual + \ ale#Escape('nvcc') . ' -cuda -std=c++11 %s -o /dev/null', + \ ale_linters#cuda#nvcc#GetCommand(bufnr('')) + + let b:ale_cuda_nvcc_executable = 'foobar' + + AssertEqual + \ ale#Escape('foobar') . ' -cuda -std=c++11 %s -o /dev/null', + \ ale_linters#cuda#nvcc#GetCommand(bufnr('')) diff --git a/test/handler/test_cuda_nvcc_handler.vader b/test/handler/test_cuda_nvcc_handler.vader new file mode 100644 index 0000000..03297ab --- /dev/null +++ b/test/handler/test_cuda_nvcc_handler.vader @@ -0,0 +1,29 @@ +Execute(The cuda nvcc handler should parse errors from multiple files for NVCC 8.0): + AssertEqual + \ [ + \ { + \ 'lnum': 1, + \ 'type': 'E', + \ 'text': 'this declaration has no storage class or type specifier', + \ 'filename': '/tmp/cudatest/test.cu', + \ }, + \ { + \ 'lnum': 2, + \ 'type': 'E', + \ 'text': 'attribute "global" does not apply here', + \ 'filename': '/tmp/cudatest/common.h', + \ }, + \ { + \ 'lnum': 2, + \ 'type': 'E', + \ 'text': 'expected a ";"', + \ 'filename': '/tmp/cudatest/common.h', + \ }, + \ ], + \ ale_linters#cuda#nvcc#HandleNVCCFormat(0, [ + \ '/tmp/cudatest/test.cu(1): error: this declaration has no storage class or type specifier', + \ '/tmp/cudatest/common.h(2): error: attribute "global" does not apply here', + \ '/tmp/cudatest/common.h(2): error: expected a ";"', + \ 'At end of source: warning: parsing restarts here after previous syntax error', + \ '3 errors detected in the compilation of "/tmp/tmpxft_00003a9f_00000000-7_test.cpp1.ii".', + \ ])