diff options
Diffstat (limited to 'dist/travis')
-rwxr-xr-x | dist/travis/build.sh | 146 | ||||
-rwxr-xr-x | dist/travis/test.sh | 116 | ||||
-rwxr-xr-x | dist/travis/travis-ci.sh | 131 | ||||
-rw-r--r-- | dist/travis/travis-utils.sh | 23 |
4 files changed, 416 insertions, 0 deletions
diff --git a/dist/travis/build.sh b/dist/travis/build.sh new file mode 100755 index 000000000..297a8561b --- /dev/null +++ b/dist/travis/build.sh @@ -0,0 +1,146 @@ +#! /bin/bash + +scriptdir=$(dirname $0) + +. "$scriptdir/travis-utils.sh" +. "$scriptdir/../ansi_color.sh" +disable_color + +echo "$0" "$@" + +# Stop in case of error +set -e + +# Transform long options to short ones +for arg in "$@"; do + shift + case "$arg" in + "--color"|"-color") set -- "$@" "-c";; + "--build"|"-build") set -- "$@" "-b";; + "--pkg"|"-pkg") set -- "$@" "-p";; + "--gpl"|"-gpl") set -- "$@" "-g";; + *) set -- "$@" "$arg" + esac +done +# Parse args +while getopts ":b:p:cg" opt; do + case $opt in + c) enable_color;; + b) BLD=$OPTARG ;; + p) PKG_NAME=$OPTARG;; + g) ISGPL=true;; + \?) printf "$ANSI_RED[GHDL - build] Invalid option: -$OPTARG $ANSI_NOCOLOR\n" >&2 + exit 1 ;; + :) printf "$ANSI_RED[GHDL - build] Option -$OPTARG requires an argument. $ANSI_NOCOLOR\n" >&2 + exit 1 ;; + esac +done + +rm -f build_ok + +#--- Env + +echo "travis_fold:start:env.docker" +printf "$ANSI_YELLOW[Info] Environment $ANSI_NOCOLOR\n" +env +echo "travis_fold:end:env.docker" + +#--- GPL: gpl-ize sources + +if [ "$ISGPL" = "true" ]; then + echo "travis_fold:start:gpl.src" + printf "$ANSI_YELLOW[Source] create GPL sources $ANSI_NOCOLOR\n" + files=`echo *` + make -f Makefile.in srcdir=. clean-pure-gpl + mkdir ${PKG_NAME} + cp -pdrl $files ${PKG_NAME} + tar -zcf "${PKG_NAME}.tar.gz" ${PKG_NAME} + PKG_NAME="${PKG_NAME}-${BLD}" + echo "travis_fold:end:gpl.src" +fi + +#--- Configure + +echo "travis_fold:start:configure" +printf "$ANSI_YELLOW[GHDL - build] Configure $ANSI_NOCOLOR\n" + +CDIR=$(pwd) +export prefix="$CDIR/install-$BLD" +mkdir "$prefix" +mkdir "build-$BLD" +cd "build-$BLD" + +case "$BLD" in + mcode) + config_opts="" + CXX="" + ;; + llvm) + CXX="clang" + config_opts="--with-llvm-config CXX=$CXX" + ;; + llvm-3.5) + CXX="clang++" + config_opts="--with-llvm-config=llvm-config-3.5 CXX=$CXX" + ;; + llvm-3.8) + CXX="clang++-3.8" + config_opts="--with-llvm-config=llvm-config-3.8 CXX=$CXX" + ;; + llvm-3.9) + CXX="clang++-3.9" + config_opts="--with-llvm-config=llvm-config-3.9 CXX=$CXX" + ;; + llvm-4.0) + CXX="clang++-4.0" + config_opts="--with-llvm-config=llvm-config-4.0 CXX=$CXX" + ;; + llvm-5.0) + CXX="clang++-5.0" + config_opts="--with-llvm-config=llvm-config-5.0 CXX=$CXX" + ;; + *) + echo "$ANSI_RED[GHDL - build] Unknown build $BLD $ANSI_NOCOLOR" + exit 1;; +esac +echo "../configure --prefix=$prefix $config_opts" +../configure "--prefix=$prefix" $config_opts +echo "travis_fold:end:configure" + +#--- make + +echo "travis_fold:start:make" +travis_time_start +printf "$ANSI_YELLOW[GHDL - build] Make $ANSI_NOCOLOR\n" +make +travis_time_finish +echo "travis_fold:end:make" + +echo "travis_fold:start:install" +printf "$ANSI_YELLOW[GHDL - build] Install $ANSI_NOCOLOR\n" +make install +cd .. +echo "travis_fold:end:install" + +#--- package + +echo "travis_fold:start:tar.bin" +printf "$ANSI_YELLOW[GHDL - build] Create package ${ANSI_DARKCYAN}${PKG_NAME}.tgz $ANSI_NOCOLOR\n" +tar -zcvf "${PKG_NAME}.tgz" -C "$prefix" . +echo "travis_fold:end:tar.bin" + +#--- build tools versions + +{ + make --version | grep 'Make' + gnatls --version | grep 'GNATLS' + gcc --version | grep 'gcc' + if [ "$CXX" != "" ]; then + $CXX --version | grep 'clang' + fi +} > BUILD_TOOLS + +#--- + +echo "[SUCCESSFUL]" +touch build_ok diff --git a/dist/travis/test.sh b/dist/travis/test.sh new file mode 100755 index 000000000..c588f01dc --- /dev/null +++ b/dist/travis/test.sh @@ -0,0 +1,116 @@ +#! /bin/bash + +scriptdir=$(dirname $0) + +. "$scriptdir/travis-utils.sh" +. "$scriptdir/../ansi_color.sh" +disable_color + +echo "$0" "$@" + +# Stop in case of error +set -e + +# Transform long options to short ones +for arg in "$@"; do + shift + case "$arg" in + "--color"|"-color") set -- "$@" "-c";; + "--gpl"|"-gpl") set -- "$@" "-g";; + *) set -- "$@" "$arg" + esac +done +# Parse args +while getopts ":b:p:cg" opt; do + case $opt in + c) enable_color;; + g) ISGPL=true;; + \?) printf "$ANSI_RED[GHDL - test] Invalid option: -$OPTARG $ANSI_NOCOLOR\n" >&2 + exit 1 ;; + :) printf "$ANSI_RED[GHDL - test] Option -$OPTARG requires an argument. $ANSI_NOCOLOR\n" >&2 + exit 1 ;; + esac +done + +rm -f test_ok + +export ENABLECOLOR +if [ "$GHDL" = "" ]; then + export GHDL="$prefix/bin/ghdl" +fi +cd testsuite +failures="" + +echo "travis_fold:start:tests.sanity" +travis_time_start +printf "$ANSI_YELLOW[GHDL - test] sanity $ANSI_NOCOLOR\n" +cd sanity +for d in [0-9]*; do + cd $d + if ./testsuite.sh > test.log 2>&1 ; then + echo "sanity $d: ok" + # Don't disp log + else + echo "${ANSI_RED}sanity $d: failed${ANSI_NOCOLOR}" + cat test.log + failures="$failures $d" + fi + cd .. + # Stop at the first failure + [ "$failures" = "" ] || break +done +cd .. +travis_time_finish +echo "travis_fold:end:tests.sanity" +[ "$failures" = "" ] || exit 1 + +if [ "$ISGPL" != "true" ]; then + echo "travis_fold:start:tests.gna" + travis_time_start + printf "$ANSI_YELLOW[GHDL - test] gna $ANSI_NOCOLOR\n" + cd gna + dirs=`./testsuite.sh --list-tests` + for d in $dirs; do + cd $d + if ./testsuite.sh > test.log 2>&1 ; then + echo "gna $d: ok" + # Don't disp log + else + echo "${ANSI_RED}gna $d: failed${ANSI_NOCOLOR}" + cat test.log + failures="$failures $d" + fi + cd .. + # Stop at the first failure + [ "$failures" = "" ] || break + done + cd .. + travis_time_finish + echo "travis_fold:end:tests.gna" + [ "$failures" = "" ] || exit 1 +fi + +echo "travis_fold:start:tests.vests" +travis_time_start +printf "$ANSI_YELLOW[GHDL - test] vests $ANSI_NOCOLOR\n" +cd vests +if ./testsuite.sh > vests.log 2>&1 ; then + echo "${ANSI_GREEN}Vests is OK$ANSI_NOCOLOR" + wc -l vests.log +else + cat vests.log + echo "${ANSI_RED}Vests failure$ANSI_NOCOLOR" + failures=vests +fi +cd .. +travis_time_finish +echo "travis_fold:end:tests.vests" +[ "$failures" = "" ] || exit 1 + +$GHDL --version +cd .. + +#--- + +echo "[SUCCESSFUL]" +touch test_ok diff --git a/dist/travis/travis-ci.sh b/dist/travis/travis-ci.sh new file mode 100755 index 000000000..628acceaf --- /dev/null +++ b/dist/travis/travis-ci.sh @@ -0,0 +1,131 @@ +#! /bin/bash +# This script is executed in the travis-ci environment. + +build_img_ghdl() { + # Build ghdl/ghdl from ghdl/run + echo "travis_fold:start:build_run" + travis_time_start + printf "$ANSI_BLUE[DOCKER build] ghdl : ${IMAGE_TAG}$ANSI_NOCOLOR\n" + + PKG=`ls | grep -oP 'ghdl-.*tgz'` + mkdir tmp-img && cd tmp-img + cp ../$PKG ./ + cp ../BUILD_TOOLS ./ + echo "FROM ghdl/run:$IMAGE_TAG" > Dockerfile + echo "ADD $PKG /usr/local" >> Dockerfile + docker build -t ghdl/ghdl:$IMAGE_TAG . + cd .. + travis_time_finish + echo "travis_fold:end:build_run" +} + +#--- + +set -e + +scriptdir=$(dirname $0) + +. "$scriptdir/travis-utils.sh" +. "$scriptdir/../ansi_color.sh" +#disable_color + +# Display env (to debug) + +echo -en "travis_fold:start:travis_env\r" +printf "$ANSI_YELLOW[TRAVIS] Travis environment $ANSI_NOCOLOR\n" +env | grep TRAVIS +echo -en "travis_fold:end:travis_env\r" + + +if [ "$IMAGE" = "" ]; then + echo "IMAGE not defined" + exit 1 +fi + + +echo "travis_fold:start:fetch" +# The command 'git describe' (used for version) needs the history. Get it. +# But the following command fails if the repository is complete. +git fetch --unshallow || true + +echo "travis_fold:end:fetch" + + +# Compute package name + +PKG_SHORTCOMMIT="$(printf $TRAVIS_COMMIT | cut -c1-10)" +PKG_VER=`grep "ghdl_version=" configure | sed -e 's/.*"\(.*\)";/\1/'` +if [ -z "$TRAVIS_TAG" ]; then + # No tag: use date + commit id + PKG_TAG="$(date -u +%Y%m%d)-$PKG_SHORTCOMMIT"; +elif expr "$TRAVIS_TAG" : 'v[0-9].*' > /dev/null; then + # Remove leading 'v' in tags in the filenames. + PKG_TAG="$(echo $TRAVIS_TAG | cut -c2-)" +else + # Regular tag (like snapshots), nothing to change. + PKG_TAG="$TRAVIS_TAG" +fi + +# Extract from IMAGE (defined in .travis.yml) +IFS='+' read -ra REFS <<< "$IMAGE" +DDIST=${REFS[0]} # Linux distro (eg: ubuntuXX, fedoraXX) +DBLD=${REFS[1]} # Build/backend (eg: mcode, llvm) +DGPL=${REFS[2]} # GPL or not + +PKG_NAME="ghdl-${PKG_TAG}-${DDIST}-${DBLD}" +BUILD_CMD_OPTS="$ENABLECOLOR -b $DBLD" +if [ "$DGPL" = "gpl" ]; then + BUILD_CMD_OPTS="$BUILD_CMD_OPTS --gpl" + PKG_NAME="ghdl-gpl-${PKG_TAG}" +fi +BUILD_CMD_OPTS="${BUILD_CMD_OPTS} -p $PKG_NAME" + +echo "build cmd: $BUILD_CMD_OPTS" + + +# Build + +if [ "$TRAVIS_OS_NAME" = "osx" ]; then + # Install gnat compiler (use cache) + ./dist/macosx/install-ada.sh || exit 1 + PATH=$PWD/gnat/bin:$PATH + + bash -c "${scriptdir}/build.sh $BUILD_CMD_OPTS" +else + # Assume linux + + # Build version.tmp and replace version.in with it (so that the version is + # correctly set). + # This is a little bit hack-ish, as it assumes that 'git' is not + # available in docker (otherwise it will describe as -dirty + # because this modifies the source file version.in). + ghdl_version_line=`grep -e '^ghdl_version' configure` + make -f Makefile.in srcdir=. $ghdl_version_line version.tmp + cp version.tmp src/version.in + + # Run build in docker + IMAGE_TAG=`echo $IMAGE | sed -e 's/+/-/g'` + docker run --rm -t -v $(pwd):/work -w "/work" ghdl/build:$IMAGE_TAG bash -c "${scriptdir}/build.sh $BUILD_CMD_OPTS" +fi + +if [ ! -f build_ok ]; then + printf "$ANSI_RED[TRAVIS] BUILD failed $ANSI_NOCOLOR\n" + exit 1 +fi + + +# Test + +if [ "$TRAVIS_OS_NAME" = "osx" ]; then + bash -c "prefix=$(realpath ./install-mcode) ${scriptdir}/test.sh $BUILD_CMD_OPTS" +else + # Build ghdl/ghdl:$IMAGE_TAG image + build_img_ghdl + # Run test in docker container + docker run --rm -t -v $(pwd):/work -w "/work" ghdl/ghdl:$IMAGE_TAG bash -c "GHDL=ghdl ${scriptdir}/test.sh $BUILD_CMD_OPTS" +fi + +if [ ! -f test_ok ]; then + printf "$ANSI_RED[TRAVIS] TEST failed $ANSI_NOCOLOR\n" + exit 1 +fi diff --git a/dist/travis/travis-utils.sh b/dist/travis/travis-utils.sh new file mode 100644 index 000000000..8db013f7b --- /dev/null +++ b/dist/travis/travis-utils.sh @@ -0,0 +1,23 @@ +# This is a trimmed down copy of +# https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/templates/header.sh +travis_time_start() { + # `date +%N` returns the date in nanoseconds. It is used as a replacement for $RANDOM, which is only available in bash. + travis_timer_id=`date +%N` + travis_start_time=$(travis_nanoseconds) + echo "travis_time:start:$travis_timer_id" +} +travis_time_finish() { + travis_end_time=$(travis_nanoseconds) + local duration=$(($travis_end_time-$travis_start_time)) + echo "travis_time:end:$travis_timer_id:start=$travis_start_time,finish=$travis_end_time,duration=$duration" +} + +if [ "$TRAVIS_OS_NAME" = "osx" ]; then + travis_nanoseconds() { + date -u '+%s000000000' + } +else + travis_nanoseconds() { + date -u '+%s%N' + } +fi |