mirror of
https://github.com/rizsotto/scan-build.git
synced 2025-12-16 12:00:08 +01:00
49 lines
1.4 KiB
Python
Executable File
49 lines
1.4 KiB
Python
Executable File
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
# The LLVM Compiler Infrastructure
|
|
#
|
|
# This file is distributed under the University of Illinois Open Source
|
|
# License. See LICENSE.TXT for details.
|
|
|
|
import argparse
|
|
import json
|
|
import shlex
|
|
import os.path
|
|
|
|
|
|
def diff(lhs, rhs):
|
|
left = {smooth(entry): entry for entry in lhs}
|
|
right = {smooth(entry): entry for entry in rhs}
|
|
for key in left.keys():
|
|
if key not in right:
|
|
yield '> {}'.format(left[key])
|
|
for key in right.keys():
|
|
if key not in left:
|
|
yield '< {}'.format(right[key])
|
|
|
|
|
|
def smooth(entry):
|
|
directory = os.path.normpath(entry['directory'])
|
|
source = entry['file'] if os.path.isabs(entry['file']) else \
|
|
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)
|
|
|
|
|
|
def main():
|
|
""" Semantically diff two compilation databases. """
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('left', type=argparse.FileType('r'))
|
|
parser.add_argument('right', type=argparse.FileType('r'))
|
|
args = parser.parse_args()
|
|
# files are open, parse the json content
|
|
lhs = json.load(args.left)
|
|
rhs = json.load(args.right)
|
|
# run the diff and print the result
|
|
count = 0
|
|
for result in diff(lhs, rhs):
|
|
print(result)
|
|
count += 1
|
|
return count
|