how to exclude third party lib / dll from getting analyzed in CLANG scan-build xcodebuild? - clang

I have used some open-source code and third party libs in my project and want to exclude that code from getting analyzed while analyzing my project using scan-build file.
I know we can #ifndef clang_analyzer use this macro to suppress the code from getting analysed, but I dont want to copy paste this in all the files.
OR
Is there any way so that the report which get generated after analysis using scan-build command, not to show the warnings/error generated from some set of files?
thanks in advance.

Use --exclude [1] [2] option (available since 2018)
--exclude
Do not run static analyzer against files found in this directory
(You can specify this option multiple times). Could be useful when
project contains 3rd party libraries.
Same is applicable for Python implementation of scan-build ($ pip install scan-build) - https://github.com/rizsotto/scan-build

Related

Bazel C++ code coverage with a custom coverage tool (Squish Coco)

I couldn't find anything in the official documentation on this. We're using Squish Coco for code coverage and can't use lcov for certification reasons, which is the only tool supported by bazel coverage.
We're trying to get this running in Bazel. For this we added a toolchain for the Squish Coco Wrappers. Which seems to be the standard way to add different compilers, shown here https://bazel.build/tutorials/ccp-toolchain-config.
However linking fails with undefined reference to '__cs_tb...', because Bazel deletes all the instrumentation files (*.o.csmes and *.csmes). The same toolchain for clang or gcc works, as presented in the tutorial.
Is there any way to tell Bazel to keep any files with the ending *.csmes? I'd like to declare that cc_library produces .o files and maybe ( not always, depends on instrumentation options) *.o.csmes. cc_binary amd cc_test may create no extension files and .csmes files.

Yocto SDK with cmake toolchain file

I provide a Yocto SDK to cross-build an application for an embedded target. The application itself is built using CMake. The SDK setup script provides many necessary environment variables (like location of the cross-compiler, sysroot, etc.), which so far was enough to build the application.
However, since recently the application has a dependency to the Boost library (through the command find_package(Boost REQUIRED) in the CMakeLists.txt). Now CMake complains that it cannot find the library, even though it's installed in the SDK sysroot. But if I build the application directly in Yocto, it works fine.
After some research it turned out that Yocto generates a toolchain.cmake file which is added to the cmake call. In this file, the variable CMAKE_FIND_ROOT_PATH is set, which CMake needs to find libraries. Using such a toolchain file, I can also build using the SDK.
Now I'm wondering if Yocto provides any mechanism to export such a toolchain file with the SDK. Or alternatively if the SDK provides a script or something to automatically create a toolchain file directly on the SDK build host.
Or shall I just tell the users of the SDK to manually create a toolchain file and add it to their cmake call?
Assuming that you're using the image based SDK, i.e. building it with bitbake <image> -c populate_sdk, adding the following toimage.bb should fix it:
TOOLCHAIN_HOST_TASK += "nativesdk-cmake"
That should give you a OEToolchainConfig.cmake file in the SDK. After sourcing the SDK environment file, cmake will be an alias to cmake -DCMAKE_TOOLCHAIN_FILE=$OECORE_NATIVE_SYSROOT/usr/share/cmake/OEToolchainConfig.cmake to further help your developers.
I'd like to add to Anders answer that while it worked great for me to add nativesdk-cmake this way it did not work when I tried to add nativesdk-python3-numpy. After some googling I found this, suggesting that TOOLCHAIN_HOST_TASK has to be extended using _append instead of +=.

How do I compile libffi for iOS & macOS?

I'm trying to use libffi in one of my projects, but I can't seem to compile for iOS (or macOS, for that matter). Here is one of the various errors I've encountered while building for the iOS Simulator:
bash: src/arm/gentramp.sh: No such file or directory
Update 1: Since the question remains unanswered, I've decided to open an issue at the official repository as well.
Update 2: Question has been answered and the issue has been closed!
If you check the repository you will see that the file you require was deleted in this commit. You can find the last version of this file here.
generate-darwin-source-and-headers.py and the libffi.xcodeproj need to be updated to include all currently relevant source files.
The gentramp.sh script is not needed anymore and the current upstream xcodeproj is not up to date either with compilation settings and to be included source files for 64-bit on iOS. A patched fork can be found at https://github.com/ksjogo/libffi
sh autogen.sh
python generate-darwin-source-and-headers.py --only-ios
open libffi.xcodeproj
select scheme libffi-iOS and device Generic iOS Device
click "Product - Build"
If success, you would see a "Product/libffi.a" in the side bar, you can right click it to get the lib in the finder.
Please make sure you are following the installing libffi instructions released on the TBD or git project: https://github.com/libffi/libffi
Here some of the main Highlights:
First you must configure the distribution for your particular
system. Go to the directory you wish to build libffi in and run the
"configure" program found in the root directory of the libffi source
distribution.
If you're building libffi directly from version control, configure won't
exist yet; run ./autogen.sh first.
You may want to tell configure where to install the libffi library and
header files. To do that, use the --prefix configure switch. Libffi
will install under /usr/local by default.
If you want to enable extra run-time debugging checks use the the
--enable-debug configure switch. This is useful when your program dies
mysteriously while using libffi.
Another useful configure switch is --enable-purify-safety. Using this
will add some extra code which will suppress certain warnings when you
are using Purify with libffi. Only use this switch when using
Purify, as it will slow down the library.
For iOS builds, the 'libffi.xcodeproj' Xcode project is available.
Configure has many other options. Use "configure --help" to see them all.
Once configure has finished, type "make". Note that you must be using
GNU make. You can ftp GNU make from ftp.gnu.org:/pub/gnu/make .
To ensure that libffi is working as advertised, type "make check".
This will require that you have DejaGNU installed.
To install the library and header files, type "make install".
Alternatively, try merging one of the following git projects to your project in order to include the missing files. Please make sure the files are not outdated before merging.
1 https://github.com/pandamonia/libffi-iOS
2 https://github.com/influitive/libffi-iOS
3 https://github.com/landonf/libffi-ios

Using scan-build command for clang code analysis

I have installed scan-build/clang version 2.9 on Ubuntu desktop. I build my C++ source code there using make . As it said scan-build would analyze a project which is built using make if you give
scan-build make
to
but after the make i see a message
scan-build: Removing '/tmp/scan-build-2013-10-16-1' because it contains no reports.
Also tried
scan-build --use-c++=/use/bin/clang++ make
Q1 - What am i doing wrong/missing here. How to use scan-build to analyze all source files.
Q2 - Is there any option to use clang++ --analyze myfile.cpp
to analyze single source file. But it gives an error about a header file included not found 'fatal' error' my.h
what is the option to clang analyze to point it to the folder having header files.
As for Q2, you should be able to use:
scan-build clang++ -c myfile.cpp
or what you suggested:
clang++ --analyze myfile.cpp
but you need to make sure that the compiler knows about all the includes and libraries (you should be able to successfully compile myfile.cpp to an object file without analysis). That includes especially the -I directories.
There is also the -o option to scan-build, which specifies the target directory for HTML report files. Subdirectories will be created as needed to represent separate "runs" of the analyzer. If this option is not specified, a directory is created in /tmp to store the reports, as you already know.
Another useful option would be -v (verbose), which should print any errors that the analyzer might run into.
Last but not least, you should use the analysis with debug builds where the optimization is disabled, but more importantly where the symbols are not stripped.
Not sure if it helps, let me know ...

devenv command line option for macros and lib file

I am trying to make build using devenv.exe command line and have some preprocessor definitions and lib file to be given with command line.
as such one way is to set in proj file
c/c++ ---> proprocessor --> preposessor defintions
i want to give macro name in command line with devenv.exe
similarly i have one additional linker library dependency
linker - input - additional dependencies
which i want to supply with devenv
any help will be really appreciated.
Thanks
also i need the answer to solve the same question.
i have the same project source code, but different binary version will be built out with different building macros. now i try two ways to build the project. one is described as sachinc's; another is to replace the PreprocessorDefinitions in .vcproj by python scripts.
iam also hankeringly to know how to make build using devenv.exe with command line.

Resources