Skip to main content

Generate compile_commands.json from a build log with compiler invocations

Project description

log2compdb

This is a simple script to parse out compiler invocations from a build log and generate a compile_commands.json compilation database. This might be useful on macOS or in any other case where Bear doesn't work correctly. Theoretically any build log that contains full compiler invocations (e.g. gcc -c -o foo.o -DENABLE_SOME_FEATURE -I./include foo.c) should work, but I've only tested pretty limited cases.

Usage

log2compdb takes three arguments:

  • The build log file, with -i/--in
  • The path to the desired output file, with -o/--out (defaults to compile_commands.json in the current directory)
  • The compiler used in that build log, with -c/--compiler — an absolute path works best, but isn't required
    • If your build log has multiple compilers (for example if your build includes host and cross compilation objects), then -c can be specified multiple times.

Example

Let's take the firmware repository for the Black Magic Probe project for an example. Many build systems don't output the compiler invocations by default, requiring a variable like BUILD_VERBOSE=1 or V=1. In Blackmagic's case, it looks like this:

$ make V=1 > build.log

It can be important that you don't pass a -j argument (other than -j1), as log2compdb uses directory change log entries as well, which will be out of order if you build in parallel.

Non-parallel builds can take a while, so you might want to include the build output in your terminal as well with something like:

$ make V=1 | tee /dev/stdin > build.log

After that, you can run log2compdb, telling it the path to the build log, and the compiler used in the build. In the case of the Black Magic Probe firmware, that's going to be arm-none-eabi-gcc, which on my system is in /opt/homebrew/bin, so for me generating the compile_commands.json looks like this:

$ log2compdb -i build.log -o compile_commands.json -c /opt/homebrew/bin/arm-none-eabi-gcc

Alternatively, you can also tell log2comp2db to read from standard in, and skip the extra file:

$ make V=1 | tee /dev/stdin | log2compdb -o compile_commands.json -c /opt/homebrew/bin/arm-none-eabi/gcc

Installation

log2compdb is packaged on PyPI, and can be installed with Python packaging tools, such as pip:

$ pip install log2compdb

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

log2compdb-0.2.3.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

log2compdb-0.2.3-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file log2compdb-0.2.3.tar.gz.

File metadata

  • Download URL: log2compdb-0.2.3.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for log2compdb-0.2.3.tar.gz
Algorithm Hash digest
SHA256 44d6e68c9d598b006915fc9cdd3b9451150cfde0ec77276404ccf8588c1b2aa6
MD5 648b41071a4dd1e18a605032539b0327
BLAKE2b-256 df9635c513846a4d2fa984b994d7ef5d666d4a62a590a10388362fa7d577394e

See more details on using hashes here.

File details

Details for the file log2compdb-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: log2compdb-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for log2compdb-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 36154bddc146a360d0f554b8b2acf92c76e988ea59c94b583a8be853ecae3cdc
MD5 8a343bd76625cb031b9739b7771d0d7a
BLAKE2b-256 0e10cf4989effd96630786b94b286c20b13472ec6e108c6975a574d5a6a251ba

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page