Skip to content
This repository was archived by the owner on Aug 30, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion config_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ def main():
else:
lang, flags = ("c++", cxx_flags)

generate_conf(["-x", lang] + flags, config_file)
if force_lang:
lang += ["-x", force_lang]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lang should be a scalar value, not a list of flags


generate_conf(flags, config_file)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change will break color-coded config generation (generate_cc_conf()), because it outputs a plain text file without the logic in template.py.

IMO, a better way to handle this would be to add separate parameters to the generate_*_conf functions for force_lang and detected_lang, so they can do the right thing for their outputs.

print("Created {} config file with {} {} flags".format(output_format.upper(), len(flags), lang.upper()))


Expand Down
26 changes: 26 additions & 0 deletions template.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,29 @@ def IsHeaderFile( filename ):
extension = os.path.splitext( filename )[ 1 ]
return extension in [ '.H', '.h', '.hxx', '.hpp', '.hh' ]

def filter_out_cxx_std( flags ):
return [f for f in flags if not (f[:5] == '-std=' and f[5:].find('++') != -1)]

def filter_out_c_std( flags ):
return [f for f in flags if not (f[:5] == '-std=' and f[5:].find('++') == -1)]

def LangFlags( filename, flags ):
extension = os.path.splitext( filename )[ 1 ]
langmap = {
'c++': [ '.hh', '.hpp', '.cc', '.cpp', '.cxx' ],
'c': [ '.h', '.c' ]
}
for lang, extlist in langmap.iteritems():
if extension in extlist:
if lang == 'c++':
fflags = filter_out_c_std(flags)
elif lang == 'c':
fflags = filter_out_cxx_std(flags)
else:
fflags = flags
return [ '-x', lang ] + fflags
return flags


def GetCompilationInfoForFile( filename ):
# The compilation_commands.json file generated by CMake does not have entries
Expand Down Expand Up @@ -127,6 +150,9 @@ def FlagsForFile( filename, **kwargs ):
relative_to = DirectoryOfThisScript()
final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )

if '-x' not in final_flags:
final_flags = LangFlags( filename, final_flags )

return {
'flags': final_flags,
'do_cache': True
Expand Down