Files
scylladb/scripts/merge-compdb.py
Michael Livshin 43f2c55c5d configure.py: speed up and simplify compdb generation
The most time-consuming part is invoking "ninja -t compdb", and there
is no need to repeat that for every mode.

Signed-off-by: Michael Livshin <michael.livshin@scylladb.com>

Closes #10733
2022-06-15 16:40:52 +03:00

54 lines
1.5 KiB
Python
Executable File

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2021 ScyllaDB
#
#
# SPDX-License-Identifier: AGPL-3.0-or-later
#
#
# Called by configure.py to merge several compdbs into one, so your
# favourite compatible code indexer can present you with a relevant
# maximally-complete unified index.
#
# Usage: merge-compdb.py build/{debug,release,dev,sanitize} [input...]
#
# Glue inputs, which must be compdb ("compile_command.json") files,
# together, filtering out anything that is not indexable or not built
# under the given prefix, and write the result to stdout.
#
# An input is either a file name or "-" for stdin.
#
# configure.py calls this with "-" for the ninja-generated scylla
# compdb and mode-specific seastar & abseil compdbs.
#
import json
import re
import sys
prefix = sys.argv[1]
inputs = sys.argv[2:]
def read_input(fname):
with open(fname) as f:
return json.load(f)
def is_indexable(e):
return any(e['file'].endswith('.' + suffix) for suffix in ['c', 'C', 'cc', 'cxx'])
# We can only definitely say whether an entry is built under the right
# prefix when it has an "output" field, so those without are assumed
# to be OK. This works for our usage, where only "ninja -t compdb"
# creates entries with an 'output' field _and_ needs to be filtered in
# the first place.
def is_relevant(e):
return ('output' not in e) or (e['output'].startswith(prefix))
json.dump([e for fname in inputs
for e in read_input(fname) if is_indexable(e) and is_relevant(e)],
sys.stdout, indent=True)