Skip to content

CPP-5239 Migrate to compilation database output format #6

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

Merged
merged 12 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
12 changes: 9 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@ It is very easy to manually analyze a C, C++ and Objective-C project with SonarQ

. Create a `sonar-project.properties` file to store your configuration
.. Add a projectKey of your project
.. Add a Build Wrapper output directory
.. https://docs.sonarqube.org/latest/user-guide/user-token/[Generate a unique token] and set it as "sonar.login" (`SONARQUBE_TOKEN` in this example project)
.. Set `sonar.host.url` to your SonarQube server URL
. Download and unzip the Build Wrapper for macOS from {SonarQube URL}/static/cpp/build-wrapper-macosx-x86.zip
. Add the Build Wrapper to your `$PATH`
. Download and unzip the https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/[SonarScanner] for macOS
. Add the bin directory of the SonarScanner to your `$PATH`
. Wrap your clean build command with the Build Wrapper. E.g.: `build-wrapper-macosx-x86 --out-dir bw-output xcodebuild clean build` (with `bw-output` being the same directory as the one set in `sonar-project.properties`)
. Run `sonar-scanner`
. Wrap your clean build command with the Build Wrapper. E.g.: `build-wrapper-macosx-x86 --out-dir bw-output xcodebuild clean build`
. Run `sonar-scanner` specifying:
+
--
.. `-Dsonar.cfamily.compile-commands=bw-output/compile_commands.json` if you are using SonarQube version 10.6 or later
.. `-Dsonar.cfamily.build-wrapper-output=bw-output` if you are using SonarQube version 10.5 or earlier, as build-wrapper did not generate a `compile_commands.json` file before SonarQube 10.6
--
+
Noting that `bw-output` is the directory passed to build wrapper as `--out-dir`

You can take a look at the link:sonar-project.properties[sonar-project.properties] and link:build-analyze.sh[build-analyze.sh] (a script that downloads the `sonar-scanner` and the Build Wrapper before compiling and analyzing the project) to see it in practice. Please be aware that the SonarQube server URLs and the `sonar.login` are not completed in these examples.

Expand Down
4 changes: 3 additions & 1 deletion build-analyze.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ xcodebuild -project macos-xcode.xcodeproj clean
build-wrapper-macosx-x86 --out-dir $BUILD_WRAPPER_OUT_DIR xcodebuild -project macos-xcode.xcodeproj -configuration Release

# Run sonar scanner
sonar-scanner -Dsonar.host.url="${SONAR_HOST_URL}" -Dsonar.login=$SONAR_TOKEN -Dsonar.cfamily.build-wrapper-output=$BUILD_WRAPPER_OUT_DIR
sonar-scanner -Dsonar.host.url="${SONAR_HOST_URL}" -Dsonar.login=$SONAR_TOKEN -Dsonar.cfamily.compile-commands=$BUILD_WRAPPER_OUT_DIR/compile_commands.json
# if you are using using SonarQube 10.5 or earlier, replace -Dsonar.cfamily.compile-commands with -Dsonar.cfamily.build-wrapper-output=$BUILD_WRAPPER_OUT_DIR
# as build-wrapper does not generate a compile_commands.json file before SonarQube 10.6