Skip to content

Commit ab96587

Browse files
nyalldawson3nidsdxli
authored
Improve CI (#43)
* github workflow * fix workflow * sudo * Update build.yml * Remove travis * cppcheck workflow * Fix workflow * ifdef out debug function * Don't error on warning category for now * Fix cpp check ubuntu versions * cppcheck on 18.04 never finishes * Try porting proj's mac build workflow * Try using ninja build * Clang static analyzer build (port from proj) * Fix permission * Fix path * Try using more recent clang tools * Fix clang value is never read, uninitialized field warnings * Fix memory leak --------- Co-authored-by: Denis Rouzaud <denis.rouzaud@gmail.com> Co-authored-by: Dongxu Li <dongxuli2011@gmail.com>
1 parent a515b9d commit ab96587

15 files changed

Lines changed: 295 additions & 31 deletions

File tree

.github/workflows/build.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: 🧪 build
2+
3+
on:
4+
push:
5+
pull_request:
6+
branches:
7+
- master
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v2
16+
17+
- name: Get deps
18+
run: |
19+
sudo apt-get install cmake ninja-build clang
20+
21+
- name: Build
22+
run: |
23+
mkdir -p build
24+
cd build
25+
cmake -GNinja ..
26+
ninja
27+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: CLang Static Analyzer
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
7+
clang_static_analyzer:
8+
runs-on: ubuntu-latest
9+
if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')"
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v2
13+
14+
- name: Run
15+
run: .github/workflows/clang_static_analyzer/start.sh
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
sudo apt update
6+
7+
DEBIAN_FRONTEND=noninteractive sudo apt-get install -y --no-install-recommends \
8+
libtool g++ make jq clang-tools
9+
10+
# prepare build files
11+
mkdir -p build
12+
cd build
13+
14+
NPROC=$(nproc)
15+
echo "NPROC=${NPROC}"
16+
export MAKEFLAGS="-j ${NPROC}"
17+
18+
CXXFLAGS="-std=c++11" scan-build -o scanbuildoutput -plist -v cmake ..
19+
rm -rf scanbuildoutput
20+
TOPDIR=$PWD
21+
scan-build -o $TOPDIR/scanbuildoutput -sarif -v -enable-checker alpha.unix.cstring.OutOfBounds,alpha.unix.cstring.BufferOverlap,optin.cplusplus.VirtualCall,optin.cplusplus.UninitializedObject make
22+
23+
rm -f filtered_scanbuild.txt
24+
files=$(find scanbuildoutput -name "*.sarif")
25+
for f in $files; do
26+
jq '.runs[].results[] | (if .locations[].physicalLocation.fileLocation.uri | (contains("_generated_parser") ) then empty else { "uri": .locations[].physicalLocation.fileLocation.uri, "msg": .message.text, "location": .codeFlows[-1].threadFlows[-1].locations[-1] } end)' < $f > tmp.txt
27+
if [ -s tmp.txt ]; then
28+
echo "Errors from $f: "
29+
cat $f
30+
echo ""
31+
cat tmp.txt >> filtered_scanbuild.txt
32+
fi
33+
done
34+
if [ -s filtered_scanbuild.txt ]; then
35+
echo ""
36+
echo ""
37+
echo "========================"
38+
echo "Summary of errors found:"
39+
cat filtered_scanbuild.txt
40+
/bin/false
41+
fi

.github/workflows/code_checks.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Code Checks
2+
3+
on:
4+
push:
5+
pull_request:
6+
branches:
7+
- master
8+
9+
jobs:
10+
11+
cppcheck_2004:
12+
runs-on: ubuntu-20.04
13+
if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')"
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v2
17+
18+
- name: Install Requirements
19+
run: |
20+
sudo apt update
21+
sudo apt install -y cppcheck
22+
23+
- name: Run cppcheck test
24+
run: ./scripts/cppcheck.sh
25+
26+
cppcheck_latest:
27+
runs-on: ubuntu-latest
28+
if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')"
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v2
32+
33+
- name: Install Requirements
34+
run: |
35+
sudo apt update
36+
sudo apt install -y cppcheck
37+
38+
- name: Run cppcheck test
39+
run: ./scripts/cppcheck.sh

.github/workflows/mac.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: MacOS build
2+
3+
on:
4+
push:
5+
pull_request:
6+
branches:
7+
- master
8+
9+
jobs:
10+
macos_build:
11+
runs-on: macos-latest
12+
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v2
16+
17+
- uses: conda-incubator/setup-miniconda@v2
18+
with:
19+
channels: conda-forge
20+
auto-update-conda: true
21+
22+
- name: Cache
23+
uses: actions/cache@v2
24+
id: cache
25+
with:
26+
path: ~/.ccache
27+
key: ${{ runner.os }}-cache-mac-${{ github.run_id }}
28+
restore-keys: ${{ runner.os }}-cache-mac-
29+
30+
- name: Install Requirements
31+
shell: bash -l {0}
32+
run: |
33+
source .github/workflows/mac/before_install.sh
34+
35+
- name: Build
36+
shell: bash -l {0}
37+
run: |
38+
source .github/workflows/mac/install.sh
39+
env:
40+
TRAVIS_OS_NAME: osx
41+
BUILD_NAME: osx
42+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
6+
conda update -n base -c defaults conda
7+
conda install compilers -y
8+
9+
conda config --set channel_priority strict
10+
conda install --yes --quiet libtool ccache ninja -y
11+

.github/workflows/mac/install.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
export CCACHE_CPP2=yes
6+
export PROJ_DB_CACHE_DIR="$HOME/.ccache"
7+
8+
ccache -M 200M
9+
ccache -s
10+
11+
export CC="ccache clang"
12+
export CXX="ccache clang++"
13+
export CFLAGS="-Werror -O2"
14+
export CXXFLAGS="-Werror -O2"
15+
16+
mkdir -p build
17+
cd build
18+
cmake -GNinja ..
19+
ninja
20+
21+
ccache -s

.travis.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

scripts/cppcheck.sh

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/sh
2+
3+
set -eu
4+
5+
SCRIPT_DIR=$(dirname "$0")
6+
case $SCRIPT_DIR in
7+
"/"*)
8+
;;
9+
".")
10+
SCRIPT_DIR=$(pwd)
11+
;;
12+
*)
13+
SCRIPT_DIR=$(pwd)/$(dirname "$0")
14+
;;
15+
esac
16+
17+
LOG_FILE=/tmp/cppcheck_libdxfrw.txt
18+
19+
rm -f ${LOG_FILE}
20+
echo "Checking ${SCRIPT_DIR}/../src ..."
21+
22+
cppcheck --inline-suppr \
23+
--template='{file}:{line},{severity},{id},{message}' \
24+
--enable=all --inconclusive --std=c++11 \
25+
-j $(nproc) \
26+
${SCRIPT_DIR}/../src \
27+
>>${LOG_FILE} 2>&1 &
28+
29+
PID=$!
30+
while kill -0 $PID 2>/dev/null; do
31+
printf "."
32+
sleep 1
33+
done
34+
echo " done"
35+
if ! wait $PID; then
36+
echo "cppcheck failed"
37+
exit 1
38+
fi
39+
40+
ret_code=0
41+
42+
cat ${LOG_FILE} | grep -v -e "syntaxError," -e "cppcheckError," > ${LOG_FILE}.tmp
43+
mv ${LOG_FILE}.tmp ${LOG_FILE}
44+
45+
for category in "style" "performance" "portability" "warning"; do
46+
if grep "${category}," ${LOG_FILE} >/dev/null; then
47+
echo "INFO: Issues in '${category}' category found, but not considered as making script to fail:"
48+
grep "${category}," ${LOG_FILE} | grep -v -e "clarifyCalculation," -e "duplicateExpressionTernary," -e "redundantCondition," -e "unusedPrivateFunction," -e "postfixOperator,"
49+
echo ""
50+
fi
51+
done
52+
53+
# unusedPrivateFunction not reliable enough in cppcheck 1.72 of Ubuntu 16.04
54+
if test "$(cppcheck --version)" = "Cppcheck 1.72"; then
55+
UNUSED_PRIVATE_FUNCTION=""
56+
else
57+
UNUSED_PRIVATE_FUNCTION="unusedPrivateFunction"
58+
fi
59+
60+
for category in "error" "clarifyCalculation" "duplicateExpressionTernary" "redundantCondition" "postfixOperator" "${UNUSED_PRIVATE_FUNCTION}"; do
61+
if test "${category}" != ""; then
62+
if grep "${category}," ${LOG_FILE} >/dev/null; then
63+
echo "ERROR: Issues in '${category}' category found:"
64+
grep "${category}," ${LOG_FILE}
65+
echo ""
66+
echo "${category} check failed !"
67+
ret_code=1
68+
fi
69+
fi
70+
done
71+
72+
if [ ${ret_code} = 0 ]; then
73+
echo "cppcheck succeeded"
74+
fi
75+
76+
exit ${ret_code}

src/drw_header.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2411,9 +2411,8 @@ fs0.close();
24112411
}
24122412

24132413
//temporary code to show header end sentinel
2414-
duint64 sz= buf->size()-1;
24152414
if (version < DRW::AC1018) {//pre 2004
2416-
sz= buf->size()-16;
2415+
const duint64 sz= buf->size()-16;
24172416
buf->setPosition(sz);
24182417
DRW_DBG("\nsetting position to: "); DRW_DBG(buf->getPosition());
24192418
DRW_DBG("\ndwg header end sentinel= ");
@@ -2430,7 +2429,7 @@ fs0.close();
24302429
DRW_DBGH(buf->getRawChar8()); DRW_DBG(" ");
24312430
}
24322431
} else if (version == DRW::AC1021) {//2007
2433-
sz= buf->size()-16;
2432+
const duint64 sz= buf->size()-16;
24342433
buf->setPosition(sz);
24352434
DRW_DBG("\nsetting position to: "); DRW_DBG(buf->getPosition());
24362435
DRW_DBG("\ndwg header end sentinel= ");

0 commit comments

Comments
 (0)