After the appearance of a series of articles on embedding PVS-Studio in various IDEs under Linux ( Eclipse , Anjuta ), there was a desire to launch PVS-Studio to test its projects being developed in Eclipse under macOS. But the PVS-Studio developers are not planning to release a version for macOS yet. Well, let us shut this gap for now.
There are actually several solutions:
I stopped at Docker, because a virtual machine would consume too many resources, it is theoretically possible to organize a check on another computer using, for example, a bunch of NFS + SSH, but, I'm afraid, it would work too slowly.
Docker had cons too. Rather, one fat - I did not know anything about Docker. On Habré there are introductory articles. With their help, it took a day and a half to implement the idea.
A quick start takes just a few minutes. You need to set up scripts and Eclipce.
Five files will be needed:
#!/bin/sh echo "Fetching last timurey/docker-pvs image" /usr/local/bin/docker pull timurey/docker-pvs:latest echo "Testing" /usr/local/bin/docker run -i timurey/docker-pvs echo "Ready to run"
#!/bin/bash debug() { if [ "$debug" == "1" ]; then d=$1 echo $d fi } usage() { echo "usage: eclipse-pvs [[-w <path> -n <name> [-d]]| -h]" echo "where args:" echo " -w(--workspace) <path> set path to workspace directory" echo " -n(--projectname) <name> project name in eclipse" echo " -c(--config) <config> config descriptor (Debug or Release)" echo " -d(--debug) some debuging info" echo " -h(--help) show this message" } clean () { debug "Clean" make -f makefile clean exit } analyze() { debug "running command:" debug "/usr/local/bin/docker run --security-opt seccomp:\"""$workspace/docker-pvs/strace.json""\" -v \"""$workspace""\":/root/workspace -i timurey/docker-pvs /root/workspace/docker-pvs/client.sh -n \"""$projectname""\" -c \"""$config""\"" /usr/local/bin/docker run --security-opt seccomp:"$workspace/docker-pvs/strace.json" -v "$workspace":/root/workspace -i timurey/docker-pvs /root/workspace/docker-pvs/client.sh -n "$projectname" -c "$config" exit } while [ "$1" != "" ]; do case $1 in -w | --workspace ) shift workspace=$1 ;; -c | --config ) shift config=$1 ;; -n | --projectname ) shift projectname=$1 ;; -d | --debug ) debug=1 ;; -h | --help ) usage exit ;; clean ) clean exit esac shift done if [ "$workspace" != "" ]; then if [ "$projectname" != "" ]; then if [ "$config" != "" ]; then debug "workspace path: \"$workspace\"" debug "project name: \"$projectname\"" debug "config description: \"$config\"" analyze else echo "config description is not defined" >&2 exit fi else echo "project name path is not defined" >&2 exit fi else echo "workspace is not defined" >&2 exit fi
#!/bin/bash while [ "$1" != "" ]; do case $1 in -n | --projectname ) shift projectname=$1 ;; -c | --config ) shift config=$1 ;; esac shift done if [ "$projectname" != "" ]; then TEMPLOG=$(tempfile) cd "/root/workspace/$projectname/$config" # `strace`, : pvs-studio-analyzer trace -- make -f makefile all 2>&1 | sed '/strace: umovestr:/d' - pvs-studio-analyzer analyze --compiler arm-none-eabi-gcc -o "$TEMPLOG" --cfg /root/workspace/docker-pvs/pvs-studio.cfg # , : RC=$(plog-converter -t errorfile "$TEMPLOG" | sed '/The documentation for all/d' -) rm -f "$TEMPLOG" echo "$RC" fi
{ "defaultAction": "SCMP_ACT_ALLOW", "syscalls": [ { "name": "strace", "action": "SCMP_ACT_ERRNO" } ] }
exclude-path = /usr/arm-none-eabi/include platform = linux64 preprocessor = gcc analysis-mode = 4 sourcetree-root = /root/workspace
Eclipse uses the workspace directory in which projects are stored. Create a docker-pvs directory inside it and add all the above files there. Making the scripts executable:
$ chmod +x run_once.sh eclipse-pvs.sh client.sh
We will run the analyzer at compile time. It is desirable that one version of the compiler be used in the container and in Eclipse. The image contains version 5-2016-q3 (from 2016-09-19), so we download and install for macOS version 5-2016-q3 (from 2016-09-28) from the site launchpad.net
In the project properties and create a new configuration based on Debug
Then in the options of the new configuration:
1. Uncheck "Use default build command
2. In the Build command, we put the following command:
${workspace_loc}/docker-pvs/eclipse-pvs.sh -w "${workspace_loc}" -n ${ProjName} -c Debug -d
3. Check Generate Makefiles automatically
Close the project properties, make the newly created configuration active and
Team
${workspace_loc}/docker-pvs/eclipse-pvs -w "${workspace_loc}" -n ${ProjName} -c Debug -d
Runs our script and passes the following parameters to it:
The eclipse-pvs.sh
script starts the docker after checking the required parameters.
/usr/local/bin/docker run --security-opt seccomp:"$workspace/docker-pvs/strace.json" -v "$workspace":/root/workspace -i timurey/docker-pvs /root/workspace/docker-pvs/client.sh -n "$projectname" -c "$config"
Here the parameters are slightly more:
For those who want to assemble the image itself:
FROM ubuntu:14.04 RUN apt-get update && apt-get install -y strace software-properties-common cmake wget \ && add-apt-repository ppa:team-gcc-arm-embedded/ppa \ && apt-get update && apt-get install -y gcc-arm-embedded RUN wget http://files.viva64.com/pvs-studio-6.11.20138.1-amd64.deb RUN dpkg -i pvs-studio-6.11.20138.1-amd64.deb RUN rm pvs-studio-6.11.20138.1-amd64.deb RUN echo Asia/Yekaterinburg >/etc/timezone && ln -sf /usr/share/zoneinfo/Asia/Yekaterinburg /etc/localtime && dpkg-reconfigure -f noninteractive tzdata
It would seem that Docker is used only by web developers. But it is not. Docker can also be used to develop C / C ++, including microcontrollers.
Source: https://habr.com/ru/post/317518/
All Articles