Close #2359 - Find compile_commands.json in build dirs for cppcheck
This commit is contained in:
parent
937138dad4
commit
28819eedd3
5 changed files with 41 additions and 23 deletions
|
@ -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,
|
||||
" 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:cd_command = !empty(l:compile_commmands_path)
|
||||
\ ? ale#path#CdString(fnamemodify(l:compile_commmands_path, ':h'))
|
||||
\ : ''
|
||||
let l:compile_commands_option = !empty(l:compile_commmands_path)
|
||||
\ ? '--project=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:compile_commands_option = !empty(l:json_path)
|
||||
\ ? '--project=' . ale#Escape(l:json_path[len(l:dir) + 1: ])
|
||||
\ : ''
|
||||
|
||||
return l:cd_command
|
||||
\ . '%e -q --language=c '
|
||||
\ . l:compile_commands_option
|
||||
\ . ale#Var(a:buffer, 'c_cppcheck_options')
|
||||
\ . '%e -q --language=c'
|
||||
\ . ale#Pad(l:compile_commands_option)
|
||||
\ . ale#Pad(ale#Var(a:buffer, 'c_cppcheck_options'))
|
||||
\ . ' %t'
|
||||
endfunction
|
||||
|
||||
|
|
|
@ -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,
|
||||
" 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:cd_command = !empty(l:compile_commmands_path)
|
||||
\ ? ale#path#CdString(fnamemodify(l:compile_commmands_path, ':h'))
|
||||
\ : ''
|
||||
let l:compile_commands_option = !empty(l:compile_commmands_path)
|
||||
\ ? '--project=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:compile_commands_option = !empty(l:json_path)
|
||||
\ ? '--project=' . ale#Escape(l:json_path[len(l:dir) + 1: ])
|
||||
\ : ''
|
||||
|
||||
return l:cd_command
|
||||
\ . '%e -q --language=c++ '
|
||||
\ . l:compile_commands_option
|
||||
\ . ale#Var(a:buffer, 'cpp_cppcheck_options')
|
||||
\ . '%e -q --language=c++'
|
||||
\ . ale#Pad(l:compile_commands_option)
|
||||
\ . ale#Pad(ale#Var(a:buffer, 'cpp_cppcheck_options'))
|
||||
\ . ' %t'
|
||||
endfunction
|
||||
|
||||
|
|
|
@ -21,4 +21,16 @@ Execute(cppcheck for C++ should detect compile_commands.json files):
|
|||
AssertLinter 'cppcheck',
|
||||
\ ale#path#CdString(ale#path#Simplify(g:dir . '/cppcheck_paths/one'))
|
||||
\ . 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'
|
||||
|
|
|
@ -17,6 +17,18 @@ Execute(cppcheck for C++ should detect compile_commands.json files):
|
|||
call ale#test#SetFilename('cppcheck_paths/one/foo.cpp')
|
||||
|
||||
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')
|
||||
\ . ' -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'
|
||||
|
|
Reference in a new issue