From 83117ae578f430e403e90a4b6fc7e2b1c2c63f81 Mon Sep 17 00:00:00 2001 From: Discookie Date: Mon, 1 Jul 2024 08:48:32 +0000 Subject: [PATCH 1/3] Add a blob in the README about generating a compilation db --- README.md | 17 +++++++++++++++-- src/editor/initialize.ts | 9 ++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d938841..6ffb927 100644 --- a/README.md +++ b/README.md @@ -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 @@ -37,6 +39,17 @@ 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. + ## 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`. diff --git a/src/editor/initialize.ts b/src/editor/initialize.ts index ca3e8d4..033563e 100644 --- a/src/editor/initialize.ts +++ b/src/editor/initialize.ts @@ -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'; @@ -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 = { From 1d776fc6c6913e975ea8cb55728d7e258cffb548 Mon Sep 17 00:00:00 2001 From: Discookie Date: Thu, 4 Jul 2024 08:37:46 +0000 Subject: [PATCH 2/3] Add blob about not being necessary to run CodeChecker log, per the README --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f21bcbd..5c4f491 100644 --- a/package.json +++ b/package.json @@ -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 }, From a319e31db616b374f7a371b8ca1fd527de5bffa5 Mon Sep 17 00:00:00 2001 From: Discookie Date: Fri, 12 Jul 2024 12:41:52 +0000 Subject: [PATCH 3/3] Add link for compilation database --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6ffb927..c79ed51 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ This is a C/C++ code analysis plugin for VSCode that shows bug reports detected ## 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. +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`. @@ -50,6 +50,8 @@ If you are using the `CMake Tools` extension for VS Code, you can add this flag 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`.