Cannot run Fortify with multi CPU for a C++ project - c++

I have a C++ project setup with CMake, running on Mac. Recently I am looking into adding Fortify to do auto code analyzation. I am using Fortify version 22.1.
After set up the CMake and shell scripts, I found that if I compile with more than one CPU (using -j), the compiler (c++ or g++) will have issues generating the libs. Sometimes it will pass and successfully generate the Fortify output, but others it will just error out. Multi CPUs compile fine for this project without running Fortify.
I also see this error when I compile with Fortify (no matter it success or not):
[error]: Translator execution failed. Please consult the Troubleshooting section of the User Manual.
Translator returned status 1:
error: unable to handle compilation, expected exactly one compiler job in ''
This error always happens after a "Linking CXX xxxxx xxxx". I can't find any documentation about them.
Does anyone know how to solve this? Thank you.
Update more details about my setup:
I use shell files to wrap the sourceanalyzer like this:
#!/bin/bash
exec sourceanalyzer -b MyApp /Library/Developer/CommandLineTools/usr/bin/c++ "$#"
And my CMake setup like this:
if (${ENABLE_FORTIFY} EQUAL 1)
set(CMAKE_CC_COMPILER ${AVSxAppDALDefaultImplementation_SOURCE_DIR}/scripts/fortify-build-cc.sh)
set(CMAKE_CXX_COMPILER ${AVSxAppDALDefaultImplementation_SOURCE_DIR}/scripts/fortify-build-cxx.sh)
endif()
My shell script to run CMake and then to the scan:
cmake $PACKAGEPATH \
...
-DENABLE_FORTIFY="${ENABLE_FORTIFY}"
echo "---BUILDING---"
make release
if [[ $ENABLE_FORTIFY == 1 ]]; then
echo "---RUNNING FORTIFY SCAN---"
sourceanalyzer -b ${CURRENT_PROJECT_NAME} -scan -f fortify_scan_result_${CURRENT_PROJECT_NAME}.txt
fi

Related

Gradle and Cmake failing to find cpp file that is definitely there

I run gradle to build an android .aar and it reports that it can't find a file, but the file definitely is there.
$ ./gradlew.bat assembleRelease
> Task :webrtc-native:externalNativeBuildRelease FAILED
Build mrwebrtc arm64-v8a
ninja: error: 'C:/Developer/Microsoft-MRWebRTC/libs/mrwebrtc/src/interop/data_channel_interop.cpp', needed by 'CMakeFiles/mrwebrtc.dir/C_/Developer/Microsoft-MRWebRTC/libs/mrwebrtc/src/interop/data_channel_interop.cpp.o', missing and no known rule to make it
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':webrtc-native:externalNativeBuildRelease'.
> Build command failed.
Error while executing process C:\Users\User\AppData\Local\Android\Sdk\cmake\3.10.2.4988404\bin\cmake.exe with arguments {--build C:\Developer\Microsoft-MRWebRTC\tools\build\android\webrtc-native\.externalNativeBuild\cmake\release\arm64-v8a --target mrwebrtc}
ninja: error: 'C:/Developer/Microsoft-MRWebRTC/libs/mrwebrtc/src/interop/data_channel_interop.cpp', needed by 'CMakeFiles/mrwebrtc.dir/C_/Developer/Microsoft-MRWebRTC/libs/mrwebrtc/src/interop/data_channel_interop.cpp.o', missing and no known rule to make it
But the file C:/Developer/Microsoft-MRWebRTC/libs/mrwebrtc/src/interop/data_channel_interop.cpp is definitely there.
$ cd C:/Developer/Microsoft-MRWebRTC/libs/mrwebrtc/src/interop/
User MSYS /c/Developer/Microsoft-MRWebRTC/libs/mrwebrtc/src/interop (master)
$ ls
data_channel_interop.cpp global_factory.cpp interop_api.cpp local_video_track_interop.cpp remote_audio_track_interop.cpp transceiver_interop.cpp
external_video_track_source_interop.cpp global_factory.h local_audio_track_interop.cpp peer_connection_interop.cpp remote_video_track_interop.cpp
Could anyone help? I am kind of running out of ideas on this.
I discovered it was because I had 'caseSensitive' flags enabled on some of my directories. Be careful, this is a new feature of WSL2 and there are some peculiarities where you may be enabled in without realizing. Windows cmake cannot traverse directories that have this flag enabled on them.
Read about it here:
https://devblogs.microsoft.com/commandline/per-directory-case-sensitivity-and-wsl/

*** internal error: unable to open jobserver semaphore '3,4': (Error 2: The system cannot find the file specified. ). Stop

I am trying to compile an existing qt application's code using mingw compiler.
During compilation I am getting an error "*** internal error: unable to open jobserver semaphore '3,4': (Error 2: The system cannot find the file specified. ). Stop".
My current project is a makefile based project. Here I have one make file (parent.mk) that compiles all primary modules and then
parent.mk
compilation steps
.
.
.
make $QT_CODE_DIR
Here in this QT code directory I have another makefile (child.mk) which has following content:
child.mk
cd "qtcode_compilation_out_dir"
qmake.exe "product.pro" -r -spec win32-g++
CONFIG+=release
mingw32-make -w
If I try to run the make command manually for QT code then it works fine.
#Alexander: Thanks for the suggestion.
Please suggest if anyone has any idea about it.
Thanks.
Finally, I found out the exact reason of the problem and solution as well.
Reason for failure:
The compilation command that I am using is "make" which is been aliased to "make -j2"and along with "mingw32-make -w" it was producing the error because mingw32-make is an obsolete make command and it doesn't support multi threaded compilation.
Solution:
I just replaced the mingw32-make with make.

Bazel build verbose compiler commands logging

How can I increase the verbosity of the build process?
Bazel seems to print compiler commands only if something goes wrong during the build.
I would like to see which compiler comands the cc_library rule fires, even if everything seems to be fine, to debug linking problems.
I already tried various bazel command line parameters but nothing gives me the compiler commands :(
This is probably what you are looking for:
bazel build --subcommands //my:target
The --subcommands option causes Bazel's execution phase to print the full command line for each command prior to executing it.
Useful information taken from Envoy's bazel readme (https://github.com/envoyproxy/envoy/blob/master/bazel/README.md)
When trying to understand what Bazel is doing, the -s and --explain options are useful. To have Bazel provide verbose output on which commands it is executing:
bazel build -s //source/...
To have Bazel emit to a text file the rationale for rebuilding a target:
bazel build --explain=file.txt //source/...
To get more verbose explanations:
bazel build --explain=file.txt --verbose_explanations //source/...
Maybe you can generate the compile_commands.json file. I have created Shell scripts (under Linux) to automate that: https://github.com/vincent-picaud/Bazel_and_CompileCommands.
You might also find the following useful in addition to the accepted answer of using --subcommands (-s):
bazel build --subcommands --verbose_failures //my:target
The --verbose_failures option causes Bazel's execution phase to print the full command line for commands that failed.
Although it would seem the --subcommands option supercedes it given it is documented to display prior to command execution, I have found cases (with bazel 5.2.0) where for a failing command, --subcommands alone shows only a portion of the command along with <remaining N arguments skipped>. Using both --subcommands and --verbose_failures displays the full command line in these cases.

InstallShield creates MSI even though build has errors

When I'm compiling ism project to create MSI, its still creates the MSI even though I have build errors.
The reason I need it NOT to be created is for build verification.
Instead of checking the build log for errors, I will just check the existence of the MSI.
Does anybody know how can I achieve that?
EDIT:
I'm using ISCmdBld tool to build MSIs. This is the command line I'm running to build where the environment variables are being set before running this command:
IsCmdBld -p "%FULL_PROJECT_FILENAME%" -a %BUILDMODE% -r %PRODUCT% -o "%MMSEARCHPATH%" | tee /A "%FULL_PROJECT_LOG_FILENAME%"
If you are compiling using IsCmdBld.exe, you should add the -x option, so that the build is stopped if an error occurs.
You also can use it combined with -w, which makes each warning becomes considered as an error (and thus, each warning encountered also stops the build).
More information about IsCmdBld.exe : http://helpnet.installshield.com/installshield16helplib/ISCmdBldParam.htm
I hope this helps.
Your build automation should check the exit code from ISCmdBld.exe. If the exit code is a failure, don't archive the output.

View failures when building with xcodebuild

We are building multiple targets with xcodebuild, but from the command line, all we get is failures like so:
The following build commands failed:
CompileC MOAIFmodExChannel.o ../../src/moaiext-fmod-ex/MOAIFmodExChannel.cpp normal i386 c++ com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)
If we run the builds in Xcode, it tells me information about why the build failed. How can we view this from the command line? Is there a log file where this would get dumped or can we provide some kind of flag to xcodebuild to enable that?
xcodebuild outputs a summary at the end of the build that mentions which commands failed. That's what you quoted in your answer. The actual error message will be visible in the output at the point those commands ran. You can scroll up in the output until you find an earlier occurrence of each command (e.g., CompileC MOAIFmodExChannel.o …) to see the error messages.