* tools/dist/backport.pl: Revert accidental change made in r1866188.
[svn/apache.git] / .ycm_extra_conf.py
blob4108bec5e7b9cce31fe2caf61a068e887ceaecec
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
10 # means.
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/>
30 import os
31 import ycm_core
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 )
38 else:
39 database = None
41 def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
42 if not working_directory:
43 return flags
44 new_flags = []
45 make_next_absolute = False
46 path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
47 for flag in flags:
48 new_flag = flag
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:
56 if flag == path_flag:
57 make_next_absolute = True
58 break
60 if flag.startswith( path_flag ):
61 path = flag[ len( path_flag ): ]
62 new_flag = path_flag + os.path.join( working_directory, path )
63 break
65 if new_flag:
66 new_flags.append( new_flag )
67 return new_flags
70 def FlagsForFile( filename ):
71 if database:
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_ ),
79 filename )
80 do_cache = True
81 else:
82 final_flags = [ ]
83 do_cache = False
85 return {
86 'flags': final_flags,
87 'do_cache': do_cache