File indexing completed on 2024-04-21 05:38:36

0001 #!/usr/bin/env python2
0002 
0003 
0004 # SPDX-FileCopyrightText: 2017 Sergio Martins <smartins@kde.org>
0005 # SPDX-License-Identifier: LGPL-2.0-or-later
0006 
0007 # This script is useful for fixing the json database, in case there's compiler flags
0008 # you want to remove or add. One such example is when you're required to build your
0009 # project with Apple clang, which will then generate pch errors when running
0010 # clazy.
0011 
0012 import json, sys, string
0013 
0014 #-------------------------------------------------------------------------------
0015 # Filters. Configure here.
0016 
0017 # Removes arguments starting with -include
0018 def filter_no_pch(str):
0019     return not (str.startswith("-include") or str.startswith(".pch/"))
0020 
0021 def remove_pch(c_splitted):
0022     return filter(filter_no_pch, c_splitted)
0023 
0024 def fix_command(c):
0025     c_splitted = c.split()
0026     c_splitted = remove_pch(c_splitted)
0027     return string.join(c_splitted)
0028 
0029 
0030 def fix_arguments(args):
0031     args = remove_pch(args)
0032     return args
0033 
0034 #-------------------------------------------------------------------------------
0035 # Main:
0036 
0037 f = open(sys.argv[1], 'r')
0038 contents = f.read()
0039 f.close()
0040 
0041 decoded = json.loads(contents)
0042 new_decoded = []
0043 for cmd in decoded:
0044     if 'file' in cmd:
0045         if cmd['file'].endswith('.moc') or cmd['file'].endswith('.rcc') or cmd['file'].endswith('_moc.cpp'):
0046             continue
0047 
0048     if 'command' in cmd or 'arguments' in cmd:
0049         if 'command' in cmd:
0050             cmd['command'] = fix_command(cmd['command'])
0051         if 'arguments' in cmd:
0052             cmd['arguments'] = fix_arguments(cmd['arguments'])
0053 
0054         new_decoded.append(cmd)
0055 
0056 new_contents = json.dumps(new_decoded)
0057 print new_contents