Skip to content

Commit

Permalink
ci: build examples with multiple IDF versions
Browse files Browse the repository at this point in the history
  • Loading branch information
igrr committed Jul 14, 2021
1 parent 86dade5 commit ed33103
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 101 deletions.
88 changes: 43 additions & 45 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ variables:

ESP_IDF_GIT: "https://gitlab-ci-token:${CI_JOB_TOKEN}@${GITLAB_HTTPS_SERVER}/espressif/esp-idf.git"

.setup_idf_tools: &setup_idf_tools |
cd esp-idf
# tools/idf_tools.py --non-interactive install && eval "$(tools/idf_tools.py --non-interactive export)" || exit 1

.add_gh_key_remote: &add_gh_key_remote |
command -v ssh-agent >/dev/null || exit 1
eval $(ssh-agent -s)
Expand All @@ -34,51 +30,53 @@ after_script:
# Just for cleaning space, no other causes
- git clean -ffdx

build:

# This template gets expanded multiple times, once for every IDF version.
# IDF version is specified by setting the espressif/idf image tag.
#
# EXAMPLE_TARGETS sets the list of IDF_TARGET values to build examples for.
# It should be equal to the list of targets supported by the specific IDF version.
#
# TEST_TARGETS sets the list of IDF_TARGET values to build the test_app for.
# It should contain only the targets with optimized assembly implementations.
#
.build_template:
stage: build
tags:
- build
- internet
script:
# Get ESP-IDF
- dir
- git clone ${ESP_IDF_GIT} esp-idf
- dir
- pushd esp-idf
- dir
# Non-recursive getting its submodules
- git submodule update --init
- dir
- export IDF_PATH=$PWD
- dir
#- *setup_idf_tools
- dir
- ./tools/ci/mirror-submodule-update.sh

- source /opt/pyenv/activate
- pyenv global $(pyenv versions --bare)
- ./tools/idf_tools.py --non-interactive install-python-env
- ./tools/idf_tools.py --non-interactive install

- idf_exports=$(${IDF_PATH}/tools/idf_tools.py --non-interactive export)
- eval "${idf_exports}"
- popd

# Create a copy of the project in "esp-dsp" directory.
# This is needed because CMake build system can not build a component
# when ESP-IDF directory is inside the component.
# After cloning, we will have two directories at the same level: "esp-idf" and "esp-dsp"
- git clone $PWD esp-dsp
- cd esp-dsp

# Build test app by both Makefiles and CMake ways
- pushd test_app
- make defconfig && make
- rm -rf build
- idf.py build
- popd

# Build examples
- ./build_examples.sh
- ./build_all.sh
variables:
EXAMPLE_TARGETS: "esp32"
TEST_TARGETS: "esp32"

build_idf_v4.0:
extends: .build_template
image: espressif/idf:release-v4.0

build_idf_v4.1:
extends: .build_template
image: espressif/idf:release-v4.1

build_idf_v4.2:
extends: .build_template
image: espressif/idf:release-v4.2
variables:
EXAMPLE_TARGETS: "esp32 esp32s2"

build_idf_v4.3:
extends: .build_template
image: espressif/idf:release-v4.3
variables:
EXAMPLE_TARGETS: "esp32 esp32s2"

build_idf_latest:
extends: .build_template
image: espressif/idf:latest
variables:
EXAMPLE_TARGETS: "esp32 esp32s2 esp32s3"
TEST_TARGETS: "esp32 esp32s3"

build_docs:
stage: build
Expand Down
81 changes: 81 additions & 0 deletions build_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/bash
#
# Build the test app and all examples from the examples directory.
# Expects EXAMPLE_TARGETS and TEST_TARGETS environment variables to be set.
# Each variable is the list of IDF_TARGET values to build the examples and
# the test app for, respectively.
#
# -----------------------------------------------------------------------------
# Safety settings (see https://gist.github.com/ilg-ul/383869cbb01f61a51c4d).

if [[ -n "${DEBUG_SHELL}" ]]
then
set -x # Activate the expand mode if DEBUG is anything but empty.
fi

if [[ -z "${EXAMPLE_TARGETS}" || -z "${TEST_TARGETS}" ]]
then
echo "EXAMPLE_TARGETS and TEST_TARGETS environment variables must be set before calling this script"
exit 1
fi

set -o errexit # Exit if command failed.
set -o pipefail # Exit if pipe failed.
set -o nounset # Exit if variable not set.


STARS='***************************************************'

# -----------------------------------------------------------------------------

die() {
echo "${1:-"Unknown Error"}" 1>&2
exit 1
}

# build_for_targets <target list>
# call this in the project directory
function build_for_targets
{
target_list="$1"
for IDF_TARGET in ${target_list}
do
export IDF_TARGET
if [[ "${IDF_TARGET}" = "esp32" ]]
then
echo "${STARS}"
echo "Building in $PWD with Make"
# -j option will be set via MAKEFLAGS in .gitlab-ci.yml
# shellcheck disable=SC2015
make defconfig && make || die "Make build in ${PWD} has failed"
rm -rf build
fi

echo "${STARS}"
echo "Building in $PWD with CMake for ${IDF_TARGET}"
if [[ ${IDF_TARGET} != "esp32" ]]
then
# IDF 4.0 doesn't support idf.py set-target, and only supports esp32.
idf.py set-target "${IDF_TARGET}"
fi
idf.py build || die "CMake build in ${PWD} has failed for ${IDF_TARGET}"
idf.py fullclean
done
}

# Build the test app
echo "${STARS}"
pushd test_app
build_for_targets "${TEST_TARGETS}"
popd

# Build the examples
pushd examples
EXAMPLES=$(find . -maxdepth 1 -mindepth 1 -type d | cut -d '/' -f 2)
for NAME in ${EXAMPLES}
do
pushd "${NAME}"
build_for_targets "${EXAMPLE_TARGETS}"
popd
done
popd
56 changes: 0 additions & 56 deletions build_examples.sh

This file was deleted.

0 comments on commit ed33103

Please sign in to comment.