travis: improve build process and expand build matrix

Make a build heriarchy to reduce images size.
Add Android Things builds to build matrix.
Drop gcc-4 builds, use gcc-5 and gcc-6 instead.
Add SonarQube static analysis scans.

Signed-off-by: Nicolas Oliver <dario.n.oliver@intel.com>
This commit is contained in:
Nicolas Oliver
2017-07-10 07:28:18 -07:00
parent 98811b0fb7
commit ab4eeea61e
14 changed files with 722 additions and 168 deletions

125
scripts/build-android.sh Executable file
View File

@ -0,0 +1,125 @@
#!/usr/bin/env bash
set -e
export PKG_CONFIG_LIBDIR="$NDK_HOME/platforms/android-24/arch-x86/usr/lib:$MRAA_INSTALL_DIR/lib/pkgconfig/"
cmake \
-DANDROID_COMPILER_FLAGS_CXX='-std=c++11' \
-DANDROID_PIE=1 \
-DANDROID_PLATFORM=android-24 \
-DANDROID_STL_FORCE_FEATURES=ON \
-DANDROID_STL=c++_shared \
-DANDROID_TOOLCHAIN_NAME=x86-i686 \
-DCMAKE_TOOLCHAIN_FILE=$NDK_HOME/build/cmake/android.toolchain.cmake \
-DCMAKE_FIND_ROOT_PATH=$MRAA_INSTALL_DIR \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DJAVA_AWT_INCLUDE_PATH=$JAVA_HOME/include \
-DJAVA_AWT_LIBRARY=$JAVA_HOME/jre/lib/amd64/libjawt.so \
-DJAVA_INCLUDE_PATH=$JAVA_HOME/include \
-DJAVA_INCLUDE_PATH2=$JAVA_HOME/include/linux \
-DJAVA_JVM_LIBRARY=$JAVA_HOME/jre/lib/amd64/server/libjvm.so \
-DBUILDSWIGJAVA=$BUILDSWIGJAVA \
-DBUILDSWIGNODE=$BUILDSWIGNODE \
-DBUILDSWIGPYTHON=$BUILDSWIGPYTHON \
-DWERROR=$WERROR \
-H. \
-Bbuild
make -j8 -Cbuild
# Anotate the .java src from doxygen
find src/ -name "javaupm_*.i" > build/upm.i.list
# TODO: install doxy port tool
#doxyport build/upm.i.list \
# -s src/interfaces/,src/bacnetmstp,src/bmg160,src/bma250e,src/bmm150 \
# -m doxy/samples.mapping.txt \
# -d build/src/ \
# --convert-protected-to-private \
# -o build/upm-java-files.txt \
# -c build/compile_commands.json
gen_and_upload() {
# Skip any directories without .java src files
if [ ! -f *.java ]; then
return
fi
# Get the MRAA version string from the .pom file
VERSION=$(ls *.pom | perl -nle 'print $2 if /^(.*)-(\d+\.\d+\.\d+)\.pom/')
# Get the MRAA name string from the .pom file
LIB_NAME=$(ls *.pom | perl -nle 'print $1 if /^(.*)-(\d+\.\d+\.\d+)\.pom/')
# Bundle upload directory
PKG_BUNDLE_DIR=BUNDLE_DIR
mkdir -p ${PKG_BUNDLE_DIR}
# Create the aar directory structure
AAR_DIRECTORY="$LIB_NAME-$VERSION"
mkdir -p $AAR_DIRECTORY/jni/x86
mkdir -p $AAR_DIRECTORY/res/values
# Write out res/values/values.xml to the aar
echo "${values_xml/XXX_LIBRARY/$LIB_NAME}" > $AAR_DIRECTORY/res/values/values.xml
# Write out AndroidManifest.xml to the aar
_tmp_manifest=${AndroidManifest_xml/XXX_PACKAGE/$JAVA_PKG_PREFIX_DOT}
_tmp_manifest=${_tmp_manifest/XXX_LIBRARY/$LIB_NAME}
echo "${_tmp_manifest/XXX_VERSION/$VERSION}" > $AAR_DIRECTORY/AndroidManifest.xml
# Copy over the so's
cp *.so $AAR_DIRECTORY/jni/x86
# Create javadoc jar
javadoc *.java -d $LIB_NAME-javadoc
jar cf $PKG_BUNDLE_DIR/$LIB_NAME-$VERSION-javadoc.jar $LIB_NAME-javadoc/*
# Create sources jar file for upload
jar cf $PKG_BUNDLE_DIR/$LIB_NAME-$VERSION-sources.jar *.java
# Copy pom file
cp $LIB_NAME-$VERSION.pom $PKG_BUNDLE_DIR
# Copy the java module jar to classes.jar
cp $LIB_NAME.jar $AAR_DIRECTORY/classes.jar
# Create the .aar
pushd $AAR_DIRECTORY
jar cf ../$PKG_BUNDLE_DIR/$LIB_NAME-$VERSION.aar *
popd
# Create the bundle file
pushd $PKG_BUNDLE_DIR
# Create the tar bundle
jar cvf ../$LIB_NAME-$VERSION-bundle.jar *
popd
}
# Template for res/values/values.xml in aar
values_xml='<?xml version="1.0" encoding="utf-8"?><resources><string name="app_name">XXX_LIBRARY</string></resources>'
# Template for AndroidManifest.xml in aar
AndroidManifest_xml='<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="XXX_PACKAGE.XXX_LIBRARY"
android:versionCode="1"
android:versionName="XXX_VERSION" >
<uses-sdk android:minSdkVersion="23" android:targetSdkVersion="25"/>
<application android:allowBackup="true" android:label="@string/app_name" android:supportsRtl="true" />
</manifest>'
# Package prefix
JAVA_PKG_PREFIX_DOT="io.mraa.at.upm"
# Work in the UPM build directory
cd build/src
# For each directory in build/src which contains a .pom file...
for lib_dir in `ls -d */`; do
if ls $lib_dir/upm_*.pom 1> /dev/null 2>&1; then
pushd $lib_dir
# Allow for spawning multiple if necessary (&)
gen_and_upload
popd
fi
done

20
scripts/run-cmake.sh Executable file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env bash
# Run cmake
cmake \
-DSWIG_EXECUTABLE=/usr/bin/swig \
-DBUILDDOC=$BUILDDOC \
-DBUILDCPP=$BUILDCPP \
-DBUILDFTI=$BUILDFTI \
-DBUILDSWIGPYTHON=$BUILDSWIGPYTHON \
-DBUILDSWIGNODE=$BUILDSWIGNODE \
-DBUILDSWIGJAVA=$BUILDSWIGJAVA \
-DBUILDEXAMPLES=$BUILDEXAMPLES \
-DIPK=$IPK \
-DRPM=$RPM \
-DNPM=$NPM \
-DBUILDTESTS=$BUILDTESTS \
-DWERROR=$WERROR \
-H. \
-Bbuild

76
scripts/sonar-scan.sh Executable file
View File

@ -0,0 +1,76 @@
#!/bin/bash
#
# The script is used for determining options and running a static code
# analysis scan via SonarCloud.
#
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
#
# All environment variables used are passed from either Travis or docker-compose.
# See details at https://docs.sonarqube.org/display/SONAR/Analysis+Parameters.
#
# Travis ones are:
# Created by us:
# - SONAR_ORG - SonarCloud "organization", under which the project is located.
# - SONAR_PROJ_KEY - SonarCloud project key (name) to report to.
# - SONAR_TOKEN - access token for that project (must be protected in Travis).
# - GITHUB_TOKEN - GH OAuth token used by SonarCloud's GH plugin to report status in PRs.
# See details at https://docs.sonarqube.org/display/PLUG/GitHub+Plugin. Must be protected.
# Default:
# - All TRAVIS_* variables. They are described in Travis docs
# at https://docs.travis-ci.com/user/environment-variables
#
# docker-compose ones are:
# - UPM_SRC_DIR - path to upm's git clone in the Docker container.
# Check required environment variables and exit if they are not set
UPM_SRC_DIR=${UPM_SRC_DIR:?value not provided}
SONAR_PROJ_KEY=${SONAR_PROJ_KEY:?value not provided}
SONAR_ORG=${SONAR_ORG:?value not provided}
SONAR_TOKEN=${SONAR_TOKEN:?value not provided}
bw_output_path="${UPM_SRC_DIR}/build/bw-output"
sonar_cmd_base="build-wrapper-linux-x86-64 --out-dir ${bw_output_path} make clean all && \
sonar-scanner \
--debug \
-Dsonar.projectKey=${SONAR_PROJ_KEY} \
-Dsonar.projectBaseDir=${UPM_SRC_DIR} \
-Dsonar.sources=${UPM_SRC_DIR} \
-Dsonar.inclusions='api/**/*,CMakeLists.txt,examples/**/*,imraa/**/*,include/**/*,src/**/*,tests/**/*' \
-Dsonar.coverage.exclusions='**/*' \
-Dsonar.cfamily.build-wrapper-output=${bw_output_path} \
-Dsonar.host.url=https://sonarqube.com \
-Dsonar.organization=${SONAR_ORG} \
-Dsonar.login=${SONAR_TOKEN} \
"
# Some useful data for logs
echo "TRAVIS_BRANCH: ${TRAVIS_BRANCH}"
echo "TRAVIS_PULL_REQUEST: ${TRAVIS_PULL_REQUEST}"
echo "TRAVIS_PULL_REQUEST_SLUG: ${TRAVIS_PULL_REQUEST_SLUG}"
echo "TRAVIS_REPO_SLUG: ${TRAVIS_REPO_SLUG}"
if [ "${TRAVIS_BRANCH}" == "master" -a "${TRAVIS_PULL_REQUEST}" == "false" ]; then
# Master branch push - do a full-blown scan
echo "Performing master branch push scan"
sonar_cmd="${sonar_cmd_base}"
elif [ "${TRAVIS_PULL_REQUEST}" != "false" -a "${TRAVIS_PULL_REQUEST_SLUG}" == "${TRAVIS_REPO_SLUG}" ]; then
# Internal PR - do a preview scan with report to the PR
${GITHUB_TOKEN:?value not provided}
echo "Performing internal pull request scan"
sonar_cmd="${sonar_cmd_base} \
-Dsonar.analysis.mode=preview \
-Dsonar.github.pullRequest=${TRAVIS_PULL_REQUEST} \
-Dsonar.github.repository=${TRAVIS_REPO_SLUG} \
-Dsonar.github.oauth=${GITHUB_TOKEN} \
"
else
echo "Skipping the scan - external pull request or non-master branch push"
exit 0
fi
echo "About to run the scan, the command is:"
echo "${sonar_cmd}"
eval "${sonar_cmd}"