Scanning Objective-c code only in a mixed Objective-c and C++ project

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    **SonarQube 8.9 LTS
    ** sonar-scanner-cli-4.6.2.2472-macosx
    ** build-wrapper-macosx-x86
  • what are you trying to achieve
    scan an iOS project written in objective-c and C++
  • what have you tried so far to achieve this
    I followed the guide in the documentation in https://docs.sonarqube.org/8.9/analysis/languages/cfamily/
    The analysis report on SonarQube server shows code smells and duplications but it shows 0 bugs.
    I tried to scan pure Objective-c project and it is working fine.

I found that code written in Objective-c and C++ together is not supported by sonarQube yet. as it shows here [CPP-649] Add support for Objective-C++ language - SonarSource

I want to know if this is the case why I get 0 bugs. If so? is there is a way to scan only objective-c code and ignore C++?

Thank you

Hi @Ahmed_Ghareeb ,

Objective-C++ code is already ignored.

Could you please share the sonar-scanner analysis log?

Hi @Ahmed_Ghareeb ,

I am not sure you are properly configuring the analysis. Looking at your log you are having only /Users/serv_jenkinsmacos/jenkins/workspace/iOSWorkspace_PR-55/MobiControl/iOSWorkspace/iOSAgent/Carthage/Checkouts/** files being analyzed which are dependencies.

Could you share the debug log of the analysis? You can add sonar.verbose=true property to get it.

You should look at having:

  • build-wrapper to catch a clean build
  • analysis to be correctly configured with a good sonar.sources property.

I am not sure you are properly configuring the analysis. Looking at your log you are having only /Users/serv_jenkinsmacos/jenkins/workspace/iOSWorkspace_PR-55/MobiControl/iOSWorkspace/iOSAgent/Carthage/Checkouts/** files being analyzed which are dependencies.

That is exactly the problem, if I remove this dependency I get an error that 0 files scanned. As if the project files are not being seen as objectiv-c code.
I need to analyze /Users/serv_jenkinsmacos/jenkins/workspace/iOSWorkspace_PR-55/MobiControl/iOSWorkspace/iOSAgent/iOSAgent
which is my project.
please see the requested attachements.

and this is how I run the build-wrapper and the scanner:

${workspace}/build-wrapper-macosx-x86/build-wrapper-macosx-x86 --out-dir build_wrapper_output_directory ./MobiControl/iOSWorkspace/iOSAgent/ops/BuildScript.sh

cd ${workspace}/MobiControl/iOSWorkspace

${workspace}/sonar-scanner-4.6.2.2472-macosx/bin/sonar-scanner -Dsonar.cfamily.build-wrapper-output=${workspace}/build_wrapper_output_directory -Dsonar.verbose=true

Hi @Ahmed_Ghareeb ,

could you please share also the build_wrapper_output_directory?

In sonar-project.properties.txt I can see some properties which have nothing to do with our plugin:

sonar.objectivec.project=iOSAgent/iOSAgent.xcodeproj 
sonar.objectivec.workspace=iOSMobiControl.xcworkspace

sonar.objectivec.appScheme=iOSAgent

and sonar.language=objc is not needed.

hi @mpaladin

I did a fresh scan after removing the properties you suggested that are not used by the plugin.

as you can see in the image It is not reporting any bugs in iOSAgent project.

Hi @mpaladin,

Please let me know if you have any updates regarding the above.

Thank you.

Hi @Ahmed_Ghareeb ,

the reason why your source files are excluded is that you are compiling them as objective-c++, in the build-wrapper-dump.json file your source files are compiled with option -x objective-c++. We don’t support objective-c++, are you really using objective-c++ or can you set the language to objective-c?

What do you mean by set the language to objective-c instead of objective-c++?

Hi @Ahmed_Ghareeb ,

you are building your project in objective-c++ mode, is that intended? Do you really have some code that is a mix of objective-c and c++? Isn’t it that maybe that is not intended and you have just objective-c or c++ code?

Yes we have a mixed code of objective-c and c++, this is intended.

Then I am sorry but Objective-C++ is not supported as seen in CPP-649, this is why you see no issues for those files.

Thank you very much for confirming that. Now I know what is the issue and I can move forward.

1 Like

@mpaladin can we remove the shared attachments please. I am not comfortable having them online.
Thank you for your understanding.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.