MythTV master
build_compdb.py
Go to the documentation of this file.
1#! /usr/bin/python3
2
3from pathlib import Path
4import json
5from optparse import OptionParser
6
7parser = OptionParser()
8parser.add_option("-v", "--verbose",
9 action="store_true", dest="verbose",
10 help="Print progress messages")
11(options, args) = parser.parse_args()
12
13paths = list(Path("..").glob("**/*.o.json"))
14if len(paths) < 600:
15 print("Not enough *.o.json files present. Did you remember to")
16 print("clean ccache and do a full build with clang?")
17 exit(1)
18
19outlines = []
20for path in paths:
21 filename = path.as_posix()
22 badnames = ["/external/", "moc_", "dummy.o.json"]
23 if any(bad in filename for bad in badnames):
24 if options.verbose:
25 print("Skipping input file: {0:s}".format(path.as_posix()))
26 continue
27 in_file = open(path, "r")
28 if not in_file:
29 if options.verbose:
30 print("Cannot open input file: {0:s}".format(filename))
31 continue
32
33 # Read and strip trailing comma
34 rawcontent = in_file.read()
35 if len(rawcontent) < 2:
36 print("Bad file contents: {0:s}".format(filename))
37 exit(1)
38 content = json.loads(rawcontent[:-2])
39 in_file.close()
40
41 # Manipulate file names
42 if content["file"].startswith("../") and not content["file"].endswith("Json.cpp"):
43 if options.verbose:
44 print("Skipping input file2: {0:s}".format(filename))
45 continue
46 content["file"] = content["directory"] + "/" + content["file"]
47
48 # Save the output for this file
49 if options.verbose:
50 print("Including input file: {0:s}".format(path.as_posix()))
51 outlines.append(json.dumps(content, indent=4))
52
53# Dump out the compdb file
54out_file = open("../compile_commands.json", "w")
55print("[\n{0:s}\n]".format(",\n".join(outlines)), file=out_file)
56out_file.close()
static void print(const QList< uint > &raw_minimas, const QList< uint > &raw_maximas, const QList< float > &minimas, const QList< float > &maximas)