1 # Configuration file for YouCompleteMe vim plugin to allow the plugin
2 # to determine the compile flags. This file is based on:
3 # https://github.com/Valloric/YouCompleteMe/blob/master/cpp/ycm/.ycm_extra_conf.py
5 # This is free and unencumbered software released into the public domain.
7 # Anyone is free to copy, modify, publish, use, compile, sell, or
8 # distribute this software, either in source code form or as a compiled
9 # binary, for any purpose, commercial or non-commercial, and by any
12 # In jurisdictions that recognize copyright laws, the author or authors
13 # of this software dedicate any and all copyright interest in the
14 # software to the public domain. We make this dedication for the benefit
15 # of the public at large and to the detriment of our heirs and
16 # successors. We intend this dedication to be an overt act of
17 # relinquishment in perpetuity of all present and future rights to this
18 # software under copyright law.
20 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 # IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24 # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25 # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 # OTHER DEALINGS IN THE SOFTWARE.
28 # For more information, please refer to <http://unlicense.org/>
32 from clang_helpers
import PrepareClangFlags
34 compilation_database_folder
= os
.path
.dirname(os
.path
.realpath(__file__
))
36 if compilation_database_folder
:
37 database
= ycm_core
.CompilationDatabase( compilation_database_folder
)
41 def MakeRelativePathsInFlagsAbsolute( flags
, working_directory
):
42 if not working_directory
:
45 make_next_absolute
= False
46 path_flags
= [ '-isystem', '-I', '-iquote', '--sysroot=' ]
50 if make_next_absolute
:
51 make_next_absolute
= False
52 if not flag
.startswith( '/' ):
53 new_flag
= os
.path
.join( working_directory
, flag
)
55 for path_flag
in path_flags
:
57 make_next_absolute
= True
60 if flag
.startswith( path_flag
):
61 path
= flag
[ len( path_flag
): ]
62 new_flag
= path_flag
+ os
.path
.join( working_directory
, path
)
66 new_flags
.append( new_flag
)
70 def FlagsForFile( filename
):
72 # Bear in mind that compilation_info.compiler_flags_ does NOT return a
73 # python list, but a "list-like" StringVec object
74 compilation_info
= database
.GetCompilationInfoForFile( filename
)
75 final_flags
= PrepareClangFlags(
76 MakeRelativePathsInFlagsAbsolute(
77 compilation_info
.compiler_flags_
,
78 compilation_info
.compiler_working_dir_
),