Main Content

Select Files for Polyspace Analysis Using Pattern Matching

When you run static analysis using Polyspace® products, the analysis covers all files specified in your Polyspace project (or specified using -sources at the command line). Sometimes, you might want to see results only in a subset of these files, or might want a different analysis behavior to apply to a subset of files. You can specify a subset of files using file selection patterns. The file selection patterns (glob patterns) use wildcards such as ? or * to cover multiple files.

When to Specify File Selection Patterns

You can select a subset of files when creating a Polyspace project or options file from your build command, or when running static analysis using Polyspace Bug Finder™.

Select Files When Setting Up Polyspace Analysis from Build Command

When you create projects by using polyspace-configure, you can include or exclude source files whose paths match the pattern that you pass to the options -include-sources or -exclude-sources. You can specify these two options multiple times and combine them at the command line.

This folder structure applies to these examples.

Example folder structure used for the following examples.

To try these examples, use the demo files in polyspaceroot\polyspace\examples\doc_cxx\sources-select. polyspaceroot is the Polyspace installation folder.

Run this command:

polyspace-configure -allow-overwrite -include-sources "glob_pattern" \
-print-excluded-sources -print-included-sources make -B 
glob_pattern is the glob pattern that you use to match the paths of the files you want to include or exclude from your project. To ensure the shell does not expand the glob patterns you pass to polyspace-configure, enclose them in double quotes.

Select Files When Running Bug Finder Analysis

When analyzing C/C++ code with Polyspace Bug Finder, you can define file sets in your project that need specific treatment during analysis. For instance, you might want to skip the definitions of function bodies in third-party libraries or force analysis of all functions in files that you own. You can enumerate file sets with specific behaviors in a classification XML file and fine-tune the Bug Finder analysis using this classification file.

In the classification XML file, you can specify file patterns inside a file-pattern element (child of fileset > files-in-set or fileset > files-not-in-set element). For instance, the following patterns select .hpp files in subfolders of myproject/inc but excludes files ending with -generated.

<fileset name="Application implementation and header files">
      <files-in-set>
           <file-pattern>myproject/inc/**/*.hpp</file-pattern>
      </files-in-set>
      <files-not-in-set>
           <file-pattern>myproject/inc/**/*-generated.hpp</file-pattern>
      </files-not-in-set>
      <behaviors>
            <!-- Specific behaviors for this file set -->
     </behaviors>
</fileset>

To specify a classification file during static analysis, use the analysis option -classification. For instance, you can run Bug Finder using this command:

polyspace-bug-finder -options-file myOptions.txt -classification myClassification.xml
For more information, see:

Supported Patterns for File Selection

In the table, the examples assume that sources is a top-level folder.

Glob Pattern SyntaxExample

No special characters, slashes ('/'), or backslashes ('\').

Pattern matches corresponding files, but not folders.

-include-sources "main.c" matches:

/sources/app/main.c

Pattern contains '*' or '?' special characters.

'*' matches zero or more characters in file or folder name.

'?' matches one character in file or folder name.

The matches do not include path separators.

-include-sources "b?.c" matches:

/sources/lib/b/b1.c

/sources/lib/b/b2.c

-include-sources "app/*.c" matches:

/sources/app/main.c

Pattern starts with:

  • A slash '/' (UNIX®).

  • Drive letter, for example C:\ (Windows®).

Pattern matches absolute path only.

-include-sources "/a" does not match anything.

-include-sources "/sources/app" matches:

/sources/app/main.c

Pattern ends with:

  • A slash (UNIX).

  • A backslash (Windows).

  • A double asterisk ('**')

Pattern matches all files under specified folder.

'**' is ignored if it is at the start of the pattern.

-include-sources "a/" matches

/sources/lib/a/a1.c

/sources/lib/a/a2.c

Pattern contains:

  • '/**/' (UNIX).

  • '\**\' (Windows).

Pattern matches zero or more folders in the specified path.

-include-sources "lib/**/?1.c" matches:

/sources/lib/a/a1.c

/sources/lib/b/b1.c

Pattern starts with '.' or '..'.

Pattern matches paths relative to the path where you run the command.

If you start polyspace-configure from /sources/lib/a,

-include-sources "../lib/**/b?.c" matches:

/sources/lib/b/b1.c

/sources/lib/b/b2.c

Pattern is a UNC path on Windows.

If your files are on server myServer:

\\myServer\sources\lib\b\** matches:

\\myServer\sources\lib\b\b1.c

\\myServer\sources\lib\b\b2.c

polyspace-configure does not support these glob patterns:

  • Absolute paths relative to the current drive on Windows.

    For instance, \foo\bar.

  • Relative paths to the current folder.

    For instance, C:foo\bar.

  • Extended length paths in Windows.

    For instance, \\?\foo.

  • Paths that contain '.' or '..' except at the start of the pattern.

    For instance, /foo/bar/../a?.c.

  • The '*' character by itself.

See Also

|

Related Topics