ci: sync jenkins script and travis config with NFD

This commit also adds support for "limited-build" job type to ndn-cxx,
and enables it for travis integrations.

Change-Id: I6960b1d683c94c433ad1bfe702c4273e01036a2c
diff --git a/.jenkins.d/00-deps.sh b/.jenkins.d/00-deps.sh
index d54374b..41b93f0 100755
--- a/.jenkins.d/00-deps.sh
+++ b/.jenkins.d/00-deps.sh
@@ -4,20 +4,16 @@
 JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
 source "$JDIR"/util.sh
 
-if has OSX $NODE_LABELS; then
-    if has OSX-10.8 $NODE_LABELS; then
-        EXTRA_FLAGS=--c++11
-    fi
+set -x
 
-    set -x
+if has OSX $NODE_LABELS; then
     brew update
     brew upgrade
-    brew install boost pkg-config cryptopp openssl $EXTRA_FLAGS
+    brew install boost pkg-config cryptopp openssl
     brew cleanup
 fi
 
 if has Ubuntu $NODE_LABELS; then
-    set -x
     sudo apt-get -qq update
     sudo apt-get -qq install build-essential pkg-config libboost-all-dev \
                              libcrypto++-dev libsqlite3-dev libssl-dev
diff --git a/.jenkins.d/10-build.sh b/.jenkins.d/10-build.sh
index d99f3c3..e86ced8 100755
--- a/.jenkins.d/10-build.sh
+++ b/.jenkins.d/10-build.sh
@@ -1,10 +1,11 @@
 #!/usr/bin/env bash
-set -x
 set -e
 
 JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
 source "$JDIR"/util.sh
 
+set -x
+
 sudo rm -Rf /usr/local/include/ndn-cxx
 sudo rm -f /usr/local/lib/libndn-cxx*
 sudo rm -f /usr/local/lib/pkgconfig/libndn-cxx*
@@ -12,25 +13,27 @@
 # Cleanup
 sudo ./waf -j1 --color=yes distclean
 
-# Configure/build static library in debug mode with precompiled headers
-./waf -j1 --color=yes configure --enable-static --disable-shared --with-tests --debug
-./waf -j1 --color=yes build
+if [[ "$JOB_NAME" != *"limited-build" ]]; then
+  # Configure/build static library in optimized mode with tests
+  ./waf -j1 --color=yes configure --enable-static --disable-shared --with-tests
+  ./waf -j1 --color=yes build
 
-# Cleanup
-sudo ./waf -j1 --color=yes distclean
+  # Cleanup
+  sudo ./waf -j1 --color=yes distclean
 
-# Configure/build static and shared library in optimized mode without tests with precompiled headers
-./waf -j1 --color=yes configure --enable-shared --enable-static
-./waf -j1 --color=yes build
+  # Configure/build static and shared library in optimized mode without tests
+  ./waf -j1 --color=yes configure --enable-static --enable-shared
+  ./waf -j1 --color=yes build
 
-# Cleanup
-sudo ./waf -j1 --color=yes distclean
+  # Cleanup
+  sudo ./waf -j1 --color=yes distclean
+fi
 
-# Configure/build shared library in debug mode with examples without precompiled headers
+# Configure/build shared library in debug mode with tests/examples and without precompiled headers
 if [[ "$JOB_NAME" == *"code-coverage" ]]; then
     COVERAGE="--with-coverage"
 fi
-./waf -j1 --color=yes configure --debug --enable-shared --disable-static --with-tests --without-pch --with-examples $COVERAGE
+./waf -j1 --color=yes configure --disable-static --enable-shared --debug --with-tests --with-examples --without-pch $COVERAGE
 ./waf -j1 --color=yes build
 
 # (tests will be run against debug version)
diff --git a/.jenkins.d/20-tests.sh b/.jenkins.d/20-tests.sh
index ec0f855..f0583ca 100755
--- a/.jenkins.d/20-tests.sh
+++ b/.jenkins.d/20-tests.sh
@@ -1,38 +1,37 @@
 #!/usr/bin/env bash
-set -x
 set -e
 
 JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
 source "$JDIR"/util.sh
 
+set -x
+
 # Prepare environment
 rm -Rf ~/.ndn
 
 if has OSX $NODE_LABELS; then
-    echo "Unlocking OSX Keychain"
-    security unlock-keychain -p "named-data"
+    security unlock-keychain -p named-data
 fi
 
 ndnsec-keygen "/tmp/jenkins/$NODE_NAME" | ndnsec-install-cert -
 
 BOOST_VERSION=$(python -c "import sys; sys.path.append('build/c4che'); import _cache; print(_cache.BOOST_VERSION_NUMBER);")
 
-if (( BOOST_VERSION < 106200 )); then
-    if [[ -n "$XUNIT" ]]; then
-        UNIT_TEST_PARAMS1="--log_level=all"
-        UNIT_TEST_PARAMS2="--log_format2=XML --log_sink2=build/xunit-report.xml"
-        if (( BOOST_VERSION < 106000 )); then
-            UNIT_TEST_PARAMS="$UNIT_TEST_PARAMS1 $UNIT_TEST_PARAMS2"
-        else
-            UNIT_TEST_PARAMS="$UNIT_TEST_PARAMS1 -- $UNIT_TEST_PARAMS2"
-        fi
+ut_log_args() {
+    ((ut_count+=1))
+    if (( BOOST_VERSION >= 106200 )); then
+        echo --logger=HRF,test_suite,stdout:XML,all,build/xunit-report-${ut_count}.xml
     else
-        UNIT_TEST_PARAMS="--log_level=test_suite"
+        if [[ -n $XUNIT ]]; then
+            echo --log_level=all $( (( BOOST_VERSION >= 106000 )) && echo -- ) \
+                 --log_format2=XML --log_sink2=build/xunit-report-${ut_count}.xml
+        else
+            echo --log_level=test_suite
+        fi
     fi
-else
-    UNIT_TEST_PARAMS="--logger=HRF,test_suite,stdout:XML,all,build/xunit-report.xml"
-fi
-
+}
 
 # Run unit tests
-./build/unit-tests $UNIT_TEST_PARAMS
+./build/unit-tests $(ut_log_args)
+
+unset ut_count
diff --git a/.jenkins.d/30-coverage.sh b/.jenkins.d/30-coverage.sh
index e6ecdf3..dbc8025 100755
--- a/.jenkins.d/30-coverage.sh
+++ b/.jenkins.d/30-coverage.sh
@@ -1,11 +1,15 @@
 #!/usr/bin/env bash
-set -x
 set -e
 
 JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
 source "$JDIR"/util.sh
 
-if [[ "$JOB_NAME" == *"code-coverage" ]]; then
-  BASE="`pwd | sed -e 's|/|\\\/|g'`\\"
-  (cd build && gcovr -x -f $BASE/src -r ../ -o coverage.xml -b ./)
+set -x
+
+if [[ $JOB_NAME == *"code-coverage" ]]; then
+    gcovr --object-directory=build \
+          --output=build/coverage.xml \
+          --filter="$PWD/src" \
+          --root=. \
+          --xml
 fi
diff --git a/.jenkins.d/README.md b/.jenkins.d/README.md
index 4720a52..db4b6c0 100644
--- a/.jenkins.d/README.md
+++ b/.jenkins.d/README.md
@@ -27,4 +27,5 @@
   Possible values:
 
   * empty: default build process
-  * `<any-string-with-extra-job-description>code-coverage` (Linux OS is assumed): build process with code coverage analysis
+  * `code-coverage` (Linux OS is assumed): build process with code coverage analysis
+  * `limited-build`: only a single build with tests
diff --git a/.jenkins.d/util.sh b/.jenkins.d/util.sh
old mode 100755
new mode 100644
index 81c8931..a89bc27
--- a/.jenkins.d/util.sh
+++ b/.jenkins.d/util.sh
@@ -1,9 +1,18 @@
 has() {
+    local saved_xtrace
+    [[ $- == *x* ]] && saved_xtrace=-x || saved_xtrace=+x
+    set +x
+
     local p=$1
     shift
-    local x
-    for x in "$@"; do
-        [[ "${x}" == "${p}" ]] && return 0
+    local i ret=1
+    for i in "$@"; do
+        if [[ "${i}" == "${p}" ]]; then
+            ret=0
+            break
+        fi
     done
-    return 1
+
+    set ${saved_xtrace}
+    return ${ret}
 }