fix: cflags parser: no absolute path for '-include' (#3775)

Both '-include' and '-imacros' take a file as an argument that will then
be searched in the include path like a regular '#include "..."'
statement in a source file. As such, they should not have their path
converted to an absolute path.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
This commit is contained in:
Michael Jeanson 2021-07-04 08:27:55 -04:00 committed by GitHub
parent f9332bae1f
commit 9efa96eb94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 10 deletions

View File

@ -151,8 +151,6 @@ function! ale#c#ParseCFlags(path_prefix, should_quote, raw_arguments) abort
\ || stridx(l:option, '-isystem') == 0 \ || stridx(l:option, '-isystem') == 0
\ || stridx(l:option, '-idirafter') == 0 \ || stridx(l:option, '-idirafter') == 0
\ || stridx(l:option, '-iframework') == 0 \ || stridx(l:option, '-iframework') == 0
\ || stridx(l:option, '-include') == 0
\ || stridx(l:option, '-imacros') == 0
if stridx(l:option, '-I') == 0 && l:option isnot# '-I' if stridx(l:option, '-I') == 0 && l:option isnot# '-I'
let l:arg = join(split(l:option, '\zs')[2:], '') let l:arg = join(split(l:option, '\zs')[2:], '')
let l:option = '-I' let l:option = '-I'
@ -182,6 +180,7 @@ function! ale#c#ParseCFlags(path_prefix, should_quote, raw_arguments) abort
" Options that have an argument (always separate) " Options that have an argument (always separate)
elseif l:option is# '-iprefix' || stridx(l:option, '-iwithprefix') == 0 elseif l:option is# '-iprefix' || stridx(l:option, '-iwithprefix') == 0
\ || l:option is# '-isysroot' || l:option is# '-imultilib' \ || l:option is# '-isysroot' || l:option is# '-imultilib'
\ || l:option is# '-include' || l:option is# '-imacros'
call add(l:items, [0, l:option]) call add(l:items, [0, l:option])
call add(l:items, [0, l:arguments[l:option_index]]) call add(l:items, [0, l:arguments[l:option_index]])
let l:option_index = l:option_index + 1 let l:option_index = l:option_index + 1

View File

@ -495,8 +495,8 @@ Execute(We should include several important flags):
\ . ' -isystem ' . ale#Escape(ale#path#Simplify(g:dir . '/test-files/c/makefile_project/incsystem')) \ . ' -isystem ' . ale#Escape(ale#path#Simplify(g:dir . '/test-files/c/makefile_project/incsystem'))
\ . ' -idirafter ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/incafter')) \ . ' -idirafter ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/incafter'))
\ . ' -iframework ' . ale#Escape(ale#path#Simplify(g:dir . '/test-files/c/makefile_project/incframework')) \ . ' -iframework ' . ale#Escape(ale#path#Simplify(g:dir . '/test-files/c/makefile_project/incframework'))
\ . ' -include ' . ale#Escape(ale#path#Simplify(g:dir . '/test-files/c/makefile_project/foo bar')) \ . ' -include file.h'
\ . ' -imacros ' . ale#Escape(ale#path#Simplify(g:dir . '/test-files/c/makefile_project/incmacros')) \ . ' -imacros macros.h'
\ . ' -Dmacro="value"' \ . ' -Dmacro="value"'
\ . ' -DGoal=9' \ . ' -DGoal=9'
\ . ' -D macro2' \ . ' -D macro2'
@ -525,9 +525,9 @@ Execute(We should include several important flags):
\ '-iframework', \ '-iframework',
\ 'incframework', \ 'incframework',
\ '-include', \ '-include',
\ '''foo bar''', \ 'file.h',
\ '-imacros', \ '-imacros',
\ 'incmacros', \ 'macros.h',
\ '-Dmacro="value"', \ '-Dmacro="value"',
\ '-DGoal=9', \ '-DGoal=9',
\ '-D', \ '-D',
@ -575,8 +575,8 @@ Execute(We should quote the flags we need to quote):
\ . ' -isystem ' . ale#Escape(ale#path#Simplify(g:dir . '/test-files/c/makefile_project/incsystem')) \ . ' -isystem ' . ale#Escape(ale#path#Simplify(g:dir . '/test-files/c/makefile_project/incsystem'))
\ . ' -idirafter ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/incafter')) \ . ' -idirafter ' . ale#Escape(ale#path#Simplify(g:dir. '/test-files/c/makefile_project/incafter'))
\ . ' -iframework ' . ale#Escape(ale#path#Simplify(g:dir . '/test-files/c/makefile_project/incframework')) \ . ' -iframework ' . ale#Escape(ale#path#Simplify(g:dir . '/test-files/c/makefile_project/incframework'))
\ . ' -include ' . ale#Escape(ale#path#Simplify(g:dir . '/test-files/c/makefile_project/foo bar')) \ . ' -include file.h'
\ . ' -imacros ' . ale#Escape(ale#path#Simplify(g:dir . '/test-files/c/makefile_project/incmacros')) \ . ' -imacros macros.h'
\ . ' ' . ale#Escape('-Dmacro="value"') \ . ' ' . ale#Escape('-Dmacro="value"')
\ . ' -DGoal=9' \ . ' -DGoal=9'
\ . ' -D macro2' \ . ' -D macro2'
@ -608,9 +608,9 @@ Execute(We should quote the flags we need to quote):
\ '-iframework', \ '-iframework',
\ 'incframework', \ 'incframework',
\ '-include', \ '-include',
\ '''foo bar''', \ 'file.h',
\ '-imacros', \ '-imacros',
\ 'incmacros', \ 'macros.h',
\ '-Dmacro="value"', \ '-Dmacro="value"',
\ '-DGoal=9', \ '-DGoal=9',
\ '-D', \ '-D',