Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add static code analysis recipe #155

Merged
merged 5 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.DS_Store
._*
build/
codeql-database/
codeql/
codeql-analysis.sarif
man/flog.1
20 changes: 19 additions & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ release_target := release_dir / "bin" / "flog"
man_dir := "man"
man_source := man_dir / "flog.1.md"
man_target := man_dir / "flog.1"
sarif_file := "codeql-analysis.sarif"

# generate build artifacts and run unit tests
@all: build test
Expand Down Expand Up @@ -39,7 +40,7 @@ man_target := man_dir / "flog.1"

# remove build directories and artifacts
@clean:
rm -rf "{{build_dir}}" "{{man_target}}" *.xz
rm -rf "{{build_dir}}" "{{man_target}}" "{{sarif_file}}" *.xz

# build the man page
@man:
Expand All @@ -49,6 +50,23 @@ man_target := man_dir / "flog.1"
@show-man: man
man "{{man_target}}"

# perform static code analysis
@analyse:
#!/bin/bash
set -euo pipefail

build_dir="codeql/build"
db_dir="codeql/db"

[[ -d "${build_dir}" ]] && rm -rf "${build_dir}"
[[ -d "${db_dir}" ]] && rm -rf "${db_dir}"
[[ -f "{{sarif_file}}" ]] && rm -f "{{sarif_file}}"

mkdir -p "${build_dir}"

codeql database create "${db_dir}" --source-root="./src" --language="cpp" --command="cmake -S .. -B ../${build_dir}" --command="cmake --build ../${build_dir}"
codeql database analyze "${db_dir}" --format="sarif-latest" --output="{{sarif_file}}" "codeql/cpp-queries:codeql-suites/cpp-security-and-quality.qls"

# generate release package
@package version: build-release test-release man
#!/bin/bash
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ To build the man page:
just man
```

The `flog.1` man page is output to the `man` directory, and is converted from the source file `man/flog.1.md` using [Pandoc](https://github.com/jgm/pandoc).
The `flog.1` man page is output to the `man` directory and is converted from the source file `man/flog.1.md` using [Pandoc](https://github.com/jgm/pandoc).

## Acknowledgements

Expand Down
16 changes: 0 additions & 16 deletions tool/codeql-analyse-database

This file was deleted.

12 changes: 0 additions & 12 deletions tool/codeql-create-database

This file was deleted.