Error when scanning Objc code for SonarCloud in Azure DevOps

Hi…

I am setting up a SonarCloud scan for my ObjectiveC project in Azure DevOps.

I set up a SonarCloud account ad added the required steps into my build process in Azure DevOps using CLI scanner but I always get an error in my SonarCloudAnalyze task.

The project I am trying to set up has a base iOS target 12.4 and is a clean Objective C project. ( No complex code, No Pods, and only Objective C code )

The error I am getting in the SonarQube analyze task is:

##[error]ERROR: Error during SonarQube Scanner execution
ERROR: Error during SonarQube Scanner execution
##[error]java.lang.IllegalStateException: java.nio.file.NoSuchFileException: /Users/runner/runners/2.158.0/work/1/s/build_wrapper_output/build-wrapper-dump.json

According to the documentation, you have to set the sonar.cfamily.build-wrapper-output property to be able to scan Objective-C code.

If I create the folder before analyzing, I get another error.

##[error]ERROR: Error during SonarQube Scanner execution

ERROR: Error during SonarQube Scanner execution
##[error]java.lang.IllegalStateException: java.nio.file.NoSuchFileException: /Users/runner/runners/2.158.0/work/1/s/build_wrapper_output/build-wrapper-dump.json

And if I go and create the folder and file I get this error here:

##[error]ERROR: Error during SonarQube Scanner execution
ERROR: Error during SonarQube Scanner execution
##[error]java.lang.IllegalStateException: java.io.EOFException: End of input at line 1 column 1
java.lang.IllegalStateException: java.io.EOFException: End of input at line 1 column 1
##[error]at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:311)
##[error]at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:206)

The original error suggests that I should add the following lines to my config but the whole idea is to scan my objective c code.

sonar.c.file.suffixes=-
sonar.cpp.file.suffixes=-
sonar.objc.file.suffixes=-

I ran into some posts in where a suggested fix for this would be to call a specific build-wrapper instead of https://sonarcloud.io but I have not found a good way to do that within Azure DevOps. (Issue with build-wrapper-output)
vmImage:
I am running a macOS-10.14 image in Azure Devops.

Azure devops SonarCube log info:

INFO: Project root configuration file: NONE
INFO: SonarQube Scanner 4.1.0.1829
INFO: Java 1.8.0_222 Azul Systems, Inc. (64-bit)
INFO: Mac OS X 10.14.6 x86_64
INFO: User cache: /Users/runner/.sonar/cache
INFO: SonarQube server 8.0.0

My prepare task in the Azure DevOps build process:

task: SonarCloudPrepare@1
  inputs:
    SonarCloud: 'https://sonarcloud.io'
    organization: 'myorg'
    scannerMode: 'CLI'
    configMode: 'manual'
    cliProjectKey: 'AzIT.ObjcDemo'
    cliProjectName: 'AzIT.ObjcDemo'
    cliSources: '.'
    extraProperties: |
      sonar.cfamily.build-wrapper-output=build_wrapper_output

Is there anything i’m missing in config or is this a known issue in the latest macOS image in Azure DevOps ?

Hi,

How do you invoke the scanner itself ?

Do you use the sonar-scanner.bat executable, or something else ?

Thanks.

Mickaël

Hello @ivarorn,

Hare you run the build wrapper tool while building your code, as explained in https://sonarcloud.io/documentation/analysis/languages/cfamily/?

hi @mickaelcaro

I use these tasks in my Azure DevOps Build pipeline

  • task: SonarCloudPrepare@1
  • task: Xcode@5
  • task: SonarCloudAnalyze@1
  • task: SonarCloudPublish@1

Works fine with plain vanilla Swift project but not in our Objective C projects

hi @JolyLoic

I am running from Azure DevOps. ( using the macOS-10.14 image )
How should I invoke the wrapper tool while building ?
The scan and build for my swift project was set up only using the standard DevOps SonarCloud build tasks in Azure DevOps.

Does the Objc scan require manual powershell downloads/and command invokes ?

Hi @ivarorn,

You need to setup manual download and wrap of your build, all information available in the documentation page: SonarCloud.