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 4, 2017
1 parent 490b3ee commit 3e61b03
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
27 changes: 22 additions & 5 deletions ycmd/completers/cpp/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ 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
flags_without_preceeding_dash = []

for flag in flags:
previous_flag_starts_with_dash = current_flag_starts_with_dash
Expand All @@ -400,6 +402,9 @@ def _RemoveUnusedFlags( flags, filename ):
skip_next = False
continue

if flag == '--driver-mode=cl':
enable_windows_style_flags = True

if flag in STATE_FLAGS_TO_SKIP:
continue

Expand All @@ -417,15 +422,27 @@ 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 ) ) ):
continue
( not previous_flag_starts_with_dash or
( not previous_flag_is_include and '/' in flag ) ) ):
flags_without_preceeding_dash.append( flag )
else:
new_flags.append( flag )
previous_flag_is_include = flag in INCLUDE_FLAGS

if enable_windows_style_flags:
new_flags += _FilterWindowsFlags( flags_without_preceeding_dash )

new_flags.append( flag )
previous_flag_is_include = flag in INCLUDE_FLAGS
return new_flags


def _FilterWindowsFlags( flags ):
valid_flags = []
for flag in flags:
if not os.path.exists( os.path.abspath( flag ) ):
valid_flags.append( flag )
return valid_flags


# There are 2 ways to get a development enviornment (as standard) on OS X:
# - install XCode.app, or
# - install the command-line tools (xcode-select --install)
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 3e61b03

Please sign in to comment.