5.3.5. Local Analyses

Local analyses can be run on the development machine. They can be used to analyze code changes before they are committed.

Currently, the following local analyses are supported:

5.3.5.1. Common Configuration

To run the analyses, the Axivion Suite tools must be configured.

Common preferences of local analyses.

Common preferences of local analyses.

When Axivion Eclipse Plugin starts the Axivion Suite tools, they must be able to locate this configuration. This is achieved using the environment variable BAUHAUS_CONFIG. When the tools are started, Axivion Eclipse Plugin sets this variable according to the Axivion Suite version used for the analysis. The configuration directory can be set using the option Project Configuration (BAUHAUS_CONFIG). The default value is the value of the variable BAUHAUS_CONFIG in the environment of the Eclipse process. The BAUHAUS_CONFIG defined here is not used for the Local Build; that information is contained in the start script.

Analyses use the current source code on disk; therefore, unsaved changes are not taken into account. The option Save open files before local analyses triggers Eclipse to save all open files with changes before the selected analysis starts.

Axivion Eclipse Plugin uses its own consoles within Eclipse to display the current status of local analyses, error messages, and raw analysis results: Axivion Local Build for the Local Build, Axivion Analysis for the CDT Integration, and Axivion Single-File Analysis for the Makefile Integration. By default, the console content is cleared before a CDT Integration or Makefile Integration analysis starts. This behavior can be changed using the option Clear console before analyzing.

The options Axivion Suite Installation Directory, Bauhaus Python Executable (BAUHAUS_PYTHON) (see General Configuration), and Project Configuration (BAUHAUS_CONFIG) can also be set per project. If an option is set in both the preferences and the project properties, the project property takes precedence.

Common project properties of local analyses.

Common project properties of local analyses.

5.3.5.2. CDT Integration

Axivion Eclipse Plugin allows you to start local analyses of your code from within Eclipse. It uses build information from CDT; therefore, it only works for managed make projects where CDT generates the makefile. This feature is not available for standard make projects (where CDT uses a user-generated and maintained makefile).

Note

The Axivion Eclipse Plugin CDT Integration and Local Build (Local Build) features are completely independent. Therefore, the restriction to managed make projects for CDT Integration does not apply to the Local Build.

Configuration

To run the analysis, the Axivion Suite tools must be configured. Configuration is divided into (workspace) global and project-local settings. Project-local settings override global settings where they exist.

(Workspace) Global Configuration

CDT Integration Preferences.

CDT Integration Preferences.

The preferences include the groups Single-File Analysis and Project Analysis, each with its own Pre- and Post-analysis step. These steps can be used to execute arbitrary programs before and after the Axivion Suite tools compile the code. Typically, the Post-analysis step is used to run axivion_analysis. The variables shown on the preferences page can be used in any step.

If use default command is selected, Axivion Eclipse Plugin guesses the analyzer tool (axivion_analysis or stylecheck) based on the Axivion Suite version and the provided Axivion Suite configuration.

Caution

If you use command-line tools (e.g., to check for style violations), consider setting the corresponding exclude or include parameters to reduce messages from parts of the code that you do not want to see.

Axivion Eclipse Plugin must invoke the Axivion Suite compiler and linker instead of the toolchain normally used. Therefore, a command mapping is provided to map the commands CDT would execute to the commands Axivion Eclipse Plugin executes during analysis.

Command mapping preferences.

Command mapping preferences.

In addition to the command mapping, additional parameters can be set. These are passed to the executed process alongside the parameters CDT would pass to the original command. In the command mapping, it is crucial to separate the parameters from the command.

Even when clicking Restore Defaults, changes are only saved if you click Apply or OK. Therefore, accidentally restoring the command mapping to defaults – and deleting custom command mappings – can be undone by clicking Cancel.

The configuration is stored in the text file
<workspace>/.metadata/.plugins/org.eclipse.core.runtime/.settings/
com.axivion.aclipse.plugin.prefs. To distribute command mappings (and all other workspace-global Axivion Eclipse Plugin preferences), you can simply copy this file.

(Project) Local Configuration

In addition to workspace-global settings, project-specific (project-local) settings are available. These can be accessed by right-clicking a project and selecting Properties from the context menu. The category Axivion CDT Integration displays the project-local settings.

Axivion CDT Integration settings.

Axivion CDT Integration settings.

Project-local settings are also split into the groups Single-File Analysis and Project Analysis. Their pre- and post-analysis steps allow you to control additional actions executed before or after the actual build/analysis. In addition to enabling or disabling the global Axivion pre-/post-analysis steps (defined in the preferences), you can define project-specific pre-/post-analysis steps. Within the group Project Analysis, CDT pre- and post-build steps can also be enabled or disabled. Single-file analysis does not execute CDT pre- and post-build steps.

The execution order is:

  • Axivion global pre-analysis step

  • Axivion local pre-analysis step

  • CDT build steps (pre-build step, build steps, post-build step)

  • Axivion local post-analysis step

  • Axivion global post-analysis step

Command Mapping Properties.

Command Mapping Properties.

The Command Mapping page allows for fine-tuning of the command mapping for the selected project. Mappings can be disabled to use the command that CDT would execute. In addition to disabling a command mapping, its options can be changed. Additional options defined in the global settings can be disabled, and project-specific additional options can be defined.

Using the CDT Integration of Axivion Eclipse Plugin for Analysis

In addition to using Axivion Eclipse Plugin as a dashboard viewer, it can also be used to run analyses. It detects which tools and parameters CDT would use to build the project. The analysis tools are executed based on the information obtained from CDT and the configured settings (e.g., the command mapping).

Analysis execution and result feedback can be handled via a post-analysis step. By default, axivion_analysis is executed. It may be necessary to configure the Axivion Suite installation directory (see General Configuration). The Axivion Eclipse Plugin uses the Axivion Analysis Error Parser CDT error parser to generate issue markers from the standard output and error streams of the executed process.

The use of axivion_analysis is only an example; arbitrary programs can be defined as post-analysis steps. Available command-line options are described in section Command-Line Switches.

Analyses are started from the context menu of the relevant resource. For C/C++ projects, two menu items are available:

  • Axivion CDT Integration: Analyze Project and

  • Axivion CDT Integration: Clean Project

Project analysis also builds and analyzes dependencies. The clean command simply cleans the selected project.

Project context menu with :guielement:`Axivion CDT Integration: Analyze Project` and :guielement:`Axivion CDT Integration: Clean Project`.

Project context menu with Axivion CDT Integration: Analyze Project and Axivion CDT Integration: Clean Project.

Individual files can also be analyzed using the Axivion CDT Integration: Analyze File(s) item in the context menu of C/C++ source files.

File context menu with :guielement:`Axivion CDT Integration: Analyze File(s)`.

File context menu with Axivion CDT Integration: Analyze File(s).

Markers indicating found issues are removed when the project is cleaned.

Note

The Axivion Eclipse Plugin sets the environment variable AXIVION_USER_AGENT=AxivionEclipsePlugin/<version> for every subprocess it starts.

5.3.5.3. Makefile Integration

Makefile Integration allows for quick checks of individual files and folders. It requires a customer-configured command (e.g., make with a special target) to run the build and analysis tools of the Axivion Suite.

Caution

When analyzing folders, note that MISRA system checks cannot be run on such a “module” because only a part of the system is being analyzed.

Configuration

Single-File Analysis project properties.

Single-File Analysis project properties.

The Supported File Types field is a whitelist of file types that can be analyzed. The context menu entry for analyzing single files is enabled only for files of the specified types.

The command is started in the working directory specified in Build Working Directory. Do not change this directory during analysis (e.g., in a makefile), as it is used to parse the output for marker generation.

The path of the selected file or folder is made relative to the Source Basepath before being injected into the make command (${axivion_ir_file}). The basepath must be an absolute path. For example:

  • source basepath: C:\Users\usr\project

  • selected file: C:\Users\usr\project\src\module\source.cpp

  • relative path: src\module\source.cpp

If the OS path separator (Windows: “\\”, Linux: “/”) should not be used, an alternative separator can be specified using the Separator Format option.

The Enabled checkboxes enable or disable the corresponding Makefile Integration context menu entries. All four entries are disabled by default; select the Enabled checkbox next to a command to make its context menu entry available.

The Make Command for Single File executes the build and analysis for a single file, while the Make Command for Folders executes them for folders.

In addition to analysis commands, you can define two other commands: Command for Single File and Command for Folders. These are intended as “quick links” to common tasks and are not used for analyses. They are started with the context menu entry Axivion Makefile Integration: Command.

By default, the two make commands invoke make with a special target, and the two other commands are empty; however, any command is permitted. The variable ${axivion_ir_file} resolves to the relative path of the selected file without the file extension. The variable ${axivion_src_ext} resolves to the extension of the source file without the dot; for folders, the variable ${axivion_src_ext} is always empty. For example:

  • source basepath: C:\Users\usr\project

  • selected file: C:\Users\usr\project\src\module\source.cpp

  • ${axivion_ir_file}: src\module\source

  • ${axivion_src_ext}: cpp

The intended use case for Makefile Integration is to call make with a special target that performs the build and analyses. An example target is shown below:

# Exemplary make target which builds the IR and does the analysis.
#
# Pattern rules cannot be phony, so use the trick of depending
# on a rule (FORCE) with empty recipe. As GNU Make supports
# phony targets, make FORCE phony.
# There must be no file or folder with the name "FORCE".
#
# Each invocation will build and analyze the given file.

IR_DIR = axivion_ir

.PHONY: FORCE

FORCE:

# Rules for analyzing a single C or C++ file (cafeCC call may need adjustments):
$(IR_DIR)/%.o.ir: %.c FORCE
     cafeCC -c $(CFLAGS) -o "$@" "$<"
     axivion_analysis --output - --quiet --limit_to AnalysisControl --limit_to Stylechecks --ir "$@"

$(IR_DIR)/%.o.ir: %.cpp FORCE
     cafeCC -c $(CFLAGS) -o "$@" "$<"
     axivion_analysis --output - --quiet --limit_to AnalysisControl --limit_to Stylechecks --ir "$@"

# Rule for analyzing a folder (cafeCC call may need adjustments):
$(IR_DIR)/%.ir: % FORCE
     cafeCC -shared $(CFLAGS) -o "$@" $(wildcard $</*.c) $(wildcard $</*.cpp)
     axivion_analysis --output - --quiet --limit_to AnalysisControl --limit_to Stylechecks --ir "$@"

Configuration of Source basepath, ${axivion_ir_file} (make command), and IR_DIR (Makefile):

The target of the make command must be matched by
$(IR_DIR)/%.o.ir: %.c,
$(IR_DIR)/%.o.ir: %.cpp
or
$(IR_DIR)/%.ir: %

In the simplest case, ${axivion_ir_file} is the part of the target matched by the %. Consequently, the target in the make command would be $(IR_DIR)/${axivion_ir_file}.o.ir. Since Eclipse and the Axivion Eclipse Plugin do not know the value of the variable IR_DIR, $(IR_DIR) must be replaced by its actual value in the make command.

Starting a Makefile Integration Analysis

To start the Makefile Integration analysis, open the context menu of the desired file and select Axivion Makefile Integration: Analyze. This entry is available only if the corresponding Enabled checkbox is selected in the configuration.

Makefile Integration context menu entry of a file.

Makefile Integration context menu entry of a file.

Similarly, the analysis of a folder can also be started from its context menu.

Makefile Integration context menu entry of a folder.

Makefile Integration context menu entry of a folder.

The output of the process is displayed in a console. The plugin converts the identified issues into markers.