Close #2359 - Find compile_commands.json in build dirs for cppcheck

This commit is contained in:
w0rp 2019-05-20 22:08:03 +01:00
parent 937138dad4
commit 28819eedd3
No known key found for this signature in database
GPG Key ID: 0FC1ECAA8C81CD83
5 changed files with 41 additions and 23 deletions

View File

@ -9,19 +9,16 @@ function! ale_linters#c#cppcheck#GetCommand(buffer) abort
" "
" If we find it, we'll `cd` to where the compile_commands.json file is, " If we find it, we'll `cd` to where the compile_commands.json file is,
" then use the file to set up import paths, etc. " then use the file to set up import paths, etc.
let l:compile_commmands_path = ale#path#FindNearestFile(a:buffer, 'compile_commands.json') let [l:dir, l:json_path] = ale#c#FindCompileCommands(a:buffer)
let l:cd_command = !empty(l:dir) ? ale#path#CdString(l:dir) : ''
let l:cd_command = !empty(l:compile_commmands_path) let l:compile_commands_option = !empty(l:json_path)
\ ? ale#path#CdString(fnamemodify(l:compile_commmands_path, ':h')) \ ? '--project=' . ale#Escape(l:json_path[len(l:dir) + 1: ])
\ : ''
let l:compile_commands_option = !empty(l:compile_commmands_path)
\ ? '--project=compile_commands.json '
\ : '' \ : ''
return l:cd_command return l:cd_command
\ . '%e -q --language=c ' \ . '%e -q --language=c'
\ . l:compile_commands_option \ . ale#Pad(l:compile_commands_option)
\ . ale#Var(a:buffer, 'c_cppcheck_options') \ . ale#Pad(ale#Var(a:buffer, 'c_cppcheck_options'))
\ . ' %t' \ . ' %t'
endfunction endfunction

View File

@ -9,19 +9,16 @@ function! ale_linters#cpp#cppcheck#GetCommand(buffer) abort
" "
" If we find it, we'll `cd` to where the compile_commands.json file is, " If we find it, we'll `cd` to where the compile_commands.json file is,
" then use the file to set up import paths, etc. " then use the file to set up import paths, etc.
let l:compile_commmands_path = ale#path#FindNearestFile(a:buffer, 'compile_commands.json') let [l:dir, l:json_path] = ale#c#FindCompileCommands(a:buffer)
let l:cd_command = !empty(l:dir) ? ale#path#CdString(l:dir) : ''
let l:cd_command = !empty(l:compile_commmands_path) let l:compile_commands_option = !empty(l:json_path)
\ ? ale#path#CdString(fnamemodify(l:compile_commmands_path, ':h')) \ ? '--project=' . ale#Escape(l:json_path[len(l:dir) + 1: ])
\ : ''
let l:compile_commands_option = !empty(l:compile_commmands_path)
\ ? '--project=compile_commands.json '
\ : '' \ : ''
return l:cd_command return l:cd_command
\ . '%e -q --language=c++ ' \ . '%e -q --language=c++'
\ . l:compile_commands_option \ . ale#Pad(l:compile_commands_option)
\ . ale#Var(a:buffer, 'cpp_cppcheck_options') \ . ale#Pad(ale#Var(a:buffer, 'cpp_cppcheck_options'))
\ . ' %t' \ . ' %t'
endfunction endfunction

View File

@ -21,4 +21,16 @@ Execute(cppcheck for C++ should detect compile_commands.json files):
AssertLinter 'cppcheck', AssertLinter 'cppcheck',
\ ale#path#CdString(ale#path#Simplify(g:dir . '/cppcheck_paths/one')) \ ale#path#CdString(ale#path#Simplify(g:dir . '/cppcheck_paths/one'))
\ . ale#Escape('cppcheck') \ . ale#Escape('cppcheck')
\ . ' -q --language=c --project=compile_commands.json --enable=style %t' \ . ' -q --language=c'
\ . ' --project=' . ale#Escape('compile_commands.json')
\ . ' --enable=style %t'
Execute(cppcheck for C++ should detect compile_commands.json files in build directories):
call ale#test#SetFilename('cppcheck_paths/with_build_dir/foo.cpp')
AssertLinter 'cppcheck',
\ ale#path#CdString(ale#path#Simplify(g:dir . '/cppcheck_paths/with_build_dir'))
\ . ale#Escape('cppcheck')
\ . ' -q --language=c'
\ . ' --project=' . ale#Escape(ale#path#Simplify('build/compile_commands.json'))
\ . ' --enable=style %t'

View File

@ -17,6 +17,18 @@ Execute(cppcheck for C++ should detect compile_commands.json files):
call ale#test#SetFilename('cppcheck_paths/one/foo.cpp') call ale#test#SetFilename('cppcheck_paths/one/foo.cpp')
AssertLinter 'cppcheck', AssertLinter 'cppcheck',
\ ale#path#CdString(ale#path#Simplify(g:dir . '/cppcheck_paths/one')) \ ale#path#CdString(ale#path#Simplify(g:dir . '/cppcheck_paths/one'))
\ . ale#Escape('cppcheck') \ . ale#Escape('cppcheck')
\ . ' -q --language=c++ --project=compile_commands.json --enable=style %t' \ . ' -q --language=c++'
\ . ' --project=' . ale#Escape('compile_commands.json')
\ . ' --enable=style %t'
Execute(cppcheck for C++ should detect compile_commands.json files in build directories):
call ale#test#SetFilename('cppcheck_paths/with_build_dir/foo.cpp')
AssertLinter 'cppcheck',
\ ale#path#CdString(ale#path#Simplify(g:dir . '/cppcheck_paths/with_build_dir'))
\ . ale#Escape('cppcheck')
\ . ' -q --language=c++'
\ . ' --project=' . ale#Escape('build/compile_commands.json')
\ . ' --enable=style %t'