]> granicus.if.org Git - esp-idf/commitdiff
CI: Fix build_examples to cover the deep hierarchy examples
authorAnton Maklakov <anton@espressif.com>
Tue, 6 Jun 2017 10:26:31 +0000 (18:26 +0800)
committerAnton Maklakov <anton@espressif.com>
Fri, 9 Jun 2017 05:24:39 +0000 (13:24 +0800)
    Now we have 57 building examples against 49 before.

    Also, a short message prints at the end of the job for found warnings.

.gitlab-ci.yml
make/build_examples.sh

index 3035095bc98c09249b678841c515afb306d16e78..9a9099fe165b49861a1311de297e6b3c44342256 100644 (file)
@@ -117,7 +117,9 @@ build_examples:
       - build_examples/*/*/*/build/*.map
       - build_examples/*/*/*/build/bootloader/*.bin
     expire_in: 6 mos
-
+  variables:
+    IDF_PATH: "$CI_PROJECT_DIR"
+    IDF_CI_BUILD: "1"
   script:
     # it's not possible to build 100% out-of-tree and have the "artifacts"
     # mechanism work, but this is the next best thing
index ee429309e173555d0ff18ff8a0fa089a1be211bc..6646c58874d2968b621681607c69a5b6bd779375 100755 (executable)
@@ -17,46 +17,63 @@ RESULT=0
 FAILED_EXAMPLES=""
 
 RESULT_WARNINGS=22  # magic number result code for "warnings found"
+LOG_WARNINGS=$(mktemp -t example_all.XXXX.log)
 
-# traverse categories
-for category in ${IDF_PATH}/examples/*; do
-    # traverse examples within each category
-    for example in ${category}/*; do
-        [ -f ${example}/Makefile ] || continue
-        echo "Building ${example} as ${EXAMPLE_NUM}..."
-        mkdir -p example_builds/${EXAMPLE_NUM}
-        cp -r ${example} example_builds/${EXAMPLE_NUM}
-        pushd example_builds/${EXAMPLE_NUM}/`basename ${example}`
+build_example () {
+    local MAKE_FILE=$1
+    shift
 
+    local EXAMPLE_DIR=$(dirname "${MAKE_FILE}")
+    local EXAMPLE_NAME=$(basename "${EXAMPLE_DIR}")
+
+    echo "Building ${EXAMPLE_NAME} as ${EXAMPLE_NUM}..."
+    mkdir -p "example_builds/${EXAMPLE_NUM}"
+    cp -r "${EXAMPLE_DIR}" "example_builds/${EXAMPLE_NUM}"
+    pushd "example_builds/${EXAMPLE_NUM}/${EXAMPLE_NAME}"
         # be stricter in the CI build than the default IDF settings
         export EXTRA_CFLAGS="-Werror -Werror=deprecated-declarations"
         export EXTRA_CXXFLAGS=${EXTRA_CFLAGS}
 
         # build non-verbose first
-        BUILDLOG=$(mktemp -t examplebuild.XXXX.log)
+        local BUILDLOG=$(mktemp -t examplebuild.XXXX.log)
         (
             set -o pipefail  # so result of make all isn't lost when piping to tee
             set -e
             make clean defconfig
-            make $* all 2>&1 | tee $BUILDLOG
-        ) || { RESULT=$?; FAILED_EXAMPLES+=" ${example}"; make V=1; } # verbose output for errors
-        popd
-        EXAMPLE_NUM=$(( $EXAMPLE_NUM + 1 ))
-
-        if grep -q ": warning:" $BUILDLOG; then
-            [ $RESULT -eq 0 ] && RESULT=$RESULT_WARNINGS
-            FAILED_EXAMPLES+=" ${example} (warnings)"
-        fi
-
-        rm -f $BUILDLOG
-    done
+            make $* all 2>&1 | tee "${BUILDLOG}"
+        ) || { RESULT=$?; FAILED_EXAMPLES+=" ${EXAMPLE_NAME}"; make V=1; } # verbose output for errors
+    popd
+
+    EXAMPLE_NUM=$(( $EXAMPLE_NUM + 1 ))
+
+    if grep ": warning:" "${BUILDLOG}" 2>&1 >> "${LOG_WARNINGS}"; then
+        [ $RESULT -eq 0 ] && RESULT=$RESULT_WARNINGS
+        FAILED_EXAMPLES+=" ${EXAMPLE_NAME} (warnings)"
+    fi
+
+    grep -i error "${BUILDLOG}" 2>&1 >> "${LOG_WARNINGS}"
+
+    rm -f "${BUILDLOG}"
+}
+
+find ${IDF_PATH}/examples/ -type f -name Makefile | \
+while read fn
+do
+    build_example "$fn" $*
 done
 
+# show warnings
+echo -e "\nFound issues:"
+# pattern is: not 'error.o' and not '-Werror'
+grep -v "error.o\|\-Werror" -- "${LOG_WARNINGS}"
+rm -f "${LOG_WARNINGS}"
+
 if [ $RESULT -eq $RESULT_WARNINGS ]; then
     echo "Build would have passed, except for warnings."
 fi
 
 [ $RESULT -eq 0 ] || echo "Failed examples: $FAILED_EXAMPLES"
 
-exit $RESULT
+echo -e "\nResult = $RESULT"
 
+exit $RESULT