Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Isaac Hier
committed
Mar 12, 2018
1 parent
d0444e5
commit 25596c0
Showing
6 changed files
with
356 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
BasedOnStyle: Google | |||
IndentWidth: 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,30 @@ | |||
--- | |||
Checks: 'clang-diagnostic-*,clang-analyzer-*' | |||
WarningsAsErrors: '' | |||
HeaderFilterRegex: '' | |||
AnalyzeTemporaryDtors: false | |||
FormatStyle: none | |||
User: isaachier | |||
CheckOptions: | |||
- key: google-readability-braces-around-statements.ShortStatementLines | |||
value: '1' | |||
- key: google-readability-function-size.StatementThreshold | |||
value: '800' | |||
- key: google-readability-namespace-comments.ShortNamespaceLines | |||
value: '10' | |||
- key: google-readability-namespace-comments.SpacesBeforeComments | |||
value: '2' | |||
- key: modernize-loop-convert.MaxCopySize | |||
value: '16' | |||
- key: modernize-loop-convert.MinConfidence | |||
value: reasonable | |||
- key: modernize-loop-convert.NamingStyle | |||
value: CamelCase | |||
- key: modernize-pass-by-value.IncludeStyle | |||
value: llvm | |||
- key: modernize-replace-auto-ptr.IncludeStyle | |||
value: llvm | |||
- key: modernize-use-nullptr.NullMacros | |||
value: 'NULL' | |||
... | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,98 @@ | |||
# Copyright (c) 2018, Uber Technologies, Inc | |||
# | |||
# Permission is hereby granted, free of charge, to any person obtaining a copy | |||
# of this software and associated documentation files (the "Software"), to deal | |||
# in the Software without restriction, including without limitation the rights | |||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
# copies of the Software, and to permit persons to whom the Software is | |||
# furnished to do so, subject to the following conditions: | |||
# | |||
# The above copyright notice and this permission notice shall be included in | |||
# all copies or substantial portions of the Software. | |||
# | |||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |||
# THE SOFTWARE. | |||
|
|||
import os | |||
import ycm_core | |||
|
|||
|
|||
def DirectoryOfThisScript(): | |||
return os.path.dirname( os.path.abspath( __file__ ) ) | |||
|
|||
|
|||
project_dir = DirectoryOfThisScript() | |||
|
|||
flags = [ | |||
'-Wall', | |||
'-Werror', | |||
'-pedantic', | |||
'-std=c11', | |||
'-pthread', | |||
'-x', | |||
'c', | |||
'-isystem', | |||
'/usr/local/include', | |||
'-I', | |||
os.path.join(project_dir, 'src/h3lib/include'), | |||
'-I', | |||
os.path.join(project_dir, 'src/apps/applib/include') | |||
] | |||
|
|||
compilation_database_folder = os.path.join(project_dir, 'build') | |||
|
|||
if os.path.exists( compilation_database_folder ): | |||
database = ycm_core.CompilationDatabase( compilation_database_folder ) | |||
else: | |||
database = None | |||
|
|||
SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ] | |||
|
|||
|
|||
def IsHeaderFile( filename ): | |||
extension = os.path.splitext( filename )[ 1 ] | |||
return extension in [ '.h', '.hxx', '.hpp', '.hh' ] | |||
|
|||
|
|||
def GetCompilationInfoForFile( filename ): | |||
# The compilation_commands.json file generated by CMake does not have entries | |||
# for header files. So we do our best by asking the db for flags for a | |||
# corresponding source file, if any. If one exists, the flags for that file | |||
# should be good enough. | |||
if IsHeaderFile( filename ): | |||
basename = os.path.splitext( filename )[ 0 ] | |||
for extension in SOURCE_EXTENSIONS: | |||
replacement_file = basename + extension | |||
if os.path.exists( replacement_file ): | |||
compilation_info = database.GetCompilationInfoForFile( | |||
replacement_file ) | |||
if compilation_info.compiler_flags_: | |||
return compilation_info | |||
return None | |||
return database.GetCompilationInfoForFile( filename ) | |||
|
|||
|
|||
def FlagsForFile( filename, **kwargs ): | |||
if not database: | |||
return { | |||
'flags': flags, | |||
'include_paths_relative_to_dir': DirectoryOfThisScript() | |||
} | |||
|
|||
compilation_info = GetCompilationInfoForFile( filename ) | |||
if not compilation_info: | |||
return None | |||
|
|||
# Bear in mind that compilation_info.compiler_flags_ does NOT return a | |||
# python list, but a "list-like" StringVec object. | |||
final_flags = list( compilation_info.compiler_flags_ ) | |||
|
|||
return { | |||
'flags': final_flags, | |||
'include_paths_relative_to_dir': compilation_info.compiler_working_dir_ | |||
} |
Oops, something went wrong.