[tools] Add --cdb to make compile_commands.json.

This commit is contained in:
bernard 2024-05-03 16:04:55 +08:00 committed by Meco Man
parent b632dc1aaf
commit c4e7a0e5e3
4 changed files with 25 additions and 2 deletions

View File

@ -850,6 +850,11 @@ def DoBuilding(target, objects):
objects = sorted(objects)
objects.append(objects_in_group)
# generate build/compile_commands.json
if GetOption('cdb') and utils.VerTuple(SCons.__version__) >= (4, 0, 0):
Env.Tool("compilation_db")
Env.CompilationDatabase('build/compile_commands.json')
program = Env.Program(target, objects)
EndBuilding(target, program)

View File

@ -136,3 +136,8 @@ def AddOptions():
action = 'store_true',
default = False,
help = 'make menuconfig for RT-Thread BSP')
AddOption('--cdb',
dest = 'cdb',
action = 'store_true',
default = False,
help = 'make compile_commands.json')

View File

@ -303,3 +303,9 @@ def ImportModule(module):
return module
else:
return __import__(module, fromlist=[module])
def VerTuple(version_str):
ver_parts = version_str.split('.')
ver = tuple(int(part) for part in ver_parts)
return ver

View File

@ -52,12 +52,19 @@ def GenerateCFiles(env):
cc = os.path.abspath(cc).replace('\\', '/')
config_obj = {}
config_obj['name'] = 'Win32'
config_obj['name'] = 'rt-thread'
config_obj['defines'] = info['CPPDEFINES']
config_obj['intelliSenseMode'] = 'clang-x64'
intelliSenseMode = 'gcc-arm'
if cc.find('aarch64') != -1:
intelliSenseMode = 'gcc-arm64'
elif cc.find('arm') != -1:
intelliSenseMode = 'gcc-arm'
config_obj['intelliSenseMode'] = intelliSenseMode
config_obj['compilerPath'] = cc
config_obj['cStandard'] = "c99"
config_obj['cppStandard'] = "c++11"
config_obj['compileCommands'] ="build/compile_commands.json"
# format "a/b," to a/b. remove first quotation mark("),and remove end (",)
includePath = []