summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfx-carton <40282476+fx-carton@users.noreply.github.com>2019-08-17 13:08:14 -0500
committerw0rp <w0rp@users.noreply.github.com>2019-08-17 19:08:14 +0100
commitb62e30622269726d71fb0dbf1c7046ee77cb86f1 (patch)
treef4ae6e1545c7c35f5f171565c391b96abc867669
parent5388ff1d54e05cfaa9429cdbf9a2cacba94d190f (diff)
downloadale-b62e30622269726d71fb0dbf1c7046ee77cb86f1.zip
Fix cflags parsing (#2510, #2265) (#2590)
* Parse CFLAGS that can be passed using a whitelist I went through GCC's man page and selected flags that can safely be passed to GCC and that can be useful to syntax checking. These include: - -I/-i* include flags - preprocessor flags such as -D - -W* warning flags - -O* optimization flags - most -f options - -m arch dependent options * Fix CFLAGS tests: -Idir is now parsed to -I dir * Added two tests for flags we want or don't want to pass. * Also check for / in addition to s:sep
-rw-r--r--autoload/ale/c.vim131
-rw-r--r--test/test_c_flag_parsing.vader162
2 files changed, 199 insertions, 94 deletions
diff --git a/autoload/ale/c.vim b/autoload/ale/c.vim
index 2d2083da..5540ec14 100644
--- a/autoload/ale/c.vim
+++ b/autoload/ale/c.vim
@@ -28,76 +28,107 @@ function! ale#c#GetBuildDirectory(buffer) abort
return ale#path#Dirname(l:json_file)
endfunction
-function! ale#c#AreSpecialCharsBalanced(option) abort
- " Escape \"
- let l:option_escaped = substitute(a:option, '\\"', '', 'g')
-
- " Retain special chars only
- let l:special_chars = substitute(l:option_escaped, '[^"''()`]', '', 'g')
- let l:special_chars = split(l:special_chars, '\zs')
-
- " Check if they are balanced
+function! ale#c#ShellSplit(line) abort
let l:stack = []
+ let l:args = ['']
+ let l:prev = ''
- for l:char in l:special_chars
- if l:char is# ')'
- if len(l:stack) == 0 || get(l:stack, -1) isnot# '('
- return 0
+ for l:char in split(a:line, '\zs')
+ if l:char is# ''''
+ if len(l:stack) > 0 && get(l:stack, -1) is# ''''
+ call remove(l:stack, -1)
+ elseif (len(l:stack) == 0 || get(l:stack, -1) isnot# '"') && l:prev isnot# '\'
+ call add(l:stack, l:char)
endif
-
- call remove(l:stack, -1)
- elseif l:char is# '('
- call add(l:stack, l:char)
- else
+ elseif (l:char is# '"' || l:char is# '`') && l:prev isnot# '\'
if len(l:stack) > 0 && get(l:stack, -1) is# l:char
call remove(l:stack, -1)
- else
+ elseif len(l:stack) == 0 || get(l:stack, -1) isnot# ''''
call add(l:stack, l:char)
endif
+ elseif (l:char is# '(' || l:char is# '[' || l:char is# '{') && l:prev isnot# '\'
+ if len(l:stack) == 0 || get(l:stack, -1) isnot# ''''
+ call add(l:stack, l:char)
+ endif
+ elseif (l:char is# ')' || l:char is# ']' || l:char is# '}') && l:prev isnot# '\'
+ if len(l:stack) > 0 && get(l:stack, -1) is# {')': '(', ']': '[', '}': '{'}[l:char]
+ call remove(l:stack, -1)
+ endif
+ elseif l:char is# ' ' && len(l:stack) == 0
+ if len(get(l:args, -1)) > 0
+ call add(l:args, '')
+ endif
+
+ continue
endif
+
+ let l:args[-1] = get(l:args, -1) . l:char
endfor
- return len(l:stack) == 0
+ return l:args
endfunction
function! ale#c#ParseCFlags(path_prefix, cflag_line) abort
- let l:split_lines = split(a:cflag_line)
+ let l:cflags_list = []
+
+ let l:split_lines = ale#c#ShellSplit(a:cflag_line)
let l:option_index = 0
while l:option_index < len(l:split_lines)
- let l:next_option_index = l:option_index + 1
-
- " Join space-separated option
- while l:next_option_index < len(l:split_lines)
- \&& stridx(l:split_lines[l:next_option_index], '-') != 0
- let l:next_option_index += 1
- endwhile
-
- let l:option = join(l:split_lines[l:option_index : l:next_option_index-1], ' ')
- call remove(l:split_lines, l:option_index, l:next_option_index-1)
- call insert(l:split_lines, l:option, l:option_index)
-
- " Ignore invalid or conflicting options
- if stridx(l:option, '-') != 0
- \|| stridx(l:option, '-o') == 0
- \|| stridx(l:option, '-c') == 0
- call remove(l:split_lines, l:option_index)
- let l:option_index = l:option_index - 1
- " Fix relative path
- elseif stridx(l:option, '-I') == 0
- if !(stridx(l:option, ':') == 2+1 || stridx(l:option, '/') == 2+0)
- let l:option = '-I' . a:path_prefix . s:sep . l:option[2:]
- call remove(l:split_lines, l:option_index)
- call insert(l:split_lines, l:option, l:option_index)
+ let l:option = l:split_lines[l:option_index]
+ let l:option_index = l:option_index + 1
+
+ " Include options, that may need relative path fix
+ if stridx(l:option, '-I') == 0
+ \ || stridx(l:option, '-iquote') == 0
+ \ || stridx(l:option, '-isystem') == 0
+ \ || stridx(l:option, '-idirafter') == 0
+ if stridx(l:option, '-I') == 0 && l:option isnot# '-I'
+ let l:arg = join(split(l:option, '\zs')[2:], '')
+ let l:option = '-I'
+ else
+ let l:arg = l:split_lines[l:option_index]
+ let l:option_index = l:option_index + 1
endif
- endif
- let l:option_index = l:option_index + 1
- endwhile
+ " Fix relative paths if needed
+ if stridx(l:arg, s:sep) != 0 && stridx(l:arg, '/') != 0
+ let l:rel_path = substitute(l:arg, '"', '', 'g')
+ let l:rel_path = substitute(l:rel_path, '''', '', 'g')
+ let l:arg = ale#Escape(a:path_prefix . s:sep . l:rel_path)
+ endif
+
+ call add(l:cflags_list, l:option)
+ call add(l:cflags_list, l:arg)
+ " Options with arg that can be grouped with the option or separate
+ elseif stridx(l:option, '-D') == 0 || stridx(l:option, '-B') == 0
+ call add(l:cflags_list, l:option)
- call uniq(l:split_lines)
+ if l:option is# '-D' || l:option is# '-B'
+ call add(l:cflags_list, l:split_lines[l:option_index])
+ let l:option_index = l:option_index + 1
+ endif
+ " Options that have an argument (always separate)
+ elseif l:option is# '-iprefix' || stridx(l:option, '-iwithprefix') == 0
+ \ || l:option is# '-isysroot' || l:option is# '-imultilib'
+ call add(l:cflags_list, l:option)
+ call add(l:cflags_list, l:split_lines[l:option_index])
+ let l:option_index = l:option_index + 1
+ " Options without argument
+ elseif (stridx(l:option, '-W') == 0 && stridx(l:option, '-Wa,') != 0 && stridx(l:option, '-Wl,') != 0 && stridx(l:option, '-Wp,') != 0)
+ \ || l:option is# '-w' || stridx(l:option, '-pedantic') == 0
+ \ || l:option is# '-ansi' || stridx(l:option, '-std=') == 0
+ \ || (stridx(l:option, '-f') == 0 && stridx(l:option, '-fdump') != 0 && stridx(l:option, '-fdiagnostics') != 0 && stridx(l:option, '-fno-show-column') != 0)
+ \ || stridx(l:option, '-O') == 0
+ \ || l:option is# '-C' || l:option is# '-CC' || l:option is# '-trigraphs'
+ \ || stridx(l:option, '-nostdinc') == 0 || stridx(l:option, '-iplugindir=') == 0
+ \ || stridx(l:option, '--sysroot=') == 0 || l:option is# '--no-sysroot-suffix'
+ \ || stridx(l:option, '-m') == 0
+ call add(l:cflags_list, l:option)
+ endif
+ endwhile
- return join(l:split_lines, ' ')
+ return join(l:cflags_list, ' ')
endfunction
function! ale#c#ParseCFlagsFromMakeOutput(buffer, make_output) abort
diff --git a/test/test_c_flag_parsing.vader b/test/test_c_flag_parsing.vader
index 045554a3..8ae6f9dc 100644
--- a/test/test_c_flag_parsing.vader
+++ b/test/test_c_flag_parsing.vader
@@ -14,7 +14,7 @@ Execute(The CFlags parser should be able to parse include directives):
call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c')
AssertEqual
- \ '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir'),
+ \ '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')),
\ ale#c#ParseCFlagsFromMakeOutput(bufnr(''), ['gcc -Isubdir -c file.c'])
AssertEqual
@@ -25,14 +25,14 @@ Execute(ParseCFlags should ignore -c and -o):
call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c')
AssertEqual
- \ '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir'),
+ \ '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')),
\ ale#c#ParseCFlagsFromMakeOutput(bufnr(''), ['gcc -Isubdir -c file.c -o a.out'])
Execute(The CFlags parser should be able to parse macro directives):
call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c')
AssertEqual
- \ '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')
+ \ '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir'))
\ . ' -DTEST=1',
\ ale#c#ParseCFlagsFromMakeOutput(bufnr(''), ['gcc -Isubdir -DTEST=1 -c file.c'])
@@ -40,7 +40,7 @@ Execute(The CFlags parser should be able to parse macro directives with spaces):
call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c')
AssertEqual
- \ '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')
+ \ '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir'))
\ . ' -DTEST=$(( 2 * 4 ))',
\ ale#c#ParseCFlagsFromMakeOutput(bufnr(''), ['gcc -Isubdir -DTEST=$(( 2 * 4 )) -c file.c'])
@@ -48,14 +48,14 @@ Execute(The CFlags parser should be able to parse shell directives with spaces):
call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c')
AssertEqual
- \ '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')
+ \ '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir'))
\ . ' -DTEST=`date +%s`',
\ ale#c#ParseCFlagsFromMakeOutput(bufnr(''), ['gcc -Isubdir -DTEST=`date +%s` -c file.c'])
Execute(ParseCFlags should be able to parse flags with relative paths):
AssertEqual
- \ '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')
- \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')
+ \ '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir'))
+ \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include'))
\ . ' -DTEST=`date +%s`',
\ ale#c#ParseCFlags(
\ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
@@ -67,8 +67,8 @@ Execute(ParseCFlags should be able to parse flags with relative paths):
Execute(ParseCFlags should be able to parse -Dgoal):
AssertEqual
\ '-Dgoal=9'
- \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')
- \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')
+ \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir'))
+ \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include'))
\ . ' -DTEST=`date +%s`',
\ ale#c#ParseCFlags(
\ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
@@ -77,16 +77,30 @@ Execute(ParseCFlags should be able to parse -Dgoal):
\ . ' -DTEST=`date +%s` -c file.c'
\ )
+Execute(ParseCFlags should ignore -T and other arguments):
+ AssertEqual
+ \ '-Dgoal=9'
+ \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir'))
+ \ . ' ' . '--sysroot=subdir'
+ \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include'))
+ \ . ' -DTEST=`date +%s`',
+ \ ale#c#ParseCFlags(
+ \ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
+ \ 'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir --sysroot=subdir '
+ \ . '-I'. ale#path#Simplify('kernel/include')
+ \ . ' -DTEST=`date +%s` -c file.c'
+ \ )
+
Execute(ParseCFlags should handle paths with spaces in double quotes):
AssertEqual
\ '-Dgoal=9'
- \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')
- \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/"dir with spaces"')
- \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')
+ \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir'))
+ \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir with spaces'))
+ \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include'))
\ . ' -DTEST=`date +%s`',
\ ale#c#ParseCFlags(
\ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
- \ 'gcc -Dgoal=9 -Isubdir '
+ \ 'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir '
\ . '-I"dir with spaces"' . ' -I'. ale#path#Simplify('kernel/include')
\ . ' -DTEST=`date +%s` -c file.c'
\ )
@@ -94,28 +108,29 @@ Execute(ParseCFlags should handle paths with spaces in double quotes):
Execute(ParseCFlags should handle paths with spaces in single quotes):
AssertEqual
\ '-Dgoal=9'
- \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')
- \ . ' ' . '-I' . ale#path#Simplify(g:dir. "/test_c_projects/makefile_project/'dir with spaces'")
- \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')
+ \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir'))
+ \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir with spaces'))
+ \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include'))
\ . ' -DTEST=`date +%s`',
\ ale#c#ParseCFlags(
\ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
- \ 'gcc -Dgoal=9 -Isubdir '
- \ . "-I'dir with spaces'" . ' -I'. ale#path#Simplify('kernel/include')
+ \ 'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir '
+ \ . '-I''dir with spaces''' . ' -I'. ale#path#Simplify('kernel/include')
\ . ' -DTEST=`date +%s` -c file.c'
\ )
Execute(ParseCFlags should handle paths with minuses):
AssertEqual
\ '-Dgoal=9'
- \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')
- \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir-with-dash')
- \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')
+ \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir'))
+ \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir with spaces'))
+ \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir-with-dash'))
+ \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include'))
\ . ' -DTEST=`date +%s`',
\ ale#c#ParseCFlags(
\ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
- \ 'gcc -Dgoal=9 -Isubdir '
- \ . ' -Idir-with-dash'
+ \ 'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir '
+ \ . '-I''dir with spaces''' . ' -Idir-with-dash'
\ . ' -I'. ale#path#Simplify('kernel/include')
\ . ' -DTEST=`date +%s` -c file.c'
\ )
@@ -123,14 +138,17 @@ Execute(ParseCFlags should handle paths with minuses):
Execute(ParseCFlags should handle -D with minuses):
AssertEqual
\ '-Dgoal=9'
- \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')
+ \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir'))
\ . ' -Dmacro-with-dash'
- \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')
+ \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir with spaces'))
+ \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir-with-dash'))
+ \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include'))
\ . ' -DTEST=`date +%s`',
\ ale#c#ParseCFlags(
\ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
- \ 'gcc -Dgoal=9 -Isubdir '
+ \ 'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir '
\ . '-Dmacro-with-dash '
+ \ . '-I''dir with spaces''' . ' -Idir-with-dash'
\ . ' -I'. ale#path#Simplify('kernel/include')
\ . ' -DTEST=`date +%s` -c file.c'
\ )
@@ -138,11 +156,16 @@ Execute(ParseCFlags should handle -D with minuses):
Execute(ParseCFlags should handle flags at the end of the line):
AssertEqual
\ '-Dgoal=9'
- \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')
- \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include'),
+ \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir'))
+ \ . ' -Dmacro-with-dash'
+ \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir with spaces'))
+ \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir-with-dash'))
+ \ . ' ' . '-I' . ' ' . ale#Escape(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 -Isubdir '
+ \ 'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir '
+ \ . '-Dmacro-with-dash '
+ \ . '-I''dir with spaces''' . ' -Idir-with-dash'
\ . ' -I'. ale#path#Simplify('kernel/include')
\ )
@@ -156,14 +179,14 @@ Execute(ParseCompileCommandsFlags should parse some basic flags):
silent noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'))
AssertEqual
- \ '-I/usr/include/xmms2',
+ \ '-I ' . ale#path#Simplify('/usr/include/xmms2'),
\ ale#c#ParseCompileCommandsFlags(bufnr(''), { "xmms2-mpris.c": [
\ {
- \ 'directory': '/foo/bar/xmms2-mpris',
- \ 'command': '/usr/bin/cc -I' . '/usr/include/xmms2'
+ \ 'directory': ale#path#Simplify('/foo/bar/xmms2-mpris'),
+ \ 'command': '/usr/bin/cc -I' . ale#path#Simplify('/usr/include/xmms2')
\ . ' -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o'
- \ . ' -c ' . '/foo/bar/xmms2-mpris/src/xmms2-mpris.c',
- \ 'file': '/foo/bar/xmms2-mpris/src/xmms2-mpris.c',
+ \ . ' -c ' . ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'),
+ \ 'file': ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'),
\ },
\ ] }, {})
@@ -183,14 +206,14 @@ Execute(ParseCompileCommandsFlags should fall back to files in the same director
silent noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'))
AssertEqual
- \ '-I/usr/include/xmms2',
+ \ '-I ' . ale#path#Simplify('/usr/include/xmms2'),
\ ale#c#ParseCompileCommandsFlags(bufnr(''), {}, { "src": [
\ {
- \ 'directory': '/foo/bar/xmms2-mpris',
- \ 'command': '/usr/bin/cc -I' . '/usr/include/xmms2'
+ \ 'directory': ale#path#Simplify('/foo/bar/xmms2-mpris'),
+ \ 'command': '/usr/bin/cc -I' . ale#path#Simplify('/usr/include/xmms2')
\ . ' -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o'
- \ . ' -c ' . '/foo/bar/xmms2-mpris/src/xmms2-mpris.c',
- \ 'file': (has('win32') ? 'C:' : '') . '/foo/bar/xmms2-mpris/src/xmms2-other.c',
+ \ . ' -c ' . ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'),
+ \ 'file': ale#path#Simplify((has('win32') ? 'C:' : '') . '/foo/bar/xmms2-mpris/src/xmms2-other.c'),
\ },
\ ] })
@@ -198,7 +221,7 @@ Execute(ParseCompileCommandsFlags should take commands from matching .c files fo
silent noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.h'))
AssertEqual
- \ '-I/usr/include/xmms2',
+ \ '-I /usr/include/xmms2',
\ ale#c#ParseCompileCommandsFlags(
\ bufnr(''),
\ {
@@ -220,7 +243,7 @@ Execute(ParseCompileCommandsFlags should take commands from matching .cpp files
silent noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.hpp'))
AssertEqual
- \ '-I/usr/include/xmms2',
+ \ '-I /usr/include/xmms2',
\ ale#c#ParseCompileCommandsFlags(
\ bufnr(''),
\ {
@@ -242,7 +265,7 @@ Execute(ParseCompileCommandsFlags should take commands from matching .cpp files
silent noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.h'))
AssertEqual
- \ '-I/usr/include/xmms2',
+ \ '-I /usr/include/xmms2',
\ ale#c#ParseCompileCommandsFlags(
\ bufnr(''),
\ {
@@ -282,13 +305,64 @@ Execute(ParseCompileCommandsFlags should not take commands from .c files for .h
\ },
\ )
+Execute(ParseCFlags should not merge flags):
+ AssertEqual
+ \ '-Dgoal=9'
+ \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir'))
+ \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir with spaces'))
+ \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir-with-dash'))
+ \ . ' ' . '-I' . ' ' . ale#Escape(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 '
+ \ )
+
Execute(ParseCFlags should handle parenthesis and quotes):
AssertEqual
- \ '-Dgoal=9 -Dtest1="('' '')" file1.o -Dtest2=''(` `)'' file2.o -Dtest3=`(" ")` file3.o',
+ \ '-Dgoal=9 -Dtest1="('' '')" -Dtest2=''(` `)'' -Dtest3=`(" ")`',
\ ale#c#ParseCFlags(
\ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
- \ 'gcc -Dgoal=9 '
+ \ 'gcc -Dgoal=9 -Tlinkerfile.ld blabla '
\ . '-Dtest1="('' '')" file1.o '
\ . '-Dtest2=''(` `)'' file2.o '
\ . '-Dtest3=`(" ")` file3.o '
\ )
+
+Execute(CFlags we want to pass):
+ AssertEqual
+ \ '-I ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/inc'))
+ \ . ' -I ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/include'))
+ \ . ' -iquote ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/incquote'))
+ \ . ' -isystem ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/incsystem'))
+ \ . ' -idirafter ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/incafter'))
+ \ . ' -Dmacro=value -D macro2 -Bbdir -B bdir2'
+ \ . ' -iprefix prefix -iwithprefix prefix2 -iwithprefixbefore prefix3'
+ \ . ' -isysroot sysroot --sysroot=test --no-sysroot-suffix -imultilib multidir'
+ \ . ' -Wsome-warning -std=c89 -pedantic -pedantic-errors -ansi'
+ \ . ' -foption -O2 -C -CC -trigraphs -nostdinc -nostdinc++'
+ \ . ' -iplugindir=dir -march=native -w',
+ \ ale#c#ParseCFlags(
+ \ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
+ \ 'gcc'
+ \ . ' -Iinc -I include -iquote incquote -isystem incsystem -idirafter incafter'
+ \ . ' -Dmacro=value -D macro2 -Bbdir -B bdir2'
+ \ . ' -iprefix prefix -iwithprefix prefix2 -iwithprefixbefore prefix3'
+ \ . ' -isysroot sysroot --sysroot=test --no-sysroot-suffix -imultilib multidir'
+ \ . ' -Wsome-warning -std=c89 -pedantic -pedantic-errors -ansi'
+ \ . ' -foption -O2 -C -CC -trigraphs -nostdinc -nostdinc++'
+ \ . ' -iplugindir=dir -march=native -w'
+ \ )
+
+Execute(CFlags we dont want to pass):
+ AssertEqual
+ \ '',
+ \ ale#c#ParseCFlags(
+ \ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'),
+ \ 'gcc -Wl,option -Wa,option -Wp,option filename.c somelib.a '
+ \ . '-fdump-file=name -fdiagnostics-arg -fno-show-column'
+ \ )