Skip to content

Commit

Permalink
Windows style flags
Browse files Browse the repository at this point in the history
  • Loading branch information
bstaletic committed Jul 5, 2017
1 parent 490b3ee commit 1581d48
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ycmd/completers/cpp/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,11 @@ def _RemoveUnusedFlags( flags, filename ):
previous_flag_is_include = False
previous_flag_starts_with_dash = False
current_flag_starts_with_dash = False
enable_windows_style_flags = False

for flag in flags:
if flag.startswith( '--driver-mode' ):
enable_windows_style_flags = ( flag == '--driver-mode=cl' )

for flag in flags:
previous_flag_starts_with_dash = current_flag_starts_with_dash
Expand All @@ -417,12 +422,15 @@ def _RemoveUnusedFlags( flags, filename ):
# flags for headers. The returned flags include "foo.cpp" and we need to
# remove that.
if ( not current_flag_starts_with_dash and
( not previous_flag_starts_with_dash or
( not previous_flag_is_include and '/' in flag ) ) ):
( not previous_flag_starts_with_dash or
( not previous_flag_is_include and '/' in flag ) ) and
( not enable_windows_style_flags or
( enable_windows_style_flags and os.path.exists( flag ) ) ) ):
continue

new_flags.append( flag )
previous_flag_is_include = flag in INCLUDE_FLAGS

return new_flags


Expand Down
11 changes: 11 additions & 0 deletions ycmd/tests/clang/flags_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,17 @@ def RemoveUnusedFlags_RemoveFlagWithoutPrecedingDashFlag_test():
eq_( expected,
flags._RemoveUnusedFlags( expected[ :1 ] + to_remove + expected[ 1: ],
filename ) )
expected = [ 'g++', '-foo', '--driver-mode=cl', '-xc++', '-bar',
'include_dir', '/foo' ]
to_remove = [ '..' ]
filename = 'file'

eq_( expected,
flags._RemoveUnusedFlags( expected + to_remove, filename ) )

eq_( expected,
flags._RemoveUnusedFlags( expected[ :1 ] + to_remove + expected[ 1: ],
filename ) )


def RemoveUnusedFlags_Depfiles_test():
Expand Down

0 comments on commit 1581d48

Please sign in to comment.