@@ -43,24 +43,37 @@ def write_compilation_database(ctx):
4343 "Write the clang compilation database as json"
4444 database_file = ctx .bldnode .make_node ('compile_commands.json' )
4545 file_path = str (database_file .path_from (ctx .path ))
46+
4647 if not os .path .exists (file_path ):
4748 with open (file_path , 'w' ) as f :
4849 f .write ('[]' )
50+
4951 Logs .info ("Store compile comands in %s" % file_path )
5052 clang_db = dict ((x ["file" ], x ) for x in json .load (database_file ))
53+
5154 for task in getattr (ctx , 'clang_compilation_database_tasks' , []):
55+ # we need only to generate last_cmd, so override
56+ # exec_command temporarily
57+ def exec_command (self , * k , ** kw ):
58+ return 0
59+ old_exec = task .exec_command
60+ task .exec_command = exec_command
61+ task .run ()
62+ task .exec_command = old_exec
63+
5264 try :
53- cmd = task .last_cmd
65+ arguments = task .last_cmd
5466 except AttributeError :
5567 continue
68+
5669 filename = task .inputs [0 ].abspath ()
5770 entry = {
5871 "directory" : getattr (task , 'cwd' , ctx .variant_dir ),
59- "command" : " " . join ( cmd ) ,
60- "file" : filename ,
72+ "arguments" : arguments ,
73+ "file" : filename ,
6174 }
6275 clang_db [filename ] = entry
63- database_file .write ( json . dumps (clang_db .values (), indent = 2 ))
76+ database_file .write_json ( list (clang_db .values ()))
6477
6578
6679def options (opt ):
0 commit comments