parameters: (ctx)
docstring: Write the clang compilation database as JSON
docstring_summary: Write the clang compilation database as JSON
docstring_tokens: Write the clang compilation database as JSON
function: def write_compilation_database(ctx):
  	"Write the clang compilation database as JSON"
  	database_file = ctx.bldnode.make_node('compile_commands.json')
  	Logs.info("Build commands will be stored in %s" % database_file.path_from(ctx.path))
  	try:
  		root = json.load(database_file)
  	except IOError:
  		root = []
  	clang_db = dict((x["file"], x) for x in root)
  	for task in getattr(ctx, 'clang_compilation_database_tasks', []):
  		try:
  			cmd = task.last_cmd
  		except AttributeError:
  			continue
  		directory = getattr(task, 'cwd', ctx.variant_dir)
  		f_node = task.inputs[0]
  		filename = os.path.relpath(f_node.abspath(), directory)
  		cmd = " ".join(map(quote, cmd))
  		entry = {
  			"directory": directory,
  			"command": cmd,
  			"file": filename,
  		}
  		clang_db[filename] = entry
  	root = list(clang_db.values())
  	database_file.write(json.dumps(root, indent=2))
function_tokens: def write_compilation_database ( ctx ) : database_file = ctx . bldnode . make_node ( 'compile_commands.json' ) Logs . info ( "Build commands will be stored in %s" % database_file . path_from ( ctx . path ) ) try : root = json . load ( database_file ) except IOError : root = [ ] clang_db = dict ( ( x [ "file" ] , x ) for x in root ) for task in getattr ( ctx , 'clang_compilation_database_tasks' , [ ] ) : try : cmd = task . last_cmd except AttributeError : continue directory = getattr ( task , 'cwd' , ctx . variant_dir ) f_node = task . inputs [ 0 ] filename = os . path . relpath ( f_node . abspath ( ) , directory ) cmd = " " . join ( map ( quote , cmd ) ) entry = { "directory" : directory , "command" : cmd , "file" : filename , } clang_db [ filename ] = entry root = list ( clang_db . values ( ) ) database_file . write ( json . dumps ( root , indent = 2 ) )