Analyze Intermingled C/C++ & Objective-C/C++ Codebases with CodeMRI®

This document covers the steps required to analyze code-bases that contain both C/C++ and Objective-C source code with the CodeMRI® software.

If your code-base does not intermingle C/C++ Header Files with Objective-C header files than you can use the instruction provided here: https://silverthread.atlassian.net/wiki/spaces/CKB/pages/2774859777. Additionally all these instructions can also be reconfigured for Objective-C++

Understanding the Analysis Step

Unfortunately, if you’re attempting to produce metrics on a code-base that contains source files written in both Objective-C and C/C++, you’ve probably ran into issues with the header files throwing several errors. This is due to the fact that CodeMRI® and its included software assume that a header file (.h) is specifically tied to a single language. By default, our software assumes the more common case, that header files are written for C/C++ code bases.

As such, you’ll need to follow the instructions provided below to setup your code base such that CodeMRI® is capable of separating these two languages apart for analytical processing.

Split the Code-base

The first step will be to split your code-base into its respective parts. Keep in mind that while Objective-C is incompatible with processing alongside C/C++ code, you can still intermingle all other supported languages that do not also include .h files during compilation/interpretation.

To split the code-bases we recommend locating all .m and .h files using the following bash script.

#!/bin/bash # find_objc_files - Prings out the path to a file that is # considered by the system as an Objective-C Source File. for f in $(find | grep -E "\.h$|\.m$") do if [[ $(file $f) == *"Objective-C"* ]]; then echo $f fi done # EOF

You could hack this a bit more to automatically remove the files and drop them into an analogous code base structure.

With this you now have a list of the Objective-C source files that need to be moved & removed for this code-base into an analogous code-base that ONLY contains the Objective-C source code.

Create Dummy Project & System

It doesn’t matter what code-base this points to, so long as an element.udb is created that we can configure settings for. To do this, run the following command and fill in your information:

cmri shell project add -n project_name system add --selection project_name -n dummy_code -v 1 --origin /path/to/dummy_code select --add project_name/dummy_code-1 job run produce_reports

Produce Reports for Separate Code-bases

With the dummy project now created we can use its database (a required argument for Understand) to configure the system for the separate code-bases.

Analyze Objective-C Code

First use the dummy element.udb to configure your Understand configuration to analyze .h file as Objective-C code:

# Assumes your cmri installation is under /home/user/cmri # Also assumes your vault location is under /home/user/vault /home/user/cmri/understand5/scitools/bin/linux64/und settings -GeneralFileTypesAdd .h=Objective-C -db /home/user/vault/projects/project_name/systems/dummy_code-1/data/element.udb

Now perform execution against your Objective-C code:

The result should be valid reports against the Objective-C code for your code-base.

Analyze C/C++ Code

Again use the dummy element.udb to configure your understand configuration to analyze .h file as C/C++ code:

Now perform execution against your C/C++ code:

The result should be valid reports against the C/C++ code for your code-base.

Note that the last configuration of the -GeneralFileTypesAdd will persist between executions. As such if you regularly analyze C/C++ code and your last configuration was set to run against Objective-C Header files, you will get errors. Silverthread is currently working on a solution that will result in configurations being CodeMRI system independent.