| 1 |
#!/usr/bin/env python3 |
| 2 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 |
|
| 4 |
import json |
| 5 |
import os |
| 6 |
import sys |
| 7 |
|
| 8 |
|
| 9 |
def main() -> int: |
| 10 |
build_root = os.environ['MESON_BUILD_ROOT'] |
| 11 |
|
| 12 |
sep = sys.argv.index('--') |
| 13 |
sources = sys.argv[1:sep] |
| 14 |
command = sys.argv[sep + 1 :] |
| 15 |
|
| 16 |
db_path = os.path.join(build_root, 'compile_commands.json') |
| 17 |
try: |
| 18 |
with open(db_path) as f: |
| 19 |
db = json.load(f) |
| 20 |
except FileNotFoundError: |
| 21 |
db = [] |
| 22 |
|
| 23 |
sources_set = set(sources) |
| 24 |
db = [entry for entry in db if entry['file'] not in sources_set] |
| 25 |
|
| 26 |
for source in sources: |
| 27 |
db.append( |
| 28 |
{ |
| 29 |
'directory': build_root, |
| 30 |
'file': source, |
| 31 |
'arguments': [source if a == '@INPUT@' else a for a in command], |
| 32 |
} |
| 33 |
) |
| 34 |
|
| 35 |
with open(db_path, 'w') as f: |
| 36 |
json.dump(db, f, indent=2) |
| 37 |
|
| 38 |
return 0 |
| 39 |
|
| 40 |
|
| 41 |
if __name__ == '__main__': |
| 42 |
sys.exit(main()) |