|
NAMEBear - a tool to generate compilation database for Clang tooling. SYNOPSISbear [OPTIONS] [–] [BUILD_COMMAND...] bear intercept [OPTIONS] [–] BUILD_COMMAND... bear semantic [OPTIONS] DESCRIPTIONBear is a tool that generates a JSON compilation database for Clang tooling by intercepting command executions during the build process. The JSON compilation database is used in the Clang project to provide information about how individual compilation units were processed, enabling tools like clang-tidy, clangd, and other Clang-based analysis tools to understand your project’s build configuration. Bear operates by intercepting system calls during the build process to capture compilation commands. It supports two main interception methods: dynamic library preloading (on Unix-like systems) and wrapper executables (cross-platform). The captured commands are then filtered through semantic analysis to identify actual compiler invocations and generate the final compilation database. Bear can operate in three modes:
OPTIONS
COMMANDSCalling bear without commands will execute the combined mode, and will intercept the compiler calls and generate a compilation database as output. bear interceptIntercepts command execution events during the build process and saves them to an events file for later processing. bear intercept [OPTIONS] [–] BUILD_COMMAND... bear semanticProcesses previously captured events to generate a compilation database through semantic analysis. bear semantic [OPTIONS] OUTPUTBear generates a JSON compilation database conforming to the Clang JSON Compilation Database specification. The output is a JSON array of compilation entry objects. Entry FormatEach compilation database entry contains the following fields:
Output FormattingThe output format can be controlled through the configuration file:
Bear generates entries where all paths are absolute by default, and uses the arguments field instead of command to avoid shell escaping issues. CONFIG FILEBear uses a YAML configuration file to control its behavior. The configuration file follows a structured schema with several main sections. Configuration Schema
This example configuration file: sets the interception mode to wrapper, hints the /usr/bin/cc to be the main compiler in this project, which is the GNU compiler, hints to ignore the /usr/local/bin/gcc compilers from the project, instructs to ignore files from /project/tests, instructs to detect duplicates based on the file and arguments fields of the output file, instructs to format the output to use canonical path for the file and directory fields of the output file, instructs to use the arguments over the command field in the output file, instructs to include the output field in the output file. Configuration SectionsThe configuration file uses schema version 4.0 and has the following structure: interceptControls the command interception method:
compilersContains hints about what compiler needs to be recognized and what that compiler is.
sourcesFiltering functionality based on the source file location.
Directory rules are evaluated in order, with the last matching rule determining inclusion/exclusion. Empty directories list means include everything. duplicatesFiltering functionality based on duplicate detection. Here you can define which fields of the output file should be used in the duplicate detection.
formatOutput formatting configuration:
Default ConfigurationIf no configuration file is specified, Bear uses built-in defaults optimized for most use cases. ENVIRONMENT
Supported log levels (in order of verbosity):
Examples:
EXIT STATUSBear returns the exit status of the executed build command when running in combined or intercept mode. When the build command succeeds, Bear returns 0. When the build command fails, Bear returns the same non-zero exit code. In semantic mode, Bear returns 0 on success and a non-zero exit code if semantic analysis fails. If Bear itself encounters an internal error or crashes, it returns a non-zero exit code regardless of the build command’s status. TROUBLESHOOTINGThe potential problems you can face with are: the build with and without Bear behaves differently or the output is empty. Debug LoggingBefore reporting any issues, always run Bear with debug logging enabled:
This will provide detailed information about Bear’s internal operations. And the debug output is essential for diagnosing problems and must be included in any bug reports. Common IssuesThe most common cause for empty outputs is that the build command did not execute any commands. The reason for that could be, because incremental builds not running the compilers if everything is up-to-date. Remember, Bear does not understand the build file (eg.: makefile), but intercepts the executed commands. The other common cause for empty output is that the build has a “configure” step, which captures the compiler to build the project. In case of Bear is using the wrapper mode, it needs to run the configure step with Bear too (and discard that output), before run the build with Bear. Getting HelpThere could be many reasons for any of these failures. When seeking help:
COPYRIGHTCopyright (C) 2012-2026 by László Nagy https://github.com/rizsotto/Bear AUTHORSLászló Nagy.
|