Skip to content

Commit

Permalink
Add documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
grafikrobot committed Jun 1, 2024
1 parent f84e34b commit c10679b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
3 changes: 3 additions & 0 deletions doc/src/history.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

== Version 5.2.0

* *New*: Add support for generating `compile_commands.json` command database
for some IDE integration.
-- _René Ferdinand Rivera Morell_
* *New*: Addition of a module (`db`) for structured data management. Has a
`property-db` class that can write out as JSON data.
-- _René Ferdinand Rivera Morell_
Expand Down
8 changes: 6 additions & 2 deletions doc/src/overview.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,7 @@ B2 recognizes the following command line options.
`-d0`::
Suppress all informational messages.
`-d N`::
Enable cumulative debugging levels from 1 to n. Values are:
+
Enable cumulative debugging levels from 1 to n. Values are: +
1. Show the actions taken for building targets, as they are executed
(the default).
2. Show "quiet" actions and display all action text, as they are
Expand All @@ -653,6 +652,11 @@ B2 recognizes the following command line options.
`-s var=value`::
Set the variable `var` to `value` in the global scope of the jam language
interpreter, overriding variables imported from the environment.
`--command-database=_format_`::
Output a compile commands database as _format_. Currently _format_ can be:
`json`. (See xref:tasks#b2.tasks.commanddb[Command Database] for details.)
`--command-database-out=_file_`::
Specify the _file_ path to output the commands database to.

[[bbv2.overview.invocation.properties]]
=== Properties
Expand Down
47 changes: 47 additions & 0 deletions doc/src/tasks.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -821,3 +821,50 @@ When loading a `*.jam` file as the _path_ it is equivalent to calling:
In this case it means that the file will be loaded as part of the referenced
project and hence any bare targets or information it declares will be part of
the project.

[[b2.tasks.commanddb]]
== Command Database, and IDE Integration

Many IDE programs accept the use of a
https://clang.llvm.org/docs/JSONCompilationDatabase.html[`compile_commands.json`]
file to learn what and how your project builds. B2 supports generating such
files for any build you make. B2 supports this through a generic facility to
extract commands from the actions it executes. There are two options that
control this. The `--command-database=_format_` option indicates to generate the
file for the given _format_. It has a couple of effects when specified:

* It tells B2 to start observing and extracting commands from actions (as
specified by the toolset).
* It disables execution of actions. I.e. equivalent to adding the `-n` option.
* It enables building all default and specified targets. I.e. the equivalent to
adding the `-a` option.
* It disables all action execution output. I.e. as if specifying `-d0` option.
* At the end of the main build it writes out the results of what it observed
to the database file.

Currently on `json` is supported as a format that follows the
https://clang.llvm.org/docs/JSONCompilationDatabase.html[Clang JSON Compilation
Database Format Specification].

The `--command-database-out=_file_` option controls the name, and optionally
location, of the generated file. By default the _file_ is
`compile_commands.json` to follow the ecosystem convention. And it is generated,
by default, in one of the following locations:

* Relative to the `build-dir` of the root project, if it's specified by the
project. With the default _file_ name or as given.
* At the absolute _file_ path if it is rooted.
* At the _current working directory_.

The following fields are populated in the generated database:

* `directory` - This will always be the current directory as B2 makes all paths
relative to that (or absolute).
* `file` - The first source of each action recorded.
* `command` - The quoted, full, command as extracted by the toolset.
* `output` - The first target file of each action recorded. As B2 can build
multiple variants at once this is required to differentiate between multiple
compilations of the same source file.

NOTE: Only one command database file is generated per `b2` invocation. And each
time it is generated it overwrites any previous such file.

0 comments on commit c10679b

Please sign in to comment.