Skip to content

Commit 1d18328

Browse files
authored
Merge pull request #3 from Simverge/sonarcloud
Enable SonarCloud analysis
2 parents cd4be6b + 6867bd1 commit 1d18328

File tree

6 files changed

+68
-36
lines changed

6 files changed

+68
-36
lines changed

.travis.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
sudo: required
22

3-
language: minimal
3+
# Required by SonarCloud - see https://docs.travis-ci.com/user/sonarcloud/
4+
language: java
5+
dist: trusty
6+
47
services: docker
58

9+
addons:
10+
sonarcloud:
11+
organization: "simverge"
12+
token:
13+
secure: $SONAR_TOKEN
14+
615
env:
716
- DISTRO=alpine BUILD_TYPE=Release
817
- DISTRO=alpine BUILD_TYPE=Debug
@@ -14,4 +23,5 @@ before_install:
1423

1524
script:
1625
- chmod u+x $TRAVIS_BUILD_DIR/tests/travis/script.sh
17-
- docker run -e TRAVIS_BRANCH -e BUILD_TYPE -e DISTRO -v $TRAVIS_BUILD_DIR:/pdalc -t simverge/pdalc-build-deps:$DISTRO /pdalc/tests/travis/script.sh
26+
- docker run -e TRAVIS_BRANCH -e BUILD_TYPE -e DISTRO -v $TRAVIS_BUILD_DIR:/pdalc -t simverge/pdalc-build-deps:$DISTRO /pdalc/tests/travis/script.sh
27+
- if [ "$DISTRO" = "ubuntu" ]; then sonar-scanner; fi

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ pdal-c: PDAL C API
22
==================
33

44
[![Build Status](https://travis-ci.com/Simverge/pdal-c.svg?branch=master)](https://travis-ci.com/Simverge/pdal-c)
5+
[![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=Simverge_pdal-c&metric=alert_status)](https://sonarcloud.io/project/issues?id=Simverge_pdal-c)
56

67
*pdal-c* is a C API for the Point Data Abstraction Library ([PDAL](http:/github.com/PDAL/PDAL))
78
and is compatible with PDAL 1.7 and later.

sonar-project.properties

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# SonarQube/SonarCloud properties for pdal-c
2+
3+
# must be unique in a given SonarQube instance
4+
sonar.projectKey=Simverge_pdal-c
5+
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
6+
sonar.projectName=pdal-c
7+
sonar.projectVersion=1.8
8+
9+
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
10+
# This property is optional if sonar.modules is set.
11+
sonar.sources=source
12+
13+
# Encoding of the source code. Default is default system encoding
14+
#sonar.sourceEncoding=UTF-8
15+
16+
sonar.branch.name=sonarcloud
17+
18+
# Properties specific to the C/C++ analyzer:
19+
sonar.cfamily.build-wrapper-output=bw-output
20+
#sonar.cfamily.gcov.reportsPath=build/${env.DISTRO}-x86_64-${env.BUILD_TYPE}/coverage_pdalc

source/pdal/pdalc_config.cpp

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,28 @@ namespace pdal
4040
{
4141
namespace capi
4242
{
43-
size_t PDALGetGdalDataPath(char *path, size_t size)
43+
/**
44+
* Retrieves the value of an environment variable.
45+
*
46+
* @param name The name of the environment variable
47+
* @param[out] path The buffer used to retrieve the value
48+
* @param size The size of the provided buffer
49+
* @return The size of the retrieved value
50+
*/
51+
size_t getEnvironmentVariable(const char *name, char *value, size_t size)
4452
{
4553
size_t length = 0;
4654

47-
if (path && size > 0)
55+
if (value && size > 0)
4856
{
49-
path[0] = '\0';
50-
path[size-1] = '\0';
57+
value[0] = '\0';
58+
value[size-1] = '\0';
5159

5260
char *env = nullptr;
5361

5462
try
5563
{
56-
env = std::getenv("GDAL_DATA");
64+
env = std::getenv(name);
5765
}
5866
catch (const std::exception &)
5967
{
@@ -62,42 +70,22 @@ size_t PDALGetGdalDataPath(char *path, size_t size)
6270

6371
if (env)
6472
{
65-
std::strncpy(path, env, size - 1);
73+
std::strncpy(value, env, size - 1);
6674
length = std::min(std::strlen(env), size - 1);
6775
}
6876
}
6977

7078
return length;
7179
}
7280

73-
size_t PDALGetProj4DataPath(char *path, size_t size)
81+
size_t PDALGetGdalDataPath(char *path, size_t size)
7482
{
75-
size_t length = 0;
76-
77-
if (path && size > 0)
78-
{
79-
path[0] = '\0';
80-
path[size-1] = '\0';
81-
82-
char *env = nullptr;
83-
84-
try
85-
{
86-
env = std::getenv("PROJ_LIB");
87-
}
88-
catch (const std::exception &)
89-
{
90-
env = nullptr;
91-
}
92-
93-
if (env)
94-
{
95-
std::strncpy(path, env, size - 1);
96-
length = std::min(std::strlen(env), size - 1);
97-
}
98-
}
83+
return getEnvironmentVariable("GDAL_DATA", path, size);
84+
}
9985

100-
return length;
86+
size_t PDALGetProj4DataPath(char *path, size_t size)
87+
{
88+
return getEnvironmentVariable("PROJ_LIB", path, size);
10189
}
10290

10391
void PDALSetGdalDataPath(const char *path)

tests/docker/pdalc-build-deps_alpine/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ RUN \
1111
g++ \
1212
lcov \
1313
make \
14-
cmake
14+
cmake \
15+
curl

tests/travis/script.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
gcc --version
44
g++ --version
55

6+
if [ "$DISTRO" = "ubuntu" ]; then
7+
# Download and unzip the sonarcloud build wrapper
8+
curl -LsS https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip > build-wrapper-linux-x86.zip
9+
unzip build-wrapper-linux-x86.zip
10+
export SONARCLOUD_DIR=$PWD/build-wrapper-linux-x86
11+
fi
12+
613
export CI_PROJECT_DIR=/pdalc
714
export CI_PROJECT_NAME=pdal-c
815
export TARGET_PLATFORM=$DISTRO-`uname -m`-$BUILD_TYPE
@@ -11,5 +18,10 @@ rm -rf "$CI_PROJECT_DIR/build/$TARGET_PLATFORM"
1118
mkdir -p "$CI_PROJECT_DIR/build/$TARGET_PLATFORM"
1219
cd "$CI_PROJECT_DIR/build/$TARGET_PLATFORM"
1320
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DPDALC_GCC_PARAM_GGC_MIN_HEAPSIZE=8192 "$CI_PROJECT_DIR"
14-
make
21+
22+
if [ "$DISTRO" = "ubuntu" ]; then
23+
$SONARCLOUD_DIR/build-wrapper-linux-x86-64 --out-dir $CI_PROJECT_DIR/bw-output make
24+
else
25+
make
26+
fi
1527
make coverage_pdalc

0 commit comments

Comments
 (0)