JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.
If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.
If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.
| CodeSonar® 9.2p0 | CONFIDENTIAL | CodeSecure Inc |
For general information about building and analyzing CodeSonar projects, see section Building and Analyzing.
Note: The first time you build a project, you may need to accept the CodeSonar license.
Note: If User Account Control is enabled, your system may request permission for cs_uac_daemonize.exe from CodeSecure, Inc to continue. Click Continue to proceed.
Given the elements described below, the general form of the usual CodeSonar build/analysis command is:
This will build a project based on the underlying software build corresponding to command and any specified flags, and then perform the CodeSonar analysis and output the result to a hub, associating them with a CodeSonar project named proj-name (defaulting to pfiles-name if -project is not specified).
To accumulate project components without finalizing the project or running the analysis, use build instead of analyze.
The CodeSonar build/analysis command has several elements.
| command |
The command that invokes your CodeSonar-facing
build. This is an extended variant of your normal software build that performs any additional steps required to inform CodeSonar of components to be included in the CodeSonar project. These additional steps depend on the language of the software to be analyzed. See the language-specific project build documentation for full details.
If you have third-party analysis results for any language to include in the project, the CodeSonar-facing build must also invoke codesonar import_sarif.py on the relevant SARIF result files. If command is missing, no building takes place and the analysis starts with the pre-existing contents of pfiles-name.prj_files (which will be a child of the project directory). If pfiles-name.prj_files is empty or missing, an error is raised. |
|||||||||||||||||||||||||||||||||||||||
| build-command |
Specifies how far the CodeSonar project build/analysis should
proceed. The options are
|
|||||||||||||||||||||||||||||||||||||||
| /path/to/pfiles-name |
Identifies the project directory, and provides a basis for
naming files and subdirectories in that directory. In the
absence of a -project proj-name argument,
also provides the project name.
|
|||||||||||||||||||||||||||||||||||||||
| [-remote analysis-launchd] |
Specifies that the CodeSonar analysis should be managed
remotely, using analysis
launch daemon analysis-launchd. The argument
analysis-launchd is interpreted as follows.
At least one launch daemon matching analysis-launchd must already be running. If multiple launch daemons matching analysis-launchd are running, the hub will select one of them to be the analysis launch daemon. This option takes precedence over the REMOTE_ANALYSIS_LAUNCHD configuration parameter. Recommended usage:
For a step-by-step example, see Task: Set Up and Perform a Remote-Managed Analysis. This option does not affect the CodeSonar build phase, which will always take place locally.
|
|||||||||||||||||||||||||||||||||||||||
| [-remote-archive archive-launchd] |
Specifies that when the CodeSonar analysis transitions to
daemon mode, archive-launchd should become the analysis
launch daemon.
This option takes precedence over the REMOTE_DAEMON_LAUNCHD configuration parameter. Recommended usage:
The main -remote-archive use case is for running the CodeSonar analysis within a continuous integration (CI) tool or containerized environment. In these contexts, the analysis directory may be deleted as part of standard cleanup once the build pipeline (or similar) finishes. Moving the analysis directory to a remote location when daemon mode commences ensures that analysis information remains available to the hub. This option does not affect the CodeSonar build phase, which will always take place locally. It also does not affect the analysis phase, which is controlled by the -remote option.
|
|||||||||||||||||||||||||||||||||||||||
| [-project [/[ancestors/]]proj-name] |
Specifies the project with which
this analysis is associated on the hub.
If -project proj-name is not specified, the analysis will be associated with the project whose name matches the pfiles-name specified in the first argument to the analyze (or build) subcommand. If you specify both -project and -offline, the build/analysis will exit with an error. For more information, see the entry for -offline. See Hub Project Identification: Examples below for annotated example command lines with and without -project. CodeSonar creates infrastructure for a new analysis on the hub when you start accumulating analysis files in /path/to/pfiles-name.prj_files/, and continues to associate with the same analysis until the accumulated components have been collected into /path/to/pfiles-name.prj and analyzed. In particular, this means that if you are accumulating components with one or more codesonar build commands before issuing a final codesonar analyze command, all these commands will be associated with the same analysis, and that analysis will be associated with the project specified (including by default) in the first of the build commands: -project arguments in subsequent build or analysis commands will have no effect. |
|||||||||||||||||||||||||||||||||||||||
| [-no-services] |
[Windows only] Use this if you don't want to run the
CodeSonar launch
daemon as a Windows service.
Running with services is the default and is recommended unless services cause problems for the user. For more information, see section CodeSonar as a Windows Service. Specifying USE_SERVICES=No in the project configuration file provides equivalent functionality. If -remote analysis-launchd is specified, this option has no effect. If you specify both -no-services and -offline, the build/analysis will exit with an error. For more information, see the entry for -offline. |
|||||||||||||||||||||||||||||||||||||||
| [-foreground] |
When this is specified, the CodeSonar build/analysis will run
in the foreground (otherwise it runs in the background). This
can be useful if, for example, you are developing a CodeSonar plug-in
and want to run from inside a debugger.
Specifying FOREGROUND=Yes in the project configuration file provides equivalent functionality. When you specify this option, the analysis log is written to stdout. It is not recorded to the corresponding hub Analysis Log page. The CodeSonar analysis will not implicitly start a launch daemon on behalf of a foreground analysis. For more information, see Letting codesonar analyze Start a Launch Daemon Implicitly. Offline build/analysis always runs in the foreground, even if -foreground is not specified. See also -wait. |
|||||||||||||||||||||||||||||||||||||||
| [-wait] |
When this is specified, the codesonar analyze process will
wait to return until one of the following occurs.
See also -foreground.
If you specify both -wait and -offline, the build/analysis will exit with an error. For more information, see the entry for -offline. |
|||||||||||||||||||||||||||||||||||||||
| [-clean] |
When this is specified, all the CodeSonar internal
representations for the project will be deleted from
pfiles-name.prj_files
before the build/analysis runs. A new set of internal
representations will then be constructed, as specified by the
remainder of the build/analysis command. The analysis will
therefore be a base
analysis.
In general, -clean will be used in combination with a full rebuild of the software: the observed command should be chosen accordingly. If you are accumulating project components with a series of codesonar build commands, only specify -clean for the first one. The deleted information includes any accumulated offline information. If you have offline information that you do not wish to discard, submit it with codesonar submit-results or make a copy of the analysis directory before running a command that specifies -clean. |
|||||||||||||||||||||||||||||||||||||||
| [-clean-backend] |
When this is specified, analysis results and the internal
representation for the finalized CodeSonar project—but not
internal representations accumulated from the individual
compilation unit or units in the analysis—will be deleted from
pfiles-name.prj_files
before the build/analysis runs. The analysis will therefore be
a base
analysis that incorporates the internal representation that
remains in pfiles-name.prj_files along with
any internal representations constructed as specified by the
remainder of the build/analysis command.
It may be useful to think of -clean-backend as specifying that any codesonar analyze commands for which any results and output are still present in pfiles-name.prj_files should retroactively be treated as if they were codesonar build commands instead. If you are accumulating project components with a series of codesonar build commands, only specify -clean-backend for the first one. The only known use case for -clean-backend is plug-in development. Use -clean for all other situations where you want to perform a base analysis in an analysis directory previously used for incremental analysis. The -clean option subsumes -clean-backend. |
|||||||||||||||||||||||||||||||||||||||
| [-force-base-hub-analysis] |
If INCREMENTAL_BUILD=Yes, the build/analysis
will be performed as
usual for INCREMENTAL_BUILD=Yes, but will be
reported to the hub as a new base analysis in all
cases. If INCREMENTAL_BUILD=No, this option has no effect. This option is useful if you have an analysis directory for a parent analysis, but no longer have access to the hub on which the parent was analyzed. Note that if the build/analysis is incremental, only artifacts (warnings, metrics, files, and so forth) from the incremental portions of the project will be included in the analysis results. There is every possibility that these artifacts will represent a strict subset of those for the parent analysis. One consequence is that some links in the results for this analysis may be broken. The only known use case for -force-base-hub-analysis is plug-in development. Use -clean for all other situations where you want to perform a base analysis in an analysis directory previously used for incremental analysis. You can specify -force-base-hub-analysis for an offline build/analysis command: when the accumulated offline information is subsequently submitted to the hub it will be associated with a new base analysis. |
|||||||||||||||||||||||||||||||||||||||
| [-name analysis-name] |
The analysis
name will be set to analysis-name. Enclose
multiple-word names in quote marks "". If you specify -name multiple times, the last
name specified is used. The CodeSonar
web GUI also provides functionality for changing the analysis name
later.
This option takes precedence over the ANALYSIS_NAME configuration file parameter. If you specify both -name and -offline, the build/analysis will exit with an error. For more information, see the entry for -offline. |
|||||||||||||||||||||||||||||||||||||||
| [-preset preset-name] |
The configuration
preset named preset-name will be applied to the
CodeSonar build/analysis.
You can specify -preset preset-name multiple times in order to apply multiple presets. The presets will be applied in the order in which they were specified, along with any additional configuration files specified with -conf-file. Configuration Files: Changing Parameter Settings discusses the issues to consider when you change parameter settings for a given project, including changes in preset files or in the set of presets applied. In particular, if you are performing a build/analysis in multiple stages (that is, one or more invocations of codesonar build followed by an invocation of codesonar analyze) and using -preset to apply any of the presets shipped with CodeSonar, specify the same set of presets in the same order for each stage. |
|||||||||||||||||||||||||||||||||||||||
| [-no-default-presets] |
Specify -no-default-presets to
run the build or analysis without invoking default
configuration presets. Note: This flag can be used to
ensure that two CodeSonar installations do not behave
differently due to default presets.
Configuration Files: Changing Parameter Settings discusses the issues to consider when you change parameter settings for a given project, including changes in default preset files or in the set of default presets. In particular, if you are performing a build/analysis in multiple stages (that is, one or more invocations of codesonar build followed by an invocation of codesonar analyze) and your default presets directory contains only presets shipped with CodeSonar, specify -no-default-presets either for all stages or none of them. |
|||||||||||||||||||||||||||||||||||||||
| [-conf-file extra-conf-path] |
The configuration file at extra-conf-path will be applied to
the CodeSonar build/analysis as an additional
configuration file.
You can specify -conf-file extra-conf-path multiple times in order to apply multiple additional configuration files. The files will be applied in the order in which they were specified, along with any presets specified with -preset. Configuration Files: Changing Parameter Settings discusses the issues to consider when you change parameter settings for a given project, including changes in preset files or in the set of presets applied. In particular, if you are performing a build/analysis in multiple stages (that is, one or more invocations of codesonar build followed by an invocation of codesonar analyze) and using -conf-file to apply any of the presets shipped with CodeSonar, specify the same set of presets in the same order for each stage. |
|||||||||||||||||||||||||||||||||||||||
| [-launchd-group ldgroup] |
Specifies the parent launch
group to use if a new launch daemon is started
for this command. The value of ldgroup can be either an
integer or a string.
When you execute codesonar
build or codesonar
analyze, CodeSonar sets the Analysis
Launch Daemon for the analysis (unless the command is
executed with -offline or -foreground). CodeSonar will
attempt to start a new launch daemon only if the hub's
analysis
cloud register does not already contain a suitable launch
daemon.
Interactions with other options are as follows.
|
|||||||||||||||||||||||||||||||||||||||
| [-launchd-key ldkey] |
Specifies the Key to use in
determining the Analysis
Launch Daemon set by this command.
If -launchd-key is not specified, CodeSonar will use the value of configuration parameter LAUNCHD_KEY. If neither is specified, CodeSonar will ignore the Key field when selecting an existing launch daemon and set the Key field to the empty string when starting a new launch daemon. Interactions with other options are as follows.
|
|||||||||||||||||||||||||||||||||||||||
| [-srcroot path/to/basedir] |
When warning information from this analysis is exported in
SARIF format, source file paths will be expressed relative to
path/to/basedir. If this option is specified multiple times, the last value will be used. If one or more values are specified for configuration parameter SRCROOT_PATHS, path/to/basedir will be appended to the list of candidate paths. The --src-root option to codesonar dump_warnings.py takes precedence over this setting. |
|||||||||||||||||||||||||||||||||||||||
| [-offline] |
The codesonar build or
codesonar analyze
command will be performed offline.
Conflicting command line options.
When a build or analysis step is performed offline, command
line options that involve hub interaction are not applicable.
The following table lists these options and their corresponding
configuration parameters.
|
|||||||||||||||||||||||||||||||||||||||
| [-property propkey propval] |
Adds
user-assigned property propkey to the analysis, with value
propval.
|
|||||||||||||||||||||||||||||||||||||||
| [-watch-pid pid] |
[Windows Only] Specify that CodeSonar should watch the process
whose PID is pid in addition to the process tree
associated with your CodeSonar-facing build command. If the CodeSonar process does
not have PROCESS_ALL_ACCESS
access against pid, then the process will not be
watched.
When you specify this option, specify a command that will not terminate until operations you wish to observe in pid have occurred.
May be specified multiple times to watch multiple processes. |
|||||||||||||||||||||||||||||||||||||||
| [-watch-all-pids] |
[Windows Only] Specify that CodeSonar should watch all
processes on the machine for which the CodeSonar process has
PROCESS_ALL_ACCESS access.
This will include the CodeSonar-facing build command.
When you specify this option, specify a command that will not terminate until all the operations you wish to observe have occurred. See the -watch-pid documentation for some examples. |
|||||||||||||||||||||||||||||||||||||||
| [-auth authtype], [-hubuser username], [-hubpwfile pwfile], [-hubbearerfile bearerfile], [-hubcert certfile], [-hubkey privatekeyfile] |
Specify how CodeSonar should attempt to authenticate the
build/analysis command. For details, see
Hub Authentication: Authenticated codesonar Subcommands.
If you specify authentication options in a command line that also specifies -offline, the build/analysis will exit with an error. |
|||||||||||||||||||||||||||||||||||||||
| [[protocol://]host:port] |
CodeSonar will use the hub at protocol://host:port,
failing if one is not already running at that location.
If you specify a hub location in a command line that also specifies -offline, the build/analysis will exit with an error. |
The project build and analysis steps can be run separately, as in the following example. The first command instructs CodeSonar to observe the compilation gcc -c myfile.c and update the myproj project accordingly. The second command instructs CodeSonar to analyze myproj and send the results to the default hub.
The following example command lines illustrate the effects of various -project arguments.
Path for analysis files not specified, -project not specified.
| Local Files and Directories |
|
|---|---|
| Hub Project |
|
| Analysis Phase | Analysis Launch Daemon: local. |
| Daemon Mode | Analysis Launch Daemon: local. |
Path for analysis files specified, -project not specified.
| Local Files and Directories |
|
|---|---|
| Hub Project |
|
| Analysis Phase | Analysis Launch Daemon: local. |
| Daemon Mode | Analysis Launch Daemon: local. |
Path for analysis files specified, -project specifies name only.
| Local Files and Directories |
|
|---|---|
| Hub Project |
|
| Analysis Phase | Analysis Launch Daemon: local. |
| Daemon Mode | Analysis Launch Daemon: local. |
Path for analysis files specified, -project specifies name and project tree path.
| Local Files and Directories |
|
|---|---|
| Hub Project |
|
| Analysis Phase | Analysis Launch Daemon: local. |
| Daemon Mode | Analysis Launch Daemon: local. |
CodeSonar SaaS build/analysis.
| Local Files and Directories |
|
|---|---|
| Hub Project |
|
| Analysis Phase | Analysis Launch Daemon: remote. The SaaS hub will select a suitable launch daemon from its saas launchd group to manage the analysis and analysis data. |
| Daemon Mode | Analysis Launch Daemon: remote. The analysis launch daemon from the analysis phase is also used to service requests from the hub. |
Invoking the analysis from a continuous integration (CI) tool: local build/analysis, transferring data and control to a launch daemon in the /myremote launchd group when the analysis transitions to daemon mode.
| Local Files and Directories |
|
|---|---|
| Hub Project |
|
| Analysis Phase | Analysis Launch Daemon: local. |
| Daemon Mode |
Analysis
Launch Daemon: remote. The hub will select a suitable
launch daemon from the /myremote/ launchd group
to service requests from the hub. This launch daemon will
create a new project analysis
directory, with contents copied from the analysis directory
used in the analysis phase.
If no launch daemons in this group are connected to the hub, daemon mode will also be local-managed. (This can cause problems if the CI tool automatically cleans up the analysis directory.) |
Local build/analysis, with remotely-managed analysis and separate analysis launch daemons for analysis phase and daemon mode.
| Local Files and Directories |
|
|---|---|
| Hub Project |
|
| Analysis Phase | Analysis Launch Daemon: remote. The analysis and analysis data will be managed by the launch daemon whose Launch Daemon ID is 3. If no such launch daemon is connected to the hub, the command will fail. |
| Daemon Mode |
Analysis
Launch Daemon: remote. The launch daemon whose Launch Daemon ID
is 5 will service requests from the hub. This launch daemon
will create a new project analysis
directory, with contents copied from the analysis directory
used in the analysis phase.
If no such launch daemon is connected to the hub, daemon mode will be managed by the launch daemon used for the analysis phase. |
Some example CodeSonar command lines for supported languages and
combinations of languages.
For tier 3 languages, see
the examples in Including Tier 3
Components in a CodeSonar Project and the individual language
pages linked from there.
Note: Depending on the hub configuration, you may be prompted for hub user account credentials to authenticate and authorize codesonar build and codesonar analyze commands. See Hub Authentication: Authenticated codesonar Subcommands for more information.
Note that the variety of regular build systems in these examples are intended to illustrate a range of options. You can use any of these build systems, or many others, with any of these languages.
Example: a C-only software project built with make.
| Example regular build system | make |
|---|---|
| Regular build definition |
Makefile:
.PHONY: all clean
all: CComponent
CComponent: A.c
gcc -o CComponent A.c
clean:
rm CComponent
|
| Regular build command |
make all
|
| Other CodeSonar requirements | none |
| CodeSonar-facing build | No extensions to the Makefile are needed. |
| CodeSonar-facing build command |
make all
|
| CodeSonar command line |
codesonar analyze cs-myproj make all
CodeSonar recognizes
the gcc compiler invocation and updates the cs-myproj project accordingly.
|
Further example C and C++ build/analysis command lines are provided throughout this manual. Locations include Build and Analysis for C/C++ Projects: command examples and the various tutorials.
See also the multiple language example, below.
Example: a Java-only project built with make.
| Example regular build system | make |
|---|---|
| Regular build definition |
Makefile
.PHONY: all clean
all: MyJava.class
MyJava.class: MyJava.java
javac --release 18 MyJava.java
clean:
rm *.class
|
| Regular build command |
make
|
| Other CodeSonar requirements | none |
| CodeSonar-facing build |
Extend the Makefile as shown.
.PHONY: all clean
all: MyJava.class
MyJava.class: MyJava.java
javac --release 18 MyJava.java
csonar_facing: MyJava.java MyJava.class
cs-java-scan -include-artifacts MyJava.class -include-sources MyJava.java
clean:
rm *.class
|
| CodeSonar-facing build command |
make csonar_facing
This invokes cs-java-scan to
identify the Java artifact (MyJava.class) and source (MyJava.java) files. These files are
dependencies of the csonar_facing target.
|
| CodeSonar command line |
codesonar analyze cs-myproj make csonar_facing
CodeSonar recognizes the cs-java-scan invocation in the
CodeSonar-facing build and invokes the Java front end to update
the project definition.
|
For more Java build/analysis examples, see Build and Analysis for Java Projects: Example Command Lines.
See also the multiple language example , below.
Example: a C#-only software project built by invoking a batch file (.bat).
| Example regular build system | Batch file |
|---|---|
| Regular build definition |
csharpbuild.bat
csc /debug:full /define:DEBUG CsharpModule.cs |
| Regular build command |
cmd /c csharpbuild.bat
|
| Other CodeSonar requirements | none |
| CodeSonar-facing build |
Extend csharpbuild.bat as
shown.
csc /debug:full /define:DEBUG CsharpModule.cs
if not "%1"=="csonar_facing" goto end
cs-dotnet-scan -include-artifacts CsharpModule.exe -include-sources CsharpModule.cs
:end
|
| CodeSonar-facing build command |
cmd /c csharpbuild.bat csonar_facing
This performs all the steps that were in csharpbuild.bat before it was extended,
then invokes cs-dotnet-scan to
identify the C# artifact (CsharpModule.exe) and source (CsharpModule.cs) files.
|
| CodeSonar command line |
codesonar analyze cs-myproj cmd /c csharpbuild.bat
csonar_facing
CodeSonar recognizes the cs-dotnet-scan invocation in the
CodeSonar-facing build and invokes the C# front end to update
the project definition.
|
See the example and discussion in codesonar cs_android.py : Prepare and Analyze the Android Open Source Project.
Example: a multiple-language project built by invoking a shell
script (.sh).
Note that available languages will depend on your license.
| Example regular build system | Shell script |
|---|---|
| Regular build definition |
multibuild.sh
# /bin/sh
gcc -c A.c
javac --release 18 B.java
|
| Regular build command |
sh multibuild.sh
(or ./multibuild.sh) |
| Other CodeSonar requirements | none |
| CodeSonar-facing build |
Extend multibuild.sh as shown.
# /bin/sh
gcc -c A.c
javac --release 18 B.java
if [ $# -gt 0 ]; then
if [ $1 == "csonar_facing" ]; then
cs-java-scan -include-artifacts B.class -include-sources B.java
fi
fi
|
| CodeSonar-facing build command |
sh multibuild.sh csonar_facing
This performs all the steps that were in multibuild.sh before it was extended, then
invokes cs-java-scan to
identify the Java artifacts and source files.
|
| CodeSonar command line |
codesonar analyze cs-myproj sh multibuild.sh csonar_facing
CodeSonar recognizes the various commands (gcc, cs-java-scan, ...) in the CodeSonar-facing
build and invokes the corresponding language front ends to
update the project definition.
|
The different components have different sets of available warning classes (and classes can be enabled and disabled within those sets).
See the example Makefile and discussion in Including Go Components in a CodeSonar Project
See the example Makefile and discussion in Including JavaScript and TypeScript Components in a CodeSonar Project
Using codesonar kotlin_scan.py (will report warnings from the Kotlin warning classes corresponding to detekt rules) : see the example Makefile and discussion in Including Kotlin Components in a CodeSonar Project
Using cs-java-scan (will report warnings from the Java warning classes): see Build and Analysis for Java Projects: Example Command Lines
See the example Makefile and discussion in Including Python Components in a CodeSonar Project
See the example Makefile and discussion in Including Rust Components in a CodeSonar Project
To report problems with this documentation, please visit https://support.codesecure.com/.