Debian Codegraph @

scripts/fix_json_database.py

raw
1 #!/usr/bin/env python2
2
3
4 # SPDX-FileCopyrightText: 2017 Sergio Martins <[email protected]>
5 # SPDX-License-Identifier: LGPL-2.0-or-later
6
7 # This script is useful for fixing the json database, in case there's compiler flags
8 # you want to remove or add. One such example is when you're required to build your
9 # project with Apple clang, which will then generate pch errors when running
10 # clazy.
11
12 import json, sys, string
13
14 #-------------------------------------------------------------------------------
15 # Filters. Configure here.
16
17 # Removes arguments starting with -include
18 def filter_no_pch(str):
19 return not (str.startswith("-include") or str.startswith(".pch/"))
20
21 def remove_pch(c_splitted):
22 return filter(filter_no_pch, c_splitted)
23
24 def fix_command(c):
25 c_splitted = c.split()
26 c_splitted = remove_pch(c_splitted)
27 return string.join(c_splitted)
28
29
30 def fix_arguments(args):
31 args = remove_pch(args)
32 return args
33
34 #-------------------------------------------------------------------------------
35 # Main:
36
37 f = open(sys.argv[1], 'r')
38 contents = f.read()
39 f.close()
40
41 decoded = json.loads(contents)
42 new_decoded = []
43 for cmd in decoded:
44 if 'file' in cmd:
45 if cmd['file'].endswith('.moc') or cmd['file'].endswith('.rcc') or cmd['file'].endswith('_moc.cpp'):
46 continue
47
48 if 'command' in cmd or 'arguments' in cmd:
49 if 'command' in cmd:
50 cmd['command'] = fix_command(cmd['command'])
51 if 'arguments' in cmd:
52 cmd['arguments'] = fix_arguments(cmd['arguments'])
53
54 new_decoded.append(cmd)
55
56 new_contents = json.dumps(new_decoded)
57 print new_contents