Skip to content

feat: add the cppcheck runner #1

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

Merged
merged 23 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6450c57
feat: add the cppcheck runner
swarnim-deepsource May 2, 2023
13d2101
feat: add the Dockerfile
swarnim-deepsource May 3, 2023
2a021e7
feat: add cloudbuild to push image to dev
swarnim-deepsource May 3, 2023
461e663
fix: dockerfile target binary path
swarnim-deepsource May 3, 2023
e5c5ecc
fix: naming
swarnim-deepsource May 4, 2023
0d4a9b5
add: OWNERS list & enable DeepSource
swarnim-deepsource May 5, 2023
d7cdd5a
add: base image
swarnim-deepsource May 11, 2023
aebe3ff
fix: Dockerfile
swarnim-deepsource May 11, 2023
f6a14c5
fix: add proper issue code mapping
swarnim-deepsource May 11, 2023
8c8b56b
add: spdlog to image
swarnim-deepsource May 23, 2023
a9d11a2
chore: log cppcheck start and end time
swarnim-deepsource May 23, 2023
2eebe92
fix
swarnim-deepsource May 23, 2023
6df4118
log more
swarnim-deepsource May 23, 2023
3af37b6
use multi threading for cppcheck
swarnim-deepsource May 24, 2023
c69d6b2
chore: only lint on c family of files
swarnim-deepsource May 25, 2023
2f18e4b
pipe command output to stdout & stderr
swarnim-deepsource May 26, 2023
f67f3b2
feat: add support for caching
swarnim-deepsource May 29, 2023
03acaad
fix: add comments and cleanup
swarnim-deepsource May 30, 2023
53cf507
ci: add production cloudbuild depl
swarnim-deepsource Jun 5, 2023
78c18c1
fix: install cppcheck from source
swarnim-deepsource Jun 6, 2023
4a7845f
fix: pin version of cppcheck
swarnim-deepsource Jun 6, 2023
150f4ce
chore: update dockerfile
swarnim-deepsource Jun 12, 2023
64236af
chore: cleanup dockerfile & don't run on header files
swarnim-deepsource Jun 13, 2023
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
23 changes: 23 additions & 0 deletions .deepsource.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version = 1

test_patterns = [
"**/tests/**",
"**/*tests.rs"
]

exclude_patterns = [
"tests/**",
"**/tests/**",
]

[[analyzers]]
name = "rust"

[analyzers.meta]
msrv = "stable"

[[analyzers]]
name = "secrets"

[[transformers]]
name = "rustfmt"
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @raghav-deepsource @srijan-deepsource @swarnim-deepsource @prajwal-deepsource
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/target
/cppcheck_result.json
/cppcheck_error.xml
207 changes: 207 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "cppcheck-deepsource"
version = "0.2.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
# serialize & deserialize
serde = { version = "1.0.144", features = ["derive"] }
# json support
serde_json = "1.0.85"
log = { version = "0.4.17" }
atty = "0.2.14"
walkdir = "2.3.2"
quick-xml = { version = "0.28.0", features = ["serialize"] }

env_struct = "0.1.3"
65 changes: 65 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# -----------------------------------------------------------
# Base Image with LLVM
# -----------------------------------------------------------
FROM ubuntu:22.04 as ubuntu_llvm
ENV DEBIAN_FRONTEND=noninteractive

# update the system and install any dependencies
RUN apt-get update \
&& apt-get upgrade -y libksba-dev \
&& 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

# Get LLVM
ARG LLVM_VER=15
RUN wget --no-verbose https://apt.llvm.org/llvm.sh
RUN chmod +x ./llvm.sh \
&& ./llvm.sh ${LLVM_VER} \
&& apt-get -y install libclang-${LLVM_VER}-dev libclang-cpp${LLVM_VER}-dev --no-install-recommends \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Add environment variables for build
ENV PATH="$PATH:/usr/lib/llvm-${LLVM_VER}/bin"
ENV LLVM_INSTALL_DIR "/usr/lib/llvm-${LLVM_VER}"
ENV SENTRY_INSTALL_DIR="/usr/lib/sentry-sdk"

# Get Sentry
ARG SENTRY_TAG=0.6.3
RUN mkdir /sentry-sdk \
&& cd /sentry-sdk \
&& wget --no-verbose "https://github.com/getsentry/sentry-native/releases/download/${SENTRY_TAG}/sentry-native.zip" \
&& unzip sentry-native.zip \
&& cmake -B ./build \
&& cmake --build ./build --parallel \
&& cmake --install ./build --prefix "${SENTRY_INSTALL_DIR}"

# Install spdlog
RUN git clone --depth=1 --branch v1.11.0 https://github.com/gabime/spdlog.git \
&& cd spdlog \
&& cmake -B build \
&& cmake --build build --parallel \
&& cd build && make install

# Install cppcheck
RUN git clone --depth=1 --branch 2.10.3 https://github.com/danmar/cppcheck.git \
&& cd cppcheck \
&& cmake -B build -DHAVE_RULES=ON -DUSE_MATCHCOMPILER=ON -DCMAKE_BUILD_TYPE=RELEASE \
&& cmake --build build --parallel 4 \
&& cd build && make install

# -----------------------------------------------------------
# End
# -----------------------------------------------------------

FROM rust:slim-bookworm AS rs_builder

RUN mkdir -p /code
ADD . /code
WORKDIR /code

RUN cargo b --release

FROM ubuntu_llvm

RUN mkdir -p /toolbox
COPY --from=rs_builder /code/target/release/cppcheck-deepsource /toolbox/
1 change: 1 addition & 0 deletions analysis_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "files": [ "test.c" ] }
13 changes: 13 additions & 0 deletions cloudbuild_depl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
timeout: 30m0s

steps:
- name: 'gcr.io/kaniko-project/executor:v1.0.0'
args:
- --destination=us.gcr.io/deepsource-production/cppcheck-deepsource:$TAG_NAME
- --destination=us.gcr.io/deepsource-production/cppcheck-deepsource:latest
- --dockerfile=Dockerfile
- --cache=false
- --snapshotMode=redo

options:
machineType: 'E2_HIGHCPU_8'
13 changes: 13 additions & 0 deletions cloudbuild_depl_dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
timeout: 30m0s

steps:
- name: 'gcr.io/kaniko-project/executor:v1.0.0'
args:
- --destination=us.gcr.io/deepsource-dev/cppcheck-deepsource:dev
- --dockerfile=Dockerfile
- --cache=true
- --cache-ttl=24h
- --snapshotMode=redo

options:
machineType: 'E2_HIGHCPU_8'
38 changes: 38 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use std::path::PathBuf;

use serde::Deserialize;

#[derive(Default, Deserialize, Debug)]
pub struct AnalyzerConfig {
files: Vec<PathBuf>,
#[serde(default)]
pub analyzer_meta: AnalyzerMeta,
}

impl AnalyzerConfig {
pub fn cxx_files(self) -> Vec<PathBuf> {
self.files
.into_iter()
.filter(|f| !f.is_symlink())
.filter(|f| f.is_file())
.filter(|f| {
f.extension()
.map(|x| x.eq("cpp") | x.eq("c"))
.unwrap_or_default()
})
// ignore files > ~25MB in size
.filter(|f| {
!f.metadata()
.map(|x| x.len() > 25_000_000)
.unwrap_or_default()
})
.collect()
}
}

#[derive(Deserialize, Default, Debug)]
pub struct AnalyzerMeta {
pub name: String,
pub enabled: bool,
// todo(swarnim): add misra_compliance: bool
}
Loading