Skip to content

Commit

Permalink
Do not erase but update compilation database.
Browse files Browse the repository at this point in the history
When using the -r json-compilation-database option, if a database already
exists, it is completely rewritten. This has the side effect that when using
incremental compilation, the compilation commands for the files that are not
recompiled are lost. This has the effect that tools using the database like
clang-tidy won't find the compilation commands for file that were not
recompiled.

This commit changes the database generation code so that it updates the database
with the detected commands instead of rewriting it.
  • Loading branch information
canatella committed Oct 25, 2017
1 parent 93b6f87 commit 50e1d61
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/xcpretty/reporters/json_compilation_database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ def format_compile_command(compiler_command, file_path)
end

def write_report
if File.exist?(@filepath)
begin
json = JSON.parse(File.read(@filepath))
rescue JSON::ParserError
# drop the current database if it is not valid.
json = []
end
json.each do |c|
found = @compilation_units.detect do |u|
u[:file] == c["file"] && u[:directory] == c["directory"]
end
unless found
@compilation_units << {command: c["command"],
file: c["file"],
directory: c["directory"]}
end
end
end
File.open(@filepath, 'w') do |f|
f.write(@compilation_units.to_json)
end
Expand Down

0 comments on commit 50e1d61

Please sign in to comment.