Skip to content

Commit a4198fb

Browse files
feat: add the cppcheck runner (#1)
* feat: add the cppcheck runner just the rust code for the cppcheck deepsource runner * feat: add the Dockerfile * feat: add cloudbuild to push image to dev * fix: dockerfile target binary path * fix: naming * add: OWNERS list & enable DeepSource * add: base image * fix: Dockerfile * fix: add proper issue code mapping * add: spdlog to image * chore: log cppcheck start and end time * fix * log more * use multi threading for cppcheck * chore: only lint on c family of files * pipe command output to stdout & stderr * feat: add support for caching * fix: add comments and cleanup * ci: add production cloudbuild depl * fix: install cppcheck from source * fix: pin version of cppcheck * chore: update dockerfile update libs to latests & support multiple destinations for prod build * chore: cleanup dockerfile & don't run on header files
1 parent 83e2957 commit a4198fb

15 files changed

+1196
-0
lines changed

.deepsource.toml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
version = 1
2+
3+
test_patterns = [
4+
"**/tests/**",
5+
"**/*tests.rs"
6+
]
7+
8+
exclude_patterns = [
9+
"tests/**",
10+
"**/tests/**",
11+
]
12+
13+
[[analyzers]]
14+
name = "rust"
15+
16+
[analyzers.meta]
17+
msrv = "stable"
18+
19+
[[analyzers]]
20+
name = "secrets"
21+
22+
[[transformers]]
23+
name = "rustfmt"

.github/CODEOWNERS

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @raghav-deepsource @srijan-deepsource @swarnim-deepsource @prajwal-deepsource

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/target
2+
/cppcheck_result.json
3+
/cppcheck_error.xml

Cargo.lock

+207
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "cppcheck-deepsource"
3+
version = "0.2.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
# serialize & deserialize
10+
serde = { version = "1.0.144", features = ["derive"] }
11+
# json support
12+
serde_json = "1.0.85"
13+
log = { version = "0.4.17" }
14+
atty = "0.2.14"
15+
walkdir = "2.3.2"
16+
quick-xml = { version = "0.28.0", features = ["serialize"] }
17+
18+
env_struct = "0.1.3"

Dockerfile

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# -----------------------------------------------------------
2+
# Base Image with LLVM
3+
# -----------------------------------------------------------
4+
FROM ubuntu:22.04 as ubuntu_llvm
5+
ENV DEBIAN_FRONTEND=noninteractive
6+
7+
# update the system and install any dependencies
8+
RUN apt-get update \
9+
&& apt-get upgrade -y libksba-dev \
10+
&& apt-get install -y git cmake build-essential byacc libpcre3 libpcre3-dev grep lsb-release wget software-properties-common gnupg libcurl4-openssl-dev unzip lcov --no-install-recommends # skipcq: DOK-DL3018
11+
12+
# Get LLVM
13+
ARG LLVM_VER=15
14+
RUN wget --no-verbose https://apt.llvm.org/llvm.sh
15+
RUN chmod +x ./llvm.sh \
16+
&& ./llvm.sh ${LLVM_VER} \
17+
&& apt-get -y install libclang-${LLVM_VER}-dev libclang-cpp${LLVM_VER}-dev --no-install-recommends \
18+
&& apt-get clean \
19+
&& rm -rf /var/lib/apt/lists/*
20+
21+
# Add environment variables for build
22+
ENV PATH="$PATH:/usr/lib/llvm-${LLVM_VER}/bin"
23+
ENV LLVM_INSTALL_DIR "/usr/lib/llvm-${LLVM_VER}"
24+
ENV SENTRY_INSTALL_DIR="/usr/lib/sentry-sdk"
25+
26+
# Get Sentry
27+
ARG SENTRY_TAG=0.6.3
28+
RUN mkdir /sentry-sdk \
29+
&& cd /sentry-sdk \
30+
&& wget --no-verbose "https://github.com/getsentry/sentry-native/releases/download/${SENTRY_TAG}/sentry-native.zip" \
31+
&& unzip sentry-native.zip \
32+
&& cmake -B ./build \
33+
&& cmake --build ./build --parallel \
34+
&& cmake --install ./build --prefix "${SENTRY_INSTALL_DIR}"
35+
36+
# Install spdlog
37+
RUN git clone --depth=1 --branch v1.11.0 https://github.com/gabime/spdlog.git \
38+
&& cd spdlog \
39+
&& cmake -B build \
40+
&& cmake --build build --parallel \
41+
&& cd build && make install
42+
43+
# Install cppcheck
44+
RUN git clone --depth=1 --branch 2.10.3 https://github.com/danmar/cppcheck.git \
45+
&& cd cppcheck \
46+
&& cmake -B build -DHAVE_RULES=ON -DUSE_MATCHCOMPILER=ON -DCMAKE_BUILD_TYPE=RELEASE \
47+
&& cmake --build build --parallel 4 \
48+
&& cd build && make install
49+
50+
# -----------------------------------------------------------
51+
# End
52+
# -----------------------------------------------------------
53+
54+
FROM rust:slim-bookworm AS rs_builder
55+
56+
RUN mkdir -p /code
57+
ADD . /code
58+
WORKDIR /code
59+
60+
RUN cargo b --release
61+
62+
FROM ubuntu_llvm
63+
64+
RUN mkdir -p /toolbox
65+
COPY --from=rs_builder /code/target/release/cppcheck-deepsource /toolbox/

analysis_config.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "files": [ "test.c" ] }

cloudbuild_depl.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
timeout: 30m0s
2+
3+
steps:
4+
- name: 'gcr.io/kaniko-project/executor:v1.0.0'
5+
args:
6+
- --destination=us.gcr.io/deepsource-production/cppcheck-deepsource:$TAG_NAME
7+
- --destination=us.gcr.io/deepsource-production/cppcheck-deepsource:latest
8+
- --dockerfile=Dockerfile
9+
- --cache=false
10+
- --snapshotMode=redo
11+
12+
options:
13+
machineType: 'E2_HIGHCPU_8'

cloudbuild_depl_dev.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
timeout: 30m0s
2+
3+
steps:
4+
- name: 'gcr.io/kaniko-project/executor:v1.0.0'
5+
args:
6+
- --destination=us.gcr.io/deepsource-dev/cppcheck-deepsource:dev
7+
- --dockerfile=Dockerfile
8+
- --cache=true
9+
- --cache-ttl=24h
10+
- --snapshotMode=redo
11+
12+
options:
13+
machineType: 'E2_HIGHCPU_8'

src/config.rs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use std::path::PathBuf;
2+
3+
use serde::Deserialize;
4+
5+
#[derive(Default, Deserialize, Debug)]
6+
pub struct AnalyzerConfig {
7+
files: Vec<PathBuf>,
8+
#[serde(default)]
9+
pub analyzer_meta: AnalyzerMeta,
10+
}
11+
12+
impl AnalyzerConfig {
13+
pub fn cxx_files(self) -> Vec<PathBuf> {
14+
self.files
15+
.into_iter()
16+
.filter(|f| !f.is_symlink())
17+
.filter(|f| f.is_file())
18+
.filter(|f| {
19+
f.extension()
20+
.map(|x| x.eq("cpp") | x.eq("c"))
21+
.unwrap_or_default()
22+
})
23+
// ignore files > ~25MB in size
24+
.filter(|f| {
25+
!f.metadata()
26+
.map(|x| x.len() > 25_000_000)
27+
.unwrap_or_default()
28+
})
29+
.collect()
30+
}
31+
}
32+
33+
#[derive(Deserialize, Default, Debug)]
34+
pub struct AnalyzerMeta {
35+
pub name: String,
36+
pub enabled: bool,
37+
// todo(swarnim): add misra_compliance: bool
38+
}

0 commit comments

Comments
 (0)