SlickEdit Product Discussion > SlickEdit®

compile_commands.json

(1/1)

guth:
Hi,

I haven't been using slick for development for quite long now. The main reason is that the sources I'm working on pull in dependencies from the C++ package manager conan meaning that the dependencies are downloaded into a cache. In this cache there can be several different versions of the same package. One debug and one release for instance and/or versions 1.1, 1.1.1, 1.2 etc.. You don't want to let slick tag this cache since it gets too big. There might be several versions of boost and getting several same tag proposals from different boosts do not help anyone.

Now, by a stroke of genius, I came up with the following:
* let cmake generate compile_commands.json via the flag -DCMAKE_EXPORT_COMPILE_COMMANDS. I use this file with a lsp server today.
* parse this file for include paths
* create a directory with one link per such unique include directory
* tag this directory and select the tag file

Voila, now we are down to a more managable number of tags and also the correct versions of the dependencies are used. I'll try to use this for a bit and see how useful it is in practice. Attached is a python script that parses the compile_commands.json file and creates a directory with the links.

Hope it helps someone.


--- Code: ---import json
import sys
import subprocess

if __name__ == "__main__":
    with open(sys.argv[1]) as fp:
        j=json.load(fp)
        paths=set()
        for file in j:
            if "command" in file:
                command=file["command"]
                tokens=command.split(' ')
                for i in range(len(tokens)):
                    token=tokens[i]
                    if token.startswith('-I'):
                        paths.add(tokens[i][2:])
                    elif token == '-isystem' and i+1<len(tokens):
                        paths.add(tokens[i+1])
        subprocess.run(["mkdir", "slick"])
        i=0
        for path in paths:
            subprocess.run(["ln", "-s", f"{path}", f"slick/{i}"])
            i+=1
--- End code ---

Navigation

[0] Message Index

Go to full version