Skip to content
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

Improve CI #43

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 27 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: 🧪 build

on:
push:
pull_request:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Get deps
run: |
sudo apt-get install cmake ninja-build clang

- name: Build
run: |
mkdir -p build
cd build
cmake -GNinja ..
ninja

15 changes: 15 additions & 0 deletions .github/workflows/clang_static_analyzer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: CLang Static Analyzer

on: [push, pull_request]

jobs:

clang_static_analyzer:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')"
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Run
run: .github/workflows/clang_static_analyzer/start.sh
41 changes: 41 additions & 0 deletions .github/workflows/clang_static_analyzer/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

set -e

sudo apt update

DEBIAN_FRONTEND=noninteractive sudo apt-get install -y --no-install-recommends \
libtool g++ make jq clang-tools

# prepare build files
mkdir -p build
cd build

NPROC=$(nproc)
echo "NPROC=${NPROC}"
export MAKEFLAGS="-j ${NPROC}"

CXXFLAGS="-std=c++11" scan-build -o scanbuildoutput -plist -v cmake ..
rm -rf scanbuildoutput
TOPDIR=$PWD
scan-build -o $TOPDIR/scanbuildoutput -sarif -v -enable-checker alpha.unix.cstring.OutOfBounds,alpha.unix.cstring.BufferOverlap,optin.cplusplus.VirtualCall,optin.cplusplus.UninitializedObject make

rm -f filtered_scanbuild.txt
files=$(find scanbuildoutput -name "*.sarif")
for f in $files; do
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
if [ -s tmp.txt ]; then
echo "Errors from $f: "
cat $f
echo ""
cat tmp.txt >> filtered_scanbuild.txt
fi
done
if [ -s filtered_scanbuild.txt ]; then
echo ""
echo ""
echo "========================"
echo "Summary of errors found:"
cat filtered_scanbuild.txt
/bin/false
fi
39 changes: 39 additions & 0 deletions .github/workflows/code_checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Code Checks

on:
push:
pull_request:
branches:
- master

jobs:

cppcheck_2004:
runs-on: ubuntu-20.04
if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')"
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install Requirements
run: |
sudo apt update
sudo apt install -y cppcheck

- name: Run cppcheck test
run: ./scripts/cppcheck.sh

cppcheck_latest:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')"
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install Requirements
run: |
sudo apt update
sudo apt install -y cppcheck

- name: Run cppcheck test
run: ./scripts/cppcheck.sh
42 changes: 42 additions & 0 deletions .github/workflows/mac.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: MacOS build

on:
push:
pull_request:
branches:
- master

jobs:
macos_build:
runs-on: macos-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- uses: conda-incubator/setup-miniconda@v2
with:
channels: conda-forge
auto-update-conda: true

- name: Cache
uses: actions/cache@v2
id: cache
with:
path: ~/.ccache
key: ${{ runner.os }}-cache-mac-${{ github.run_id }}
restore-keys: ${{ runner.os }}-cache-mac-

- name: Install Requirements
shell: bash -l {0}
run: |
source .github/workflows/mac/before_install.sh

- name: Build
shell: bash -l {0}
run: |
source .github/workflows/mac/install.sh
env:
TRAVIS_OS_NAME: osx
BUILD_NAME: osx

11 changes: 11 additions & 0 deletions .github/workflows/mac/before_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

set -e


conda update -n base -c defaults conda
conda install compilers -y

conda config --set channel_priority strict
conda install --yes --quiet libtool ccache ninja -y

21 changes: 21 additions & 0 deletions .github/workflows/mac/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

set -e

export CCACHE_CPP2=yes
export PROJ_DB_CACHE_DIR="$HOME/.ccache"

ccache -M 200M
ccache -s

export CC="ccache clang"
export CXX="ccache clang++"
export CFLAGS="-Werror -O2"
export CXXFLAGS="-Werror -O2"

mkdir -p build
cd build
cmake -GNinja ..
ninja

ccache -s
17 changes: 0 additions & 17 deletions .travis.yml

This file was deleted.

76 changes: 76 additions & 0 deletions scripts/cppcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/sh

set -eu

SCRIPT_DIR=$(dirname "$0")
case $SCRIPT_DIR in
"/"*)
;;
".")
SCRIPT_DIR=$(pwd)
;;
*)
SCRIPT_DIR=$(pwd)/$(dirname "$0")
;;
esac

LOG_FILE=/tmp/cppcheck_libdxfrw.txt

rm -f ${LOG_FILE}
echo "Checking ${SCRIPT_DIR}/../src ..."

cppcheck --inline-suppr \
--template='{file}:{line},{severity},{id},{message}' \
--enable=all --inconclusive --std=c++11 \
-j $(nproc) \
${SCRIPT_DIR}/../src \
>>${LOG_FILE} 2>&1 &

PID=$!
while kill -0 $PID 2>/dev/null; do
printf "."
sleep 1
done
echo " done"
if ! wait $PID; then
echo "cppcheck failed"
exit 1
fi

ret_code=0

cat ${LOG_FILE} | grep -v -e "syntaxError," -e "cppcheckError," > ${LOG_FILE}.tmp
mv ${LOG_FILE}.tmp ${LOG_FILE}

for category in "style" "performance" "portability" "warning"; do
if grep "${category}," ${LOG_FILE} >/dev/null; then
echo "INFO: Issues in '${category}' category found, but not considered as making script to fail:"
grep "${category}," ${LOG_FILE} | grep -v -e "clarifyCalculation," -e "duplicateExpressionTernary," -e "redundantCondition," -e "unusedPrivateFunction," -e "postfixOperator,"
echo ""
fi
done

# unusedPrivateFunction not reliable enough in cppcheck 1.72 of Ubuntu 16.04
if test "$(cppcheck --version)" = "Cppcheck 1.72"; then
UNUSED_PRIVATE_FUNCTION=""
else
UNUSED_PRIVATE_FUNCTION="unusedPrivateFunction"
fi

for category in "error" "clarifyCalculation" "duplicateExpressionTernary" "redundantCondition" "postfixOperator" "${UNUSED_PRIVATE_FUNCTION}"; do
if test "${category}" != ""; then
if grep "${category}," ${LOG_FILE} >/dev/null; then
echo "ERROR: Issues in '${category}' category found:"
grep "${category}," ${LOG_FILE}
echo ""
echo "${category} check failed !"
ret_code=1
fi
fi
done

if [ ${ret_code} = 0 ]; then
echo "cppcheck succeeded"
fi

exit ${ret_code}
5 changes: 2 additions & 3 deletions src/drw_header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2400,9 +2400,8 @@ bool DRW_Header::parseDwg(DRW::Version version, dwgBuffer *buf, dwgBuffer *hBbuf
}

//temporary code to show header end sentinel
duint64 sz= buf->size()-1;
if (version < DRW::AC1018) {//pre 2004
sz= buf->size()-16;
const duint64 sz= buf->size()-16;
buf->setPosition(sz);
DRW_DBG("\nseting position to: "); DRW_DBG(buf->getPosition());
DRW_DBG("\ndwg header end sentinel= ");
Expand All @@ -2419,7 +2418,7 @@ bool DRW_Header::parseDwg(DRW::Version version, dwgBuffer *buf, dwgBuffer *hBbuf
DRW_DBGH(buf->getRawChar8()); DRW_DBG(" ");
}
} else if (version == DRW::AC1021) {//2007
sz= buf->size()-16;
const duint64 sz= buf->size()-16;
buf->setPosition(sz);
DRW_DBG("\nseting position to: "); DRW_DBG(buf->getPosition());
DRW_DBG("\ndwg header end sentinel= ");
Expand Down
1 change: 1 addition & 0 deletions src/intern/dwgreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,7 @@ bool dwgReader::readDwgTables(DRW_Header& hdr, dwgBuffer *dbuf) {
ret = false;
} else { //reset position
buff.resetPosition();
(void)bs;
/* RLZ: writeme ret2 = vpEntHeader.parseDwg(version, &buff, bs);
if(ret)
ret = ret2;*/
Expand Down
14 changes: 7 additions & 7 deletions src/intern/dwgreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ class dwgPageInfo {
dwgPageInfo(duint64 i, duint64 ad, duint32 sz){
Id=i; address=ad; size=sz;
}
duint64 Id;
duint64 address; //in file stream, for rd18, rd21
duint64 size; //in file stream, for rd18, rd21
duint64 dataSize; //for rd18, rd21
duint32 startOffset; //for rd18, rd21
duint64 cSize; //compresed page size, for rd21
duint64 uSize; //uncompresed page size, for rd21
duint64 Id{0};
duint64 address{0}; //in file stream, for rd18, rd21
duint64 size{0}; //in file stream, for rd18, rd21
duint64 dataSize{0}; //for rd18, rd21
duint32 startOffset{0}; //for rd18, rd21
duint64 cSize{0}; //compressed page size, for rd21
duint64 uSize{0}; //uncompressed page size, for rd21
};

// sections of file
Expand Down
6 changes: 5 additions & 1 deletion src/intern/dwgreader18.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "drw_textcodec.h"
#include "../libdwgr.h"

#if 0
void dwgReader18::genMagicNumber(){
int size =0x114;
duint8 *tmpMagicStr = new duint8[size];
Expand All @@ -45,6 +46,7 @@ void dwgReader18::genMagicNumber(){
}
delete[]tmpMagicStr;
}
#endif

duint32 dwgReader18::checksum(duint32 seed, duint8* data, duint32 sz){
duint32 size = sz;
Expand Down Expand Up @@ -208,7 +210,9 @@ bool dwgReader18::readFileHeader() {
if (! fileBuf->setPosition(0x80))
return false;

// genMagicNumber(); DBG("\n"); DBG("\n");
#if 0
genMagicNumber(); DBG("\n"); DBG("\n");
#endif
DRW_DBG("Encripted Header Data=\n");
duint8 byteStr[0x6C];
int size =0x6C;
Expand Down
3 changes: 3 additions & 0 deletions src/intern/dwgreader18.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ class dwgReader18 : public dwgReader {
duint64 uncompSize;

private:
#if 0
void genMagicNumber();
#endif

// dwgBuffer* bufObj;
void parseSysPage(duint8 *decompSec, duint32 decompSize); //called: Section page map: 0x41630e3b
bool parseDataPage(const dwgSectionInfo &si/*, duint8 *dData*/); //called ???: Section map: 0x4163003b
Expand Down
4 changes: 3 additions & 1 deletion src/intern/dwgreader21.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,10 @@ bool dwgReader21::readFileHeader() {
duint8 *SectionsMapData = new duint8[SectionsMapSizeUncompressed];
dwgPageInfo sectionMap = sectionPageMapTmp[SectionsMapId];
ret = parseSysPage(SectionsMapSizeCompressed, SectionsMapSizeUncompressed, SectionsMapCorrectionFactor, sectionMap.address, SectionsMapData);
if (!ret)
if (!ret) {
delete[]SectionsMapData;
return false;
}

//reads sections:
//Note: compressed value are not stored in file then, commpresed field are use to store
Expand Down