JDevlieghere/dotfiles

Finding compile db in out of source builds with YCM

Closed this issue · 1 comments

gagbo commented

Hello,

I stumbled upon your article about a better .ycm_extra_conf and I found it really great ! The only thing I missed was the possibility to keep the compile db in the not synced build folder while working with an out-of-source project. I added a few lines to FindNearest to make it look for a "build" folder each time it goes one directory up (the line starting with next_build_folder and the following 5) :

def FindNearest(path, target):
    candidate = os.path.join(path, target)
    if(os.path.isfile(candidate) or os.path.isdir(candidate)):
        logging.info("Found nearest " + target + " at " + candidate)
        return candidate;
    else:
        parent = os.path.dirname(os.path.abspath(path));
        next_build_folder = os.path.join(os.path.dirname(os.path.abspath(parent)),"build")
        if (os.path.isdir(next_build_folder)):
            if re.search("build",path):
                logging.info("NOT doing twice " + path + " folder")
            else:
                return FindNearest(next_build_folder ,target)
        if(parent == path):
            raise RuntimeError("Could not find " + target);
        return FindNearest(parent, target)

Hi Gerry,

I usually just symlink the compilation database to the root of my project, like compile_commands.json -> build/compile_commands.json. Of course that only works with cmake project, requires you to think about the symlink and possibly ignore the file in vcs. Having out of the box support for build directories is obviously way cooler!

Would you mind make putting your change in a separate function so it's clear what it does to someone that does not follow this directory structure? You can open a PR for it or I can update the file for you.

Cheers,
Jonas