Sonar scanner analysis Failing with Sonar Developer Edition

Using SonarQube:
sonarqube-developer-9.9.0.65466,
sonar-scanner-cli-4.8.0.2856-windows
build-wrapper, version 6.41 (win-x86-64)

We recently upgraded from community Edition to Developer edition, right now we are evaluating the same. During the analysis of our source code, we are facing following issue.

INFO: Trying to deduce “INCLUDE” environment variable from C:\buildtools\vcc16.0\bin\Hostx64\x64\cl.exe
ERROR: Could not find Visual Studio install from: C:\buildtools\vcc16.0\bin\Hostx64\x64\cl.exe
ERROR: The “INCLUDE” environment variable was not found, make sure that you are running the analysis from the right environment. Skip analysis of files: [C:/views/view-1/superfiery/repos/vobs/fiery/vw/mvid/ricoh/recsa/src/core_video/src/aegis_xxxx_driver.cpp]

I referred the following link Sonar-scanner with C/C++ family fails after upgrade to 9.3.0 from 9.2.2 which is a similar issue, I am facing right now. However the solution proposed in the above issue didn’t work for me, despite setting the INCLUDE environment variable.

Hence please let me know who do I proceed on this issue.

Hello, @vishal, and welcome to the community! :smiley:

I think the part about not having the typical compiler installation path applies to your case. However, it is worth noting that we only fall back to deducing the "INCLUDE" env variable when it is not visible in the wrapped build (which should be the usual case). So I would start by understanding why the INCLUDE environment variable is missing in your build. Do you also use the -I CLI switch to provide the include directories to cl.exe?

You also mentioned that you tried setting the INCLUDE environment, but you are still getting the same message. Could you please share the exact sequence commands you used to set the environment variable, run the wrapped build, then the scanner (and their output)?

In summary, could you please share how exactly you are starting your wrapped build? And in which environment do you invoke your build system? Also, the output from build-wrapper (the logs and the JSON dump), in addition to the sonar-scanner output might be valuable for us to analyze the problem. If you can’t share the files in public, let me know so I can provide you with means to share them privately…

Hi Michael,

Thanks for the reply. Please find the steps we are following to run the sonar-scanner analysis.

Environment:
We use Cygwin session for the Windows builds. As part of the build we have our batch script which would trigger the local builds. Regarding the usage of -I, I confirm we use /I to provide the include directories to cl.exe. Do you mean including -I could be the issue for INCLUDE environment variable missing in the build???

Following are the sequence of steps I have followed before I trigger the scanner.

  1. Added environment variable INCLUDE=c:\ (as suggested in one of the links which resolved include variable issue) in both user and system sessions of the environment variables
  2. Ran the build-wrapper-win-x86-64.exe --out-dir build_wrapper_output_directory build_ui.bat
  3. sonar-scanner

attaching the build-wrapper log for your reference
build-wrapper.log (186.9 KB)

Error faced during the sonar-scanner:

INFO: Using 12 threads for analysis.
INFO: Found empty cache on server
INFO: Trying to deduce “INCLUDE” environment variable from C:\buildtools\vcc16.0\bin\Hostx64\x64\cl.exe
ERROR: Could not find Visual Studio install from: C:\buildtools\vcc16.0\bin\Hostx64\x64\cl.exe
ERROR: The “INCLUDE” environment variable was not found, make sure that you are running the analysis from the right environment. Skip analysis of files: [C:/views/view-1/su
perfiery/repos/vobs/magnolia/network/oem/ricoh/transport_lib/src/transport.c]
INFO: Trying to deduce “INCLUDE” environment variable from C:\buildtools\vcc16.0\bin\Hostx64\x64\cl.exe
ERROR: Could not find Visual Studio install from: C:\buildtools\vcc16.0\bin\Hostx64\x64\cl.exe
ERROR: The “INCLUDE” environment variable was not found, make sure that you are running the analysis from the right environment. Skip analysis of files: [C:/views/view-1/su
perfiery/repos/vobs/magnolia/network/oem/ricoh/transport_lib/src/discovery.c]
INFO: Trying to deduce “INCLUDE” environment variable from C:\buildtools\vcc16.0\bin\Hostx64\x64\cl.exe
ERROR: Could not find Visual Studio install from: C:\buildtools\vcc16.0\bin\Hostx64\x64\cl.exe
ERROR: The “INCLUDE” environment variable was not found, make sure that you are running the analysis from the right environment. Skip analysis of files: [C:/views/view-1/su
perfiery/repos/vobs/fiery/vw/mvid/ricoh/recsa/src/core_video/src/aegis_timer.cpp]
INFO: Trying to deduce “INCLUDE” environment variable from C:\buildtools\vcc16.0\bin\Hostx64\x64\cl.exe
ERROR: Could not find Visual Studio install from: C:\buildtools\vcc16.0\bin\Hostx64\x64\cl.exe
ERROR: The “INCLUDE” environment variable was not found, make sure that you are running the analysis from the right environment. Skip analysis of files: [C:/views/view-1/su
perfiery/repos/vobs/fiery/vw/mvid/ricoh/recsa/src/core_video/src/aegis_extenv.cpp]

Please let me know if any further details to move forward on this issue

Hi @vishal, and thanks for your response! :smiley:

I think that the missing INCLUDE variable is a separate issue. I was asking because I want to make sure that the correct include dirs are accessible to the compiler without the INCLUDE environment variable because otherwise, it wouldn’t be safe to provide something like INCLUDE=c:\ to silence the error. Anyway, I could see that the -I CLI switches in the logs you shared, so this doesn’t look like a problem to me now.

It seems to me that the INCLUDE env variable is indeed not intercepted by build-wrapper. Could you please double-check that the env variable is visible inside your Cygwin session (where you are running your wrapped build)? For example, by examining the output of any of the commands: set | findstr INCLUDE or echo $INCLUDE?

If it doesn’t show up in the output, I would try to add the env variable in the Cygwin session before the wrapped build using something like:

export INCLUDE=C:\\

Hope this helps…

Yes env variable INCLUDE is visible in Cygwin session where the build wrapper is triggered. Please find the output of the of the session.

$ set | findstr INCLUDE
INCLUDE='C:'

Not sure what is the issue. Can you please suggest any workaround to proceed further on this issue.

Hi @vishal, I am afraid I need more details to understand your environment and track down the problem. I am trying to summarize below what I know about your situation, please correct me if I am off at any point:

  1. The INCLUDE environment variable is available in your Cygwin session before invoking build-wrapper, and you have verified this already by running set | findstr INCLUDE.
  2. Your build-wrapper command wraps a batch script that invokes cl.exe at some point. However, the INCLUDE environment variable is not seen by build-wrapper at this point (At least I couldn’t see it in the logs you shared. It would be nice if you could share your build-wrapper-dump.json file as well so that we can double-check this. Again, let me know if you would prefer to share it in private).

build-wrapper should be able to capture all environment variables that are passed at the time cl.exe was invoked. You can check that yourself by examining the logs in the output directory from a command like this in your Cygwin session, you should be able to find your INCLUDE env var in the logs in the following simple case:

./build-wrapper-win-x86-64 --out-dir dummy_bw_out cmd /C cl.exe

With that in mind, the only possible explanation I could think of is that you might have something in your build_ui.bat that manipulates the environment variables prior to invoking cl.exe. It would be nice if you could instrument your batch file, and inspect the output of set | findstr INCLUDE throughout the execution of the script. Most importantly, at the point before cl.exe is invoked. Can you still see the expected value of your INCLUDE environment variable before cl.exe is invoked in your batch script?

Hope this helps.

Hi Michael,

Thanks for your support. The INCLUDE environment issue is resolved now, after making the changes to our batch script to include the same. Right now the analysis is working fine.

Thank you.
Vishal

1 Like

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