Code Monkey home page Code Monkey logo

bear's Introduction

Build EAR

Bear is a tool that generates a compilation database for clang tooling.

The JSON compilation database is used in the clang project to provide information on how a single compilation unit is processed. With this, it is easy to re-run the compilation with alternate programs.

One way to get a compilation database is to use cmake as the build tool. Passing -DCMAKE_EXPORT_COMPILE_COMMANDS=ON to cmake generates the compile_commands.json file into the current directory.

For non-cmake projects, use Bear. Bear generates the json file during the build process.

The concept behind Bear is to execute the original build command and intercept the exec calls issued by the build tool. To achieve that, Bear uses the LD_PRELOAD or DYLD_INSERT_LIBRARIES mechanisms provided by the dynamic linker.

Bear has two components: the library and the binary. The library redefines the exec methods to be used by all child processes. The executable enables the use of the library for child processes and writes the output file.

How to build

Bear should be quite portable on UNIX operating systems. It has been tested on FreeBSD, GNU/Linux and OS X.

Prerequisites

  1. an ANSI C compiler, to compile the sources.
  2. cmake, to configure the build process.
  3. make, to run the build. The makefiles are generated by cmake.
  4. python is a runtime dependency. The bear command is written in Python. (version >= 2.7)

Build commands

Ideally, you should build Bear in a separate build directory.

cmake $BEAR_SOURCE_DIR
make all
make install # to install
make check   # to run tests
make package # to make packages

You can configure the build process with passing arguments to cmake.

How to use

After installation the usage is like this:

bear make

The output file called compile_commands.json found in current directory.

For more options you can check the man page or pass --help parameter.

Known issues

Environment overriding caused problems

Because Bear uses LD_PRELOAD or DYLD_INSERT_LIBRARIES environment variables, it does not append to it, but overrides it. So builds which are using these variables might not work. (I don't know any build tool which does that, but please let me know if you do.)

Empty compilation database on OS X Captain or Fedora

Security extension/modes on different operating systems might disable library preloads. This case Bear behaves normaly, but the result compilation database will be empty. (Please make sure it's not the case when reporting bugs.) Notable examples for enabled security modes are: OS X 10.11 (check with csrutil status | grep 'System Integrity Protection'), and Fedora, CentOS, RHEL (check with sestatus | grep 'SELinux status').

Workaround could be to disable the security feature while running Bear. (This might involve reboot of your computer, so might be heavy workaround.) The other option could be to use tools which are using compiler wrappers. (It inject a fake compiler which does record the compiler invocation and calls the real compiler too.) An example for such tool might be scan-build. The build system shall respect CC and CXX environment variables.

Problem reports

If you find a bug in this documentation or elsewhere in the program or would like to propose an improvement, please use the project's github issue tracker. Please describing the bug and where you found it. If you have a suggestion how to fix it, include that as well. Patches are also welcome.

bear's People

Contributors

bbannier avatar breser avatar drvink avatar fbauzac avatar kljohann avatar mlq avatar rizsotto avatar sarcasm avatar sebastinas avatar smmckay avatar speclad avatar svenpanne avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.