diff --git a/autoload/ale/c.vim b/autoload/ale/c.vim index d0a4fa06..cff53125 100644 --- a/autoload/ale/c.vim +++ b/autoload/ale/c.vim @@ -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 diff --git a/doc/ale-c.txt b/doc/ale-c.txt index fe28cf4a..b0d94b8e 100644 --- a/doc/ale-c.txt +++ b/doc/ale-c.txt @@ -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 diff --git a/doc/ale-cpp.txt b/doc/ale-cpp.txt index 651b4160..17894e6e 100644 --- a/doc/ale-cpp.txt +++ b/doc/ale-cpp.txt @@ -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| diff --git a/test/test_c_flag_parsing.vader b/test/test_c_flag_parsing.vader index 076be6a1..99722b17 100644 --- a/test/test_c_flag_parsing.vader +++ b/test/test_c_flag_parsing.vader @@ -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')