Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve docs about the compilation database #151

Merged
merged 4 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ This is a C/C++ code analysis plugin for VSCode that shows bug reports detected

1. [Install CodeChecker] version 6.18.2 or later, and optionally add it to the `PATH` environment variable.
2. Install the CodeChecker extension from the [Visual Studio Marketplace], from [Open VSX], or download manually from [Downloads].
3. Check the path to CodeChecker, and set your preferred command-line arguments - see [Configuring CodeChecker] for more information.
4. Open your project, and run an analysis, or browse through the found reports!
3. [Set up your build environment] to generate a `compile_commands.json` file.
4. Check the path to CodeChecker, and set your preferred command-line arguments - see [Configuring CodeChecker] for more information.
5. Open your project, and run an analysis, or browse through the found reports!

[Install CodeChecker]: https://github.com/Ericsson/CodeChecker#install-guide
[Visual Studio Marketplace]: https://marketplace.visualstudio.com/items?itemName=codechecker.vscode-codechecker
[Open VSX]: https://open-vsx.org/extension/codechecker/codechecker
[Downloads]: https://github.com/Ericsson/CodecheckerVSCodePlugin/releases
[Set up your build environment]: #setting-up-your-build-environment
[Configuring CodeChecker]: #configuring-codechecker

## Features
Expand All @@ -37,6 +39,19 @@ This is a C/C++ code analysis plugin for VSCode that shows bug reports detected

![Commands and tasks](media/codechecker-tasks.gif)

## Setting up your build environment

CodeChecker works by reading a generated [compilation database], often called `compile_commands.json`, and executing specific analyses based on that.

`CMake` has built-in support for generating a compilation database. Set the environment variable `CMAKE_EXPORT_COMPILE_COMMANDS=ON`, and the compilation database should be inside your build folder.
If you are using the `CMake Tools` extension for VS Code, you can add this flag to the extension settings under `Cmake > Build Environment`.

`make` and other build systems have no built-in support for generating a compilation database, but CodeChecker can generate one based on the build command. To generate one, you can use the command `CodeChecker log -b "[full build command]" -o .codechecker/compile_commands.json`.

To automate the process, the extension provides ways to run the `CodeChecker log` command automatically. First, in the Extension Settings set `CodeChecker > Executor > Log build command`, and then use either the VS Code Task, or the VS Code command `CodeChecker: Run CodeChecker Log` to execute the analysis. You can also run `CodeChecker: Preview CodeChecker log in terminal` to have more fine-grained control over the parameters passed to CodeChecker.

[compilation database]: https://clang.llvm.org/docs/JSONCompilationDatabase.html

## Configuring CodeChecker

The extension uses Codechecker version 6.18.2 or later. If your installation path is different, or CodeChecker is not in the the `PATH` environment variable, the path to it can be set manually under `Preferences > Settings > Extensions > CodeChecker > Executable path`.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
},
"codechecker.executor.logBuildCommand": {
"type": "string",
"description": "The build command passed to CodeChecker log.",
"description": "The build command passed to CodeChecker log. Some build systems do not need to be run via CodeChecker log - see the extension's docs for details.",
"default": "make",
"order": 6
},
Expand Down
9 changes: 8 additions & 1 deletion src/editor/initialize.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExtensionContext, commands, window, workspace } from 'vscode';
import { ExtensionContext, Uri, commands, window, workspace } from 'vscode';
import { ExtensionApi } from '../backend';
import { Editor } from './editor';
import { NotificationType } from './notifications';
Expand Down Expand Up @@ -42,6 +42,13 @@ export class FolderInitializer {
{
title: 'Locate',
command: 'codechecker.internal.locateCompilationDatabase'
},
{
title: 'More info',
command: 'vscode.open',
arguments: [ Uri.parse(
'https://github.com/Ericsson/CodeCheckerVSCodePlugin#setting-up-your-build-environment'
) ]
}
];
const disableDialogChoice = {
Expand Down
Loading