Skip to content

Commit

Permalink
gh-254: emit output field in the output
Browse files Browse the repository at this point in the history
  • Loading branch information
rizsotto committed Aug 17, 2019
1 parent e97ad03 commit 69cd736
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 19 deletions.
23 changes: 16 additions & 7 deletions bear/main.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -530,13 +530,22 @@ class Compilation:
""" This method creates a compilation database entry. """

source = os.path.relpath(self.source, self.directory)
output = ['-o', self.output] if self.output else []
return {
'file': source,
'arguments':
[self.compiler, self.phase] + self.flags + output + [source],
'directory': self.directory
}
if self.output:
return {
'file': source,
'arguments':
[self.compiler, self.phase] + self.flags +
['-o', self.output] + [source],
'directory': self.directory,
'output': self.output
}
else:
return {
'file': source,
'arguments':
[self.compiler, self.phase] + self.flags + [source],
'directory': self.directory
}

@classmethod
def from_db_entry(cls, entry, category):
Expand Down
6 changes: 4 additions & 2 deletions test/functional/cases/result/assembly_sources.fts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ cat > "${root_dir}/expected.json" << EOF
"main.s"
],
"directory": "${root_dir}/src",
"file": "main.s"
"file": "main.s",
"output": "main.o"
},
{
"arguments": [
Expand All @@ -56,7 +57,8 @@ cat > "${root_dir}/expected.json" << EOF
"main.c"
],
"directory": "${root_dir}/src",
"file": "main.c"
"file": "main.c",
"output": "main.s"
}
]
EOF
3 changes: 2 additions & 1 deletion test/functional/cases/result/define_with_quote.fts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ cat > "${root_dir}/expected.json" << EOF
{
"arguments": ["c++", "-c", "-DEXPORT=extern \"C\"", "-o", "hello", "src/main.cpp"],
"directory": "${root_dir}",
"file": "src/main.cpp"
"file": "src/main.cpp",
"output": "hello"
}
]
EOF
6 changes: 4 additions & 2 deletions test/functional/cases/result/define_with_unicode.fts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ cat > "${root_dir}/expected.json" << EOF
{
"arguments": ["cc", "-c", "-DMESSAGE=\u041a\u0430\u043a \u0434\u0435\u043b\u0430?", "-o", "hello", "src/main.c"],
"directory": "${root_dir}",
"file": "src/main.c"
"file": "src/main.c",
"output": "hello"
},
{
"arguments": ["cc", "-c", "-DMESSAGE=\u05de\u05d4 \u05e9\u05dc\u05d5\u05de\u05da?", "-o", "hello", "src/main.c"],
"directory": "${root_dir}",
"file": "src/main.c"
"file": "src/main.c",
"output": "hello"
}
]
EOF
12 changes: 8 additions & 4 deletions test/functional/cases/result/flags_filtered.fts
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,26 @@ cat > "${root_dir}/expected.json" << EOF
{
"command": "cc -c -fpic -o one.o lib.c",
"directory": "${root_dir}/src",
"file": "lib.c"
"file": "lib.c",
"output": "one.o"
},
{
"command": "cc -c -fpic -o two.o lib.c",
"directory": "${root_dir}/src",
"file": "lib.c"
"file": "lib.c",
"output": "two.o"
},
{
"command": "cc -c -o fooflag_one main.c",
"directory": "${root_dir}/src",
"file": "main.c"
"file": "main.c",
"output": "fooflag_one"
},
{
"command": "cc -c -o fooflag_two main.c",
"directory": "${root_dir}/src",
"file": "main.c"
"file": "main.c",
"output": "fooflag_two"
}
]
EOF
6 changes: 4 additions & 2 deletions test/functional/cases/result/output_kept.fts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ cat > "${root_dir}/expected.json" << EOF
{
"command": "cc -c -o src/empty.o src/empty.c",
"directory": "${root_dir}",
"file": "src/empty.c"
"file": "src/empty.c",
"output": "src/empty.o"
}
,
{
Expand All @@ -53,7 +54,8 @@ cat > "${root_dir}/expected.json" << EOF
{
"command": "cc -c -o empty.obj empty.c",
"directory": "${root_dir}/src",
"file": "empty.c"
"file": "empty.c",
"output": "empty.obj"
}
,
{
Expand Down
3 changes: 2 additions & 1 deletion test/functional/tools/cdb_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def smooth(entry):
os.path.normpath(os.path.join(directory, entry['file']))
arguments = entry['command'].split() if 'command' in entry else \
entry['arguments']
return '-'.join([source[::-1]] + arguments)
output = entry['output'] if 'output' in entry else ''
return '-'.join([source[::-1]] + arguments + [output])


def main():
Expand Down

0 comments on commit 69cd736

Please sign in to comment.