Fix #3247 - Use --always-make for make -n by default

This commit is contained in:
w0rp 2020-08-29 16:05:49 +01:00
parent bc3a843e10
commit 7e0cdb53ec
No known key found for this signature in database
GPG key ID: 0FC1ECAA8C81CD83
4 changed files with 43 additions and 1 deletions

View file

@ -2,7 +2,9 @@
" Description: Functions for integrating with C-family linters.
call ale#Set('c_parse_makefile', 0)
call ale#Set('c_always_make', has('unix') && !has('macunix'))
call ale#Set('c_parse_compile_commands', 1)
let s:sep = has('win32') ? '\' : '/'
" Set just so tests can override it.
@ -504,7 +506,10 @@ function! ale#c#GetMakeCommand(buffer) abort
let l:path = ale#path#FindNearestFile(a:buffer, 'Makefile')
if !empty(l:path)
return ale#path#CdString(fnamemodify(l:path, ':h')) . 'make -n'
let l:always_make = ale#Var(a:buffer, 'c_always_make')
return ale#path#CdString(fnamemodify(l:path, ':h'))
\ . 'make -n' . (l:always_make ? ' --always-make' : '')
endif
endif

View file

@ -8,6 +8,17 @@ runs either `clang`, or `gcc`. See |ale-c-cc|.
===============================================================================
Global Options
g:ale_c_always_make *g:ale_c_always_make*
*b:ale_c_always_make*
Type: |Number|
Default: `has('unix') && !has('macunix')`
If set to `1`, use `--always-make` for `make`, which means that output will
always be parsed from `make` dry runs with GNU make. BSD `make` does not
support this option, so you probably want to turn this option off when using
a BSD variant.
g:ale_c_build_dir_names *g:ale_c_build_dir_names*
*b:ale_c_build_dir_names*
@ -58,6 +69,11 @@ g:ale_c_parse_makefile *g:ale_c_parse_makefile*
set for C or C++ compilers. This can make it easier to determine the correct
build flags to use for different files.
NOTE: When using this option on BSD, you may need to set
|g:ale_c_always_make| to `0`, and `make -n` will not provide consistent
results if binaries have already been built, so use `make clean` when
editing your files.
WARNING: Running `make -n` automatically can execute arbitrary code, even
though it's supposed to be a dry run, so enable this option with care. You
might prefer to use the buffer-local version of the option instead with

View file

@ -10,6 +10,7 @@ Global Options
The following C options also apply to some C++ linters too.
* |g:ale_c_always_make|
* |g:ale_c_build_dir_names|
* |g:ale_c_build_dir|
* |g:ale_c_parse_makefile|

View file

@ -1,9 +1,13 @@
Before:
Save g:ale_c_parse_makefile
Save g:ale_c_always_make
Save b:ale_c_always_make
call ale#test#SetDirectory('/testplugin/test')
let g:ale_c_parse_makefile = 1
let g:ale_c_always_make = 1
let b:ale_c_always_make = 1
function SplitAndParse(path_prefix, command) abort
let l:args = ale#c#ShellSplit(a:command)
@ -18,6 +22,22 @@ After:
call ale#test#RestoreDirectory()
Execute(The make command should be correct):
call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c')
AssertEqual
\ ale#path#CdString(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'))
\ . 'make -n --always-make',
\ ale#c#GetMakeCommand(bufnr(''))
" You should be able to disable --always-make for a buffer.
let b:ale_c_always_make = 0
AssertEqual
\ ale#path#CdString(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'))
\ . 'make -n',
\ ale#c#GetMakeCommand(bufnr(''))
Execute(The CFlags parser should be able to parse include directives):
call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c')