]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/jaeger-client-cpp/.ycm_extra_conf.py
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / jaegertracing / jaeger-client-cpp / .ycm_extra_conf.py
CommitLineData
f67539c2
TL
1# Copyright (c) 2017-2018 Uber Technologies, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import os
16import ycm_core
17
18
19def DirectoryOfThisScript():
20 return os.path.dirname( os.path.abspath( __file__ ) )
21
22
23project_dir = DirectoryOfThisScript()
24
25try:
26 with open('build/_3rdParty/Hunter/install-root-dir') as f:
27 hunter_install_dir = f.readline()
28except IOError:
29 # Ignore if file does not exist
30 hunter_install_dir = ''
31
32flags = [
33'-Wall',
34'-Werror',
35'-pedantic',
36'-std=c++11',
37'-x',
38'c++',
39'-DBOOST_COROUTINES_NO_DEPRECATION_WARNING=1',
40'-DGTEST_HAS_TR1_TUPLE=0',
41'-DGTEST_USE_OWN_TR1_TUPLE=0',
42'-isystem',
43'/usr/local/include',
44'-I',
45os.path.join(project_dir, 'src'),
46'-I',
47os.path.join(project_dir, 'build/src')
48]
49
50if hunter_install_dir:
51 flags += ['-I', hunter_install_dir]
52
53compilation_database_folder = os.path.join(project_dir, 'build')
54
55if os.path.exists( compilation_database_folder ):
56 database = ycm_core.CompilationDatabase( compilation_database_folder )
57else:
58 database = None
59
60SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]
61
62
63def IsHeaderFile( filename ):
64 extension = os.path.splitext( filename )[ 1 ]
65 return extension in [ '.h', '.hxx', '.hpp', '.hh' ]
66
67
68def GetCompilationInfoForFile( filename ):
69 # The compilation_commands.json file generated by CMake does not have entries
70 # for header files. So we do our best by asking the db for flags for a
71 # corresponding source file, if any. If one exists, the flags for that file
72 # should be good enough.
73 if IsHeaderFile( filename ):
74 basename = os.path.splitext( filename )[ 0 ]
75 for extension in SOURCE_EXTENSIONS:
76 replacement_file = basename + extension
77 if os.path.exists( replacement_file ):
78 compilation_info = database.GetCompilationInfoForFile(
79 replacement_file )
80 if compilation_info.compiler_flags_:
81 return compilation_info
82 return None
83 return database.GetCompilationInfoForFile( filename )
84
85
86def FlagsForFile( filename, **kwargs ):
87 if not database:
88 return {
89 'flags': flags,
90 'include_paths_relative_to_dir': DirectoryOfThisScript()
91 }
92
93 compilation_info = GetCompilationInfoForFile( filename )
94 if not compilation_info:
95 return None
96
97 # Bear in mind that compilation_info.compiler_flags_ does NOT return a
98 # python list, but a "list-like" StringVec object.
99 final_flags = list( compilation_info.compiler_flags_ )
100
101 return {
102 'flags': final_flags,
103 'include_paths_relative_to_dir': compilation_info.compiler_working_dir_
104 }