Calling PrepareClangFlags is not needed anymore

ycm_extra_conf.py files used to import clang_helpers and then use the
PrepareClangFlags function; this is now unnecessary since the logic from that
function has been moved to flags.py. The old PrepareClangFlags function is still
there (it just returns the flags it gets) for the sake of backwards
compatibility with old ycm_extra_conf.py files.
This commit is contained in:
Strahinja Val Markovic 2013-05-19 10:48:23 -07:00
parent 4978546e62
commit 45cbc7da7f
4 changed files with 43 additions and 30 deletions

View File

@ -30,7 +30,6 @@
import os import os
import ycm_core import ycm_core
from clang_helpers import PrepareClangFlags
# These are the compilation flags that will be used in case there's no # These are the compilation flags that will be used in case there's no
# compilation database set (by default, one is not set). # compilation database set (by default, one is not set).
@ -134,11 +133,9 @@ def FlagsForFile( filename ):
# Bear in mind that compilation_info.compiler_flags_ does NOT return a # Bear in mind that compilation_info.compiler_flags_ does NOT return a
# python list, but a "list-like" StringVec object # python list, but a "list-like" StringVec object
compilation_info = database.GetCompilationInfoForFile( filename ) compilation_info = database.GetCompilationInfoForFile( filename )
final_flags = PrepareClangFlags( final_flags = MakeRelativePathsInFlagsAbsolute(
MakeRelativePathsInFlagsAbsolute(
compilation_info.compiler_flags_, compilation_info.compiler_flags_,
compilation_info.compiler_working_dir_ ), compilation_info.compiler_working_dir_ )
filename )
# NOTE: This is just for YouCompleteMe; it's highly likely that your project # NOTE: This is just for YouCompleteMe; it's highly likely that your project
# does NOT need to remove the stdlib flag. DO NOT USE THIS IN YOUR # does NOT need to remove the stdlib flag. DO NOT USE THIS IN YOUR

View File

@ -17,28 +17,9 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>. # along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
import os
# Given an iterable object that produces strings (flags for Clang), removes the # This function doesn't do anything; it used to do something useful, but not
# '-c' and '-o' options that Clang does not like to see when it's producing # anymore. It MUST NOT be removed because of backwards compatibility with old
# completions for a file. # ycm_extra_conf.py files.
def PrepareClangFlags( flags, filename ): def PrepareClangFlags( flags, filename ):
new_flags = [] return flags
skip = True
for flag in flags:
if skip:
skip = False
continue
if flag == '-c':
continue
if flag == '-o':
skip = True;
continue
if flag == filename or os.path.realpath(flag) == filename:
continue
new_flags.append( flag )
return new_flags

View File

@ -56,7 +56,7 @@ class Flags( object ):
if add_special_clang_flags: if add_special_clang_flags:
results[ 'flags' ] += self.special_clang_flags results[ 'flags' ] += self.special_clang_flags
sanitized_flags = _SanitizeFlags( results[ 'flags' ] ) sanitized_flags = _PrepareFlagsForClang( results[ 'flags' ], filename )
if results[ 'do_cache' ]: if results[ 'do_cache' ]:
self.flags_for_file[ filename ] = sanitized_flags self.flags_for_file[ filename ] = sanitized_flags
@ -88,6 +88,11 @@ class Flags( object ):
return [ x for x in include_paths if x ] return [ x for x in include_paths if x ]
def _PrepareFlagsForClang( flags, filename ):
flags = _RemoveUnusedFlags( flags, filename )
flags = _SanitizeFlags( flags )
return flags
def _SanitizeFlags( flags ): def _SanitizeFlags( flags ):
"""Drops unsafe flags. Currently these are only -arch flags; they tend to """Drops unsafe flags. Currently these are only -arch flags; they tend to
@ -113,6 +118,32 @@ def _SanitizeFlags( flags ):
return vector return vector
def _RemoveUnusedFlags( flags, filename ):
"""Given an iterable object that produces strings (flags for Clang), removes
the '-c' and '-o' options that Clang does not like to see when it's producing
completions for a file."""
new_flags = []
skip = True
for flag in flags:
if skip:
skip = False
continue
if flag == '-c':
continue
if flag == '-o':
skip = True;
continue
if flag == filename or os.path.realpath(flag) == filename:
continue
new_flags.append( flag )
return new_flags
def _SpecialClangIncludes(): def _SpecialClangIncludes():
libclang_dir = os.path.dirname( ycm_core.__file__ ) libclang_dir = os.path.dirname( ycm_core.__file__ )
path_to_includes = os.path.join( libclang_dir, 'clang_includes' ) path_to_includes = os.path.join( libclang_dir, 'clang_includes' )

View File

@ -115,6 +115,10 @@ def _Load( module_file, force = False ):
if not _ShouldLoad( module_file ): if not _ShouldLoad( module_file ):
return _Disable( module_file ) return _Disable( module_file )
# This has to be here because a long time ago, the ycm_extra_conf.py files
# used to import clang_helpers.py from the cpp folder. This is not needed
# anymore, but there are a lot of old ycm_extra_conf.py files that we don't
# want to break.
sys.path.insert( 0, _PathToCppCompleterFolder() ) sys.path.insert( 0, _PathToCppCompleterFolder() )
module = imp.load_source( _RandomName(), module_file ) module = imp.load_source( _RandomName(), module_file )
del sys.path[ 0 ] del sys.path[ 0 ]