# 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](https://github.com/rizsotto/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](https://github.com/blackmagic-debug/blackmagic) 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:
```bash
$ 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:
```bash
$ 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:
```bash
$ 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:
```bash
$ 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](https://pypi.org/project/log2compdb/), and can be installed with Python
packaging tools, such as pip:
```bash
$ pip install log2compdb
```
Raw data
{
"_id": null,
"home_page": "https://github.com/Qyriad/log2compdb",
"name": "log2compdb",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "build-tool,build-system,compilation-database",
"author": "Qyriad",
"author_email": "qyriad@qyriad.me",
"download_url": "https://files.pythonhosted.org/packages/49/34/185ec8bae13948ce983fea8a1c73ddde3e0f5ab7aee93b1cc690a484702f/log2compdb-0.2.5.tar.gz",
"platform": "any",
"description": "# log2compdb\n\nThis is a simple script to parse out compiler invocations from a build log and generate a `compile_commands.json`\ncompilation database. This might be useful on macOS or in any other case where [Bear](https://github.com/rizsotto/Bear)\ndoesn't work correctly. Theoretically any build log that contains full compiler invocations (e.g. `gcc -c -o foo.o\n-DENABLE_SOME_FEATURE -I./include foo.c`) should work, but I've only tested pretty limited cases.\n\n## Usage\n\n`log2compdb` takes three arguments:\n\n- The build log file, with `-i`/`--in`\n- The path to the desired output file, with `-o`/`--out` (defaults to `compile_commands.json` in the current directory)\n- The compiler used in that build log, with `-c`/`--compiler` \u2014 an absolute path works best, but isn't required\n - If your build log has multiple compilers (for example if your build includes host and cross compilation\n objects), then `-c` can be specified multiple times.\n\n## Example\n\nLet's take the [firmware repository](https://github.com/blackmagic-debug/blackmagic) for the Black Magic Probe\nproject for an example. Many build systems don't output the compiler invocations by default, requiring a variable\nlike `BUILD_VERBOSE=1` or `V=1`. In Blackmagic's case, it looks like this:\n\n```bash\n$ make V=1 > build.log\n```\n\nIt can be important that you don't pass a `-j` argument (other than `-j1`), as `log2compdb` uses directory change\nlog entries as well, which will be out of order if you build in parallel.\n\nNon-parallel builds can take a while, so you might want to include the build output in your terminal as well with\nsomething like:\n\n```bash\n$ make V=1 | tee /dev/stdin > build.log\n```\n\nAfter that, you can run `log2compdb`, telling it the path to the build log, and the compiler used in the build.\nIn the case of the Black Magic Probe firmware, that's going to be `arm-none-eabi-gcc`, which on my system is in\n`/opt/homebrew/bin`, so for me generating the `compile_commands.json` looks like this:\n\n```bash\n$ log2compdb -i build.log -o compile_commands.json -c /opt/homebrew/bin/arm-none-eabi-gcc\n```\n\nAlternatively, you can also tell `log2comp2db` to read from standard in, and skip the extra file:\n\n```bash\n$ make V=1 | tee /dev/stdin | log2compdb -o compile_commands.json -c /opt/homebrew/bin/arm-none-eabi/gcc\n```\n\n## Installation\n\n`log2compdb` is packaged on [PyPI](https://pypi.org/project/log2compdb/), and can be installed with Python\npackaging tools, such as pip:\n\n```bash\n$ pip install log2compdb\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Generate compile_commands.json from a build log with compiler invocations",
"version": "0.2.5",
"project_urls": {
"Homepage": "https://github.com/Qyriad/log2compdb"
},
"split_keywords": [
"build-tool",
"build-system",
"compilation-database"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "679ca17bb3f2bd81ad22790c12d494c7c77f9f67270f14bf4fe819fe489dc023",
"md5": "d37e8a27836c5717a7df26eb704e8ab2",
"sha256": "8cb6f1bfd09301861bdb72e0d76f407d13a23f1a4b9f42e8932c9f9d0864450f"
},
"downloads": -1,
"filename": "log2compdb-0.2.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d37e8a27836c5717a7df26eb704e8ab2",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 5977,
"upload_time": "2023-08-31T19:27:08",
"upload_time_iso_8601": "2023-08-31T19:27:08.863519Z",
"url": "https://files.pythonhosted.org/packages/67/9c/a17bb3f2bd81ad22790c12d494c7c77f9f67270f14bf4fe819fe489dc023/log2compdb-0.2.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4934185ec8bae13948ce983fea8a1c73ddde3e0f5ab7aee93b1cc690a484702f",
"md5": "e8994d2259a6e5b981a2a0969e694c20",
"sha256": "456b6ac354f428c0493a7fa1d4f7197bbe81b8c27ac35b5706b289d0beef76b4"
},
"downloads": -1,
"filename": "log2compdb-0.2.5.tar.gz",
"has_sig": false,
"md5_digest": "e8994d2259a6e5b981a2a0969e694c20",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5937,
"upload_time": "2023-08-31T19:27:10",
"upload_time_iso_8601": "2023-08-31T19:27:10.242236Z",
"url": "https://files.pythonhosted.org/packages/49/34/185ec8bae13948ce983fea8a1c73ddde3e0f5ab7aee93b1cc690a484702f/log2compdb-0.2.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-08-31 19:27:10",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Qyriad",
"github_project": "log2compdb",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "log2compdb"
}