Merge pull request #2168 from fx-carton/master

Fix CFLAGS & Makefile issues
This commit is contained in:
w0rp 2019-01-03 20:37:16 +00:00 committed by GitHub
commit 1b264b8662
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 10 deletions

View File

@ -48,26 +48,38 @@ endfunction
function! ale#c#ParseCFlags(path_prefix, cflag_line) abort
let l:cflags_list = []
let l:previous_options = []
let l:previous_options = ''
let l:split_lines = split(a:cflag_line, '-')
let l:split_lines = split(a:cflag_line, ' ')
let l:option_index = 0
while l:option_index < len(l:split_lines)
let l:option = l:split_lines[l:option_index]
let l:option = l:previous_options . l:split_lines[l:option_index]
let l:option_index = l:option_index + 1
call add(l:previous_options, l:option)
" Check if cflag contained a '-' and should not have been splitted
let l:option_list = split(l:option, '\zs')
if len(l:option_list) > 0 && l:option_list[-1] isnot# ' ' && l:option_index < len(l:split_lines)
" Check if cflag contained an unmatched characters and should not have been splitted
let l:option_special = substitute(l:option, '\\"', '', 'g')
let l:option_special = substitute(l:option_special, '[^"''()`]', '', 'g')
let l:option_special = substitute(l:option_special, '""', '', 'g')
let l:option_special = substitute(l:option_special, '''''', '', 'g')
let l:option_special = substitute(l:option_special, '``', '', 'g')
let l:option_special = substitute(l:option_special, '((', '(', 'g')
let l:option_special = substitute(l:option_special, '))', ')', 'g')
let l:option_special = substitute(l:option_special, '()', '', 'g')
if len(l:option_special) > 0 && l:option_index < len(l:split_lines)
let l:previous_options = l:option . ' '
continue
endif
let l:option = join(l:previous_options, '-')
let l:previous_options = []
" Check if there was spaces after -D/-I and the flag should not have been splitted
if l:option is# '-D' || l:option is# '-I'
let l:previous_options = l:option
continue
endif
let l:previous_options = ''
let l:option = '-' . substitute(l:option, '^\s*\(.\{-}\)\s*$', '\1', '')
" Fix relative paths if needed
if stridx(l:option, '-I') >= 0 &&

View File

@ -177,3 +177,20 @@ Execute(ParseCompileCommandsFlags should parse some basic flags):
\ 'file': ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'),
\ },
\ ])
Execute(ParseCFlags should not merge flags):
AssertEqual
\ '-Dgoal=9'
\ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir'))
\ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir with spaces'))
\ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir-with-dash'))
\ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')),
\ ale#c#ParseCFlags(
\ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
\ 'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir '
\ . 'subdir/somedep1.o ' . 'subdir/somedep2.o '
\ . '-I''dir with spaces''' . ' -Idir-with-dash '
\ . 'subdir/somedep3.o ' . 'subdir/somedep4.o '
\ . ' -I'. ale#path#Simplify('kernel/include') . ' '
\ . 'subdir/somedep5.o ' . 'subdir/somedep6.o '
\ )