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 |
This page describes how to extend your CodeSonar-facing build so that your CodeSonar project includes:
This page describes how to extend your CodeSonar-facing build so that your CodeSonar project includes:
Incorporating Go components follows the standard process for including a tier 3 component. The specializations to that process are summarized in the following table. For detailed instructions, see Including Go Components In Your CodeSonar project, below. We also provide an example Makefile.
| Language Tools | You will need a Go installation. |
|---|---|
| Third-Party Analyzer | Go Staticcheck |
| Third-Party Analysis Step | You do not need to explicitly invoke Staticcheck: it is invoked in the codesonar go_scan.py subcommand. |
| Extend CodeSonar-facing Build | Invoke codesonar go_scan.py on your Go module. This will analyze the corresponding source files with Staticcheck, then add the Staticcheck SARIF results and the source files to the CodeSonar project. |
Incorporating Go components follows the standard process for including a tier 3 component.
If you have not already set up a CodeSonar-facing build for your regular software project, you will need to create one.
The following diagram illustrates the extended software build described above, and its interactions with the CodeSonar build/analysis.
In this section (and throughout this manual), $CSONAR indicates the CodeSonar installation directory.
When a SARIF file is imported into a CodeSonar project, the SARIF importer determines an associated warning class for each rule object in the SARIF rules, creating this warning class if it does not already exist.
The SARIF importer has special handling for warning classes derived from SARIF produced by Staticcheck. For more information, see Warning Classes Corresponding to Staticcheck Rules.
To analyze Go source files with Staticcheck and then add the source files and analysis results to a project, CodeSonar observes the execution of a command that incorporates one or more invocations of codesonar go_scan.py.
where:
| go_pkg_or_file1 [go_pkg_or_file2 ...] |
Each go_pkg_or_filei
specifies a package (directory name) or Go source file,
relative to the Go module specified with -C/-directory.
|
|---|---|
| [-C moddir] [-directory moddir] |
The Go module directory: that is, the directory containing the
go.mod file.
Staticcheck will be run in moddir. If -C/-directory is not specified, Staticcheck will be run in the current working directory. Any go_pkg_or_filei arguments are interpreted relative to moddir. For example:
|
| [-include-sources
file_pat] [-exclude-sources file_pat] |
All Go source files (.go)
indicated by the -C/-directory and go_pkg_or_filei
argument combination will be analyzed with Staticcheck. By default, this set of Go source files is then imported into the CodeSonar project. Use -include-sources and -exclude-sources to adjust the imported set by adding or removing files. file_pat is a recursive glob pattern representing a source file path. It matches all files whose file path matches file_pat. When a single codesonar go_scan.py invocation contains a combination of -include-sources and -exclude-sources options, the set of imported files is determined by applying the corresponding inclusions and exclusions in the order in which they appear on the command line. Note:
|
| [-staticcheck staticcheck_path] | Specifies the path to your staticcheck executable. If -staticcheck staticcheck_path is not specified, CodeSonar will try to find staticcheck in your PATH. If it is unsuccessful, codesonar go_scan.py will fail. |
| [-X+sc_options_list] |
The +-separated
list of options and values in sc_options_list are passed
to the Staticcheck invocation.
codesonar go_scan.py -X+-go+1.0+-tests=false [...
remaining go_scan.py options]
codesonar go_scan.py -X+-go+1.0 -X+-tests=false [...
remaining go_scan.py options]
|
| [-sarif-output sarif_fname] |
Specifies that the SARIF output from Staticcheck should be
written to file sarif_fname. The primary use case for this option is in projects for which you wish to retain the SARIF results after the CodeSonar build/analysis has finished. If -sarif-output sarif_fname is not specified, codesonar go_scan.py will use a temporary file for the SARIF output. |
| [-source-max-bytes num] | Specifies a maximum size of num bytes for imported Go
source files: files larger than this maximum size will be ignored
by the importer. If -source-max-bytes is not specified, the importer will ignore files larger than 500KB. |
| [@infile] |
infile is a text file
containing a list of build option entries to be added to the
codesonar go_scan.py
command line.
|
The codesonar go_scan.py subcommand imports Go source files into the CodeSonar project using the same mechanism as codesonar import_sarif.py, because CodeSonar does not have a full front end for Go.
There are several consequences when files are directly imported with codesonar import_sarif.py.
An example Makefile for a Go project is shown below. We also provide an example Makefile for a mixed-language project that has a Go component: see Including Tier 3 Components in a CodeSonar Project: Example Makefile
GOMODULE=$(SRCDIR)/go_component .PHONY: all clean csonar_facing all: GoComponent GoComponent: $(GOMODULE)/go_component.go $(GOMODULE)/go.mod cd "$(GOMODULE)" && go build -o ../GoComponent # Invoke codesonar go_scan.py to analyze our Go source file with Staticcheck, # then import the SARIF results and the source file into the CodeSonar project. csonar_facing: $(GOMODULE)/go_component.go "$(CSONAR)"/codesonar/bin/codesonar go_scan.py go_component.go -C "$(GOMODULE)" clean: rm GoComponent
We have provided a minimal sample project so you can experiment with the example Makefile.
SRCDIR=.
SRCDIR=.
CSONAR=path/to/your/codesonar/installation
# on Windows, typically CSONAR=C:\\Program Files\\CodeSecure\\CodeSonar
If you are interested, you can try building other targets in the example Makefile.
To report problems with this documentation, please visit https://support.codesecure.com/.