Skip to main content

Generates compilation databases by capturing standard output from Make

Project description

Compile Commands Database GENerator

PyPI status PyPi version PyPI pyversions GitHub license

About

A Python script to generate a compile_commands.json database by capturing the output of make. This script was originally created to provide compilation databases for make based C/C++ projects in Visual Studio Code.

Installation

Latest PyPi release

pip install ccdgen

Usage

python3 -m ccdgen --extensions <arguments...> -- <your build command>

Arguments:

Option Default Description
-h, --help Show help message and exit
-c, --compiler (auto detect) Specify compiler
-d, --dir ./ Working directory to run make from
-e, --extensions Extension(s) for source files
-o, --output ./compile_commands.json Output file

For example, to run make all as the build command for a C project:

python3 -m ccdgen --extensions .c -- make all

Example Visual Studio Code task:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "ccdgen",
            "type": "shell",
            "command": "python",
            "osx": {
                "command": "python3"
            },
            "args": [
                "-m", "ccdgen",
                "--extensions", ".c",
                "--", "make", "all"
            ]
        }
    ]
}

Limitations

  • The script relies on the Python standard library modules argparse, json, os, subprocess and sys.
  • This script relies on make echoing the compiler commands it runs to stdout. If compiler commands are prefixed in the Makefile with @ or make is run in silent mode, the output cannot be captured.
  • The build must succeed to generate a full compilation database, though warnings are not a problem.
  • Currently only tested with Python 3.10 on macOS Ventura and Windows 10.

Other Tools

  • CMake (since version 2.8.5) can be used as is to generate compile_commands.json by adding -DCMAKE_EXPORT_COMPILE_COMMANDS=ON when calling it. This only works for Unix Makefile builds.
  • Bear is much more advanced tool for generating compilation databases for clang tooling. macOS, Linux and FreeBSD are currently supported.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

ccdgen-0.0.11-py3-none-any.whl (9.4 kB view hashes)

Uploaded Python 3

Supported by

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