Is a successful build required before running sonar-scan?

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)

    • sonarqube-developer-8.2.0.32929
    • sonar-scanner-cli-4.2.0.1873-linux
    • build-wrapper-linux-x86
    • sonar-cfamily-plugin-6.8.0.16475
  • what are you trying to achieve
    Scan a C project

  • what have you tried so far to achieve this

    • Successfully scanned sample-c-cpp project from SonarQube
    • Tried scanning our C project without building it, got ScannerException: Unable to execute SonarQube

Stack trace:

$sonar.sh status

SonarQube is running (14806).

$sonar-scanner   -Dsonar.projectKey=OTH-Common   -Dsonar.sources=.   -Dsonar.host.url=https://swe-oth-sonarqube-lb-683593332.us-gov-west-1.elb.amazonaws.com   -Dsonar.login=d77419a5d8a0eb5e8345c6238105ecf3c07bea7d -X

08:10:52.927 INFO: Scanner configuration file: /home/anguyen/sonarqube/sonar-scanner/conf/sonar-scanner.properties
08:10:52.932 INFO: Project root configuration file: /home/anguyen/swat-dev/SWAT/AFCAP/Common/sonar-project.properties
08:10:52.958 INFO: SonarQube Scanner 4.2.0.1873
08:10:52.958 INFO: Java 11.0.3 AdoptOpenJDK (64-bit)
08:10:52.958 INFO: Linux 3.10.0-1127.el7.x86_64 amd64
08:10:53.109 DEBUG: keyStore is :
08:10:53.109 DEBUG: keyStore type is : pkcs12
08:10:53.109 DEBUG: keyStore provider is :
08:10:53.109 DEBUG: init keystore
08:10:53.109 DEBUG: init keymanager of type SunX509
08:10:53.230 DEBUG: Create: /home/anguyen/.sonar/cache
08:10:53.231 INFO: User cache: /home/anguyen/.sonar/cache
08:10:53.231 DEBUG: Create: /home/anguyen/.sonar/cache/_tmp
08:10:53.233 DEBUG: Extract sonar-scanner-api-batch in temp…
08:10:53.237 DEBUG: Get bootstrap index…
08:10:53.237 DEBUG: Download: https://swe-oth-sonarqube-lb-683593332.us-gov-west-1.elb.amazonaws.com/batch/index
08:11:03.297 ERROR: SonarQube server [https://swe-oth-sonarqube-lb-683593332.us-gov-west-1.elb.amazonaws.com] can not be reached
08:11:03.297 INFO: ------------------------------------------------------------------------
08:11:03.297 INFO: EXECUTION FAILURE
08:11:03.297 INFO: ------------------------------------------------------------------------
08:11:03.298 INFO: Total time: 10.399s
08:11:03.307 INFO: Final Memory: 3M/14M
08:11:03.308 INFO: ------------------------------------------------------------------------
08:11:03.308 ERROR: Error during SonarQube Scanner execution
org.sonarsource.scanner.api.internal.ScannerException: Unable to execute SonarQube
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:85)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:74)
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:70)
at org.sonarsource.scanner.api.EmbeddedScanner.doStart(EmbeddedScanner.java:185)
at org.sonarsource.scanner.api.EmbeddedScanner.start(EmbeddedScanner.java:123)
at org.sonarsource.scanner.cli.Main.execute(Main.java:73)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: java.lang.IllegalStateException: Fail to get bootstrap index from server
at org.sonarsource.scanner.api.internal.BootstrapIndexDownloader.getIndex(BootstrapIndexDownloader.java:42)
at org.sonarsource.scanner.api.internal.JarDownloader.getScannerEngineFiles(JarDownloader.java:58)
at org.sonarsource.scanner.api.internal.JarDownloader.download(JarDownloader.java:53)
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:76)
… 7 more
Caused by: java.net.SocketTimeoutException: connect timed out
at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
at java.base/java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.base/java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.base/java.net.SocksSocketImpl.connect(Unknown Source)
at java.base/java.net.Socket.connect(Unknown Source)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.platform.Platform.connectSocket(Platform.java:130)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.RealConnection.connectSocket(RealConnection.java:263)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.RealConnection.connect(RealConnection.java:183)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.java:224)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.java:108)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.ExchangeFinder.find(ExchangeFinder.java:88)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.Transmitter.newExchange(Transmitter.java:169)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:41)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:94)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:88)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
at org.sonarsource.scanner.api.internal.shaded.okhttp.RealCall.getResponseWithInterceptorChain(RealCall.java:221)
at org.sonarsource.scanner.api.internal.shaded.okhttp.RealCall.execute(RealCall.java:81)
at org.sonarsource.scanner.api.internal.ServerConnection.callUrl(ServerConnection.java:113)
at org.sonarsource.scanner.api.internal.ServerConnection.downloadString(ServerConnection.java:98)
at org.sonarsource.scanner.api.internal.BootstrapIndexDownloader.getIndex(BootstrapIndexDownloader.java:39)
… 10 more

Hi @anguyen,

can you make sure that the firewall is correctly setup? It seems that sonar-scanner cannot contact the SonarQube server.

Hello Massimo,

Could you suggest what protocols and ports we should open up?

I am not the administrator for the machine where SonarQube is running, so it would be much easier to communicate with our IT department if we have specific requests.

Thanks so much,
Ai

Hi @anguyen,

please check your SonarQube server configuration, the default port is 9000 tcp, I don’t know in your setup.

Massimo,

I used the default port 9000.
I will double check to make sure.

Thank you,
Ai

1 Like

Hello Massimo,

We were able to resolve the network issue, but now run into a scanner issue (stack trace below).
As far as I can tell the wrapper ran correctly.
I was also able to run make on the project and successfully create a .so library from it.

Thank you,
Ai

15:34:06.296 ERROR: Error during SonarQube Scanner execution
java.lang.IllegalStateException: The “build-wrapper-dump.json” file was found but 0 C/C++/Objective-C files were analyzed. Please make sure that:

  • you are using the latest version of the build-wrapper and the SonarCFamily analyzer
  • you are correctly invoking the scanner with correct configuration * your compiler is supported
  • you are wrapping your build correctly
  • you are wrapping a full/clean build
  • you are providing the path to the correct build-wrapper output directory
  • you are building and analyzing the same source checkout, absolute paths must be identical in build and analysis steps
    at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:357)
    at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
    at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
    at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:62)
    at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
    at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:386)
    at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:382)
    at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:351)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
    at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:141)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
    at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
    at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
    at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.base/java.lang.reflect.Method.invoke(Unknown Source)
    at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
    at com.sun.proxy.$Proxy0.execute(Unknown Source)
    at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
    at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
    at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
    at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
    at org.sonarsource.scanner.cli.Main.main(Main.java:61)

Output from make clean and make:

~/swat-dev/SWAT/AFCAP/Common/Source$make clean

rm -f *.o
cd …/…/…/AFCAP/deploy/include;
rm -f oth_log.h oth_cfg.h oth_constants.h oth_errors.h oth_time_utils.h oth_util.h oth_geo.h oth_types.h
…/…/…/AFCAP/deploy/include: No such file or directory.
rm -f libCommon.so
rm -f …/…/…/AFCAP/deploy/lib/libCommon.so
~/swat-dev/SWAT/AFCAP/Common/Source$make
/usr/bin/gcc -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -O2 -fPIC -DLINUX -I…/…/…/AFCAP/Common/Includes -I…/…/…/AFCAP/Messaging/Includes -c pwd/oth_cfg.c
/usr/bin/gcc -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -O2 -fPIC -DLINUX -I…/…/…/AFCAP/Common/Includes -I…/…/…/AFCAP/Messaging/Includes -c pwd/oth_log.c
/usr/bin/gcc -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -O2 -fPIC -DLINUX -I…/…/…/AFCAP/Common/Includes -I…/…/…/AFCAP/Messaging/Includes -c pwd/oth_util.c
/usr/bin/gcc -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -O2 -fPIC -DLINUX -I…/…/…/AFCAP/Common/Includes -I…/…/…/AFCAP/Messaging/Includes -c pwd/oth_errors.c
/usr/bin/gcc -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -O2 -fPIC -DLINUX -I…/…/…/AFCAP/Common/Includes -I…/…/…/AFCAP/Messaging/Includes -c pwd/oth_time_utils.c
/usr/bin/gcc -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -O2 -fPIC -DLINUX -I…/…/…/AFCAP/Common/Includes -I…/…/…/AFCAP/Messaging/Includes -c pwd/oth_geo.c
/usr/bin/gcc -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -O2 -fPIC -DLINUX -I…/…/…/AFCAP/Common/Includes -I…/…/…/AFCAP/Messaging/Includes -c pwd/oth_types.c
/usr/bin/gcc -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -O2 -fPIC -DLINUX -I…/…/…/AFCAP/Common/Includes -I…/…/…/AFCAP/Messaging/Includes -shared oth_cfg.o oth_log.o oth_util.o oth_errors.o oth_time_utils.o oth_geo.o oth_types.o -lm -o libCommon.so
~/swat-dev/SWAT/AFCAP/Common/Source$echo $?
0
~/swat-dev/SWAT/AFCAP/Common/Source$lf *.so
-rwxrwxr-x. 1 anguyen anguyen 286632 May 18 15:48 libCommon.so

Hi @anguyen,

could you share the build-wrapper output directory content (build-wrapper.log and build-wrapper-dump.json files) and the sonar-scanner output with -Dsonar.verbose=true property specified?

build-wrapper.log (38.9 KB)

build-wrapper-dump.json (24.8 KB)

sonar-scanner-output.log (31.1 KB)

Please let me know if you need anything else.
Thank you.

Hi @anguyen,

in build-wrapper-dump.json I can see only:

"/usr/bin/gcc",
"-Wall",
"-Wextra",
"-Wno-unused-variable",
"-Wno-unused-parameter",
"-Wno-unused-but-set-variable",
"-O2",
"-fPIC",
"-DLINUX",
"-I../../../AFCAP/Common/Includes",
"-I../../../AFCAP/Messaging/Includes",
"-shared",
"oth_cfg.o",
"oth_log.o",
"oth_util.o",
"oth_errors.o",
"oth_time_utils.o",
"oth_geo.o",
"oth_types.o",
"-lm",
"-o",
"libCommon.so"

that’s a linker call, could you make sure you are running a clean build?

Hi Massimo,

Could you define ‘clean build’?

This project produces a library, libCommon.so
It does not produce an executable

I ran:

  1. make clean
  2. make
    both completed successfully and libCommon.so was created
    (please see output uploaded 4 days ago)

So i’m not sure what ‘clean build’ requires?
Please clarify

Thanks very much,
Ai

Hi @anguyen,

this compiler call is a linker call, the *.o files are object files, not C source files. In build-wrapper-dump.json I don’t see the call to gcc to compile the *.c files which I can see in the sonar-scanner log:

07:17:31.534 DEBUG: 'Test/geo_test.c' indexed with language 'c'
07:17:31.535 DEBUG: 'Test/time_utils_test.c' indexed with language 'c'
07:17:31.536 DEBUG: 'Test/util_test.c' indexed with language 'c'
07:17:31.537 DEBUG: 'oth_cfg.c' indexed with language 'c'
07:17:31.538 DEBUG: 'oth_errors.c' indexed with language 'c'
07:17:31.539 DEBUG: 'oth_geo.c' indexed with language 'c'
07:17:31.540 DEBUG: 'oth_log.c' indexed with language 'c'
07:17:31.544 DEBUG: 'oth_time_utils.c' indexed with language 'c'
07:17:31.545 DEBUG: 'oth_types.c' indexed with language 'c'
07:17:31.546 DEBUG: 'oth_util.c' indexed with language 'c'

A clean build is a build where all source files are compiled, an incremental build is a build where only modified files are built.

Massimo,

That helps.
I will look into it.

Thank you!
Ai

Hi @anguyen,

did you make any progress?

Hi Massimo,

It was a holiday weekend in the US, so I haven’t been working.
I plan to look into it tomorrow.

Thank you for asking, I will keep you posted.
Ai

Massimo,

Using the hints from your reply, and also your definition of “clean build”, I was able to correct our sonar-project.properties and the scan completed successfully.

The problem was I had put sonar-project.properties in the wrong directory and tried scanning from that directory. I moved to the top level of the project and it worked.

I’m closing this issue.
Thanks so much for your help,
Ai