Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a compile database for YouCompleteMe #14

Closed
ff2000 opened this issue Dec 20, 2014 · 6 comments
Closed

Create a compile database for YouCompleteMe #14

ff2000 opened this issue Dec 20, 2014 · 6 comments

Comments

@ff2000
Copy link
Contributor

ff2000 commented Dec 20, 2014

This is more of a little tip for hacking rather than an issue. But I could not find a "hacking" section or file, so I post it here - feel free to put it (modified) somewhere else everyone can find it:

First off the easiest solution is to use a compile_commands.json file. cmake could generate it itself, but astroid uses scons ;) So we need a handy little helper - called Bear.

cd ~/src
git clone https://github.com/rizsotto/Bear.git
cd Bear
mkdir build
cd build && cmake ..
make

You then can find a bear executable and a libear.so inside build/src. Furthermore there is an example config located at ~/src/Bear/src/bear.conf. You can copy them wherever you want, I simply left them where they are.

Now go over to your astroid src dir:

cd ~/src/astroid
scons --clean
~/src/Bear/build/src/bear -l ~/src/Bear/build/src/libear.so -c ~/src/Bear/src/bear.conf -- scons --verbose

and you have your compile_commands.json!

I put that long command into a small shell script - you might guess it, Bear is usable with ANY build script/system/... that actually can print the commands it runs.

$ cat ~/bin/run_bear 
#!/bin/sh

~/src/Bear/build/src/bear -l ~/src/Bear/build/src/libear.so -c ~/src/Bear/src/bear.conf "$@"

Now you need a .ycm_extra_conf.py inside /src/astroid. I tried the one shipped with neovim/contrib/YouCompleteMe, but that never worked.
The one that Valloric uses himself in YouCompleteMe works perfectly fine. It's located at YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py
On line 105 set
compilation_database_folder = '
/src/astroid'
and you are done! Completions everywhere :)

@gauteh
Copy link
Member

gauteh commented Dec 21, 2014

Nice! I need to test this out. I guess this could go in the wiki? We need a HACKING file with links to this as well!

@gauteh
Copy link
Member

gauteh commented Dec 21, 2014

I used the .ycm_extra_conf.py file as you described from https://github.com/Valloric/ycmd/blob/master/cpp/ycm/.ycm_extra_conf.py, but I moved the DirectoryOfThisScript() function up a bit and used it as the compilation_database_folder:

def DirectoryOfThisScript():
  return os.path.dirname( os.path.abspath( __file__ ) )

# Set this to the absolute path to the folder (NOT the file!) containing the
# compile_commands.json file to use that instead of 'flags'. See here for
# more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
#
# You can get CMake to generate this file for you by adding:
#   set( CMAKE_EXPORT_COMPILE_COMMANDS 1 )
# to your CMakeLists.txt file.
#
# Most projects will NOT need to set this to anything; you can just change the
# 'flags' list of compilation flags. Notice that YCM itself uses that approach.
compilation_database_folder = DirectoryOfThisScript ()

I guess standard practice is to check this file into the repository?

also, Arch Linux, has bear available as an AUR package so all I had to do there (using yaourt) was:

yaourt -S bear
yaourt -S vim-youcompleteme-git
cd path/to/astorid
scons -c
bear -- scons --verbose

thanks for figuring this out!

@ff2000
Copy link
Contributor Author

ff2000 commented Dec 21, 2014

Yeah, having it packaged by the distro is the easiest way ;)
You can also use "make install" after passing an install prefix with

cmake -DCMAKE_INSTALL_PREFIX="/path/to/install/prefix

(or stick to the default - /usr/local)
and prepend "/path/to/install/prefix/bin" to your PATH.
(but I personally like to keep my env clean - already had trouble with crashing apps due to a leftover of an old "make install" - and bear can be run without "make install")

@gauteh
Copy link
Member

gauteh commented Dec 22, 2014

I set up Hacking and Contributing pages (https://github.com/gauteh/astroid/wiki/Hacking), this kind of information should go in there once it gets cleaned up a bit.

@gauteh
Copy link
Member

gauteh commented Dec 22, 2014

I've added the complete scripts to the repository, after we've added this information to the wiki we can close the issue.

@gauteh
Copy link
Member

gauteh commented Dec 28, 2014

Included more complete instructions in the wiki, so closing here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants