1、基于centos 7.5安装cppcheck
mkdir /home/cppcheck && cd /home/cppcheck
wget https://sourceforge.net/projects/cppcheck/files/cppcheck/1.90/cppcheck-1.90.tar.gz
tar -zxf cppcheck-1.90.tar.gz && rm -f cppcheck-1.90.tar.gz
cd cppcheck-1.90 && yum -y update gcc && yum -y install gcc+ gcc-c++
pip install pygments
make install MATCHCOMPILER=yes FILESDIR=/usr/share/cppcheck HAVE_RULES=no CXXFLAGS="-O2 -DNDEBUG -Wall -Wno-sign-compare -Wno-unused-function"
2、cppcheck使用
cppcheck -j 4 --enable = all -i --xml --xml-version = 2 /SOURCE_DIRECTORY/xxx SOURCE_DIRECTORY 2> cppcheck.xml
cppcheck-htmlreport --file=/home/cppcheck_result.xml --report-dir=test1 --source-dir=/home/
3、docker镜像
dockerfile:
---------------------cppcheck:v1---------------------------
FROM alpine
LABEL maintainer="xxx"
RUN mkdir /home/cppcheck && cd /home/cppcheck
COPY ./cppcheck-1.90.tar.gz ./
RUN \
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
apk add --no-cache -t .required_apks make g++ pcre-dev && \
tar -zxf cppcheck-1.90.tar.gz && rm -f cppcheck-1.90.tar.gz && \
cd cppcheck-1.90 && \
make install FILESDIR=/cfg HAVE_RULES=yes CXXFLAGS="-O2 -DNDEBUG --static" -j `getconf _NPROCESSORS_ONLN` && \
strip /usr/bin/cppcheck && \
apk del .required_apks && \
rm -rf /home/cppcheck && \
ENTRYPOINT ["cppcheck", "/src"]
docker run --rm -t -v /home/test_src:/src cppcheck:v1 -i /src/src1 --xml-version=2 --enable=all > testreport_v1.xml
------------------------------------------------------------
---------------------cppcheck:v2---------------------------
FROM python:3.8.1-alpine AS base
RUN mkdir /home/cppcheck && cd /home/cppcheck
COPY ./cppcheck-1.90.tar.gz ./
WORKDIR /tmp/cppcheck
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
apk add --no-cache -t .required_apks \
git=2.24.2-r0 \
make=4.2.1-r2 \
g++=9.2.0-r4 \
pcre-dev=8.43-r0 && \
tar -zxf cppcheck-1.90.tar.gz && rm -f cppcheck-1.90.tar.gz && \
cd cppcheck-1.90 && \
make install MATCHCOMPILER=yes FILESDIR=/etc/cppcheck HAVE_RULES=yes CXXFLAGS="-O2 -DNDEBUG -Wall -Wno-sign-compare -Wno-unused-function --static" && \
apk del .required_apks && \
echo -e "#!/bin/sh\ncppcheck --dump .\n misra.py \`find . -name '*.dump' | tr '\n' ' '\` 2> misra-report.txt" > /usr/bin/misra && chmod +x /usr/bin/misra
FROM python:3.8.1-alpine
RUN pip install pygments && \
rm -rf /lib/apk /etc/apk /home /var /tmp /srv /media /mnt /run /sbin /opt
COPY --from=base /usr/bin/cppcheck /usr/bin/cppcheck-htmlreport /usr/bin/misra /usr/bin/*.py /usr/bin/
COPY --from=base /etc/cppcheck /etc/cppcheck
LABEL maintainer="xxxx"
WORKDIR /src
ENTRYPOINT ["sh", "-c"]
docker run --rm -t -v /home/test_src:/src cppcheck:v2 "cppcheck -i /src/src1 /src --xml-version=2 --enable=all 2> testreport_v2.xml && cppcheck-htmlreport --file=./testreport_v2.xml --report-dir=htmlreport --source-dir=./"
网友评论