1.build_template:
2  stage: build
3  image: $CI_DOCKER_REGISTRY/esp32-ci-env$BOT_DOCKER_IMAGE_TAG
4  tags:
5    - build
6  variables:
7    SIZE_INFO_LOCATION: "$CI_PROJECT_DIR/size_info.txt"
8  dependencies: []
9
10.build_template_app_template:
11  extends:
12    - .build_template
13    - .rules:labels:build
14  variables:
15    LOG_PATH: "${CI_PROJECT_DIR}/log_template_app"
16    BUILD_PATH: "${CI_PROJECT_DIR}/build_template_app"
17    BUILD_DIR: "@t/@w"
18    BUILD_LOG_MAKE: "${LOG_PATH}/make_@t_@w.txt"
19    BUILD_LOG_CMAKE: "${LOG_PATH}/cmake_@t_@w.txt"
20    BUILD_COMMAND_ARGS: ""
21  artifacts:
22    when: always
23    paths:
24      - log_template_app/*
25      - size_info.txt
26      - build_template_app/**/size.json
27  script:
28    # Set the variable for 'esp-idf-template' testing
29    - ESP_IDF_TEMPLATE_GIT=${ESP_IDF_TEMPLATE_GIT:-"https://github.com/espressif/esp-idf-template.git"}
30    - retry_failed git clone ${ESP_IDF_TEMPLATE_GIT}
31    # Try to use the same branch name for esp-idf-template that we're
32    # using on esp-idf. If it doesn't exist then just stick to the default branch
33    - python $CHECKOUT_REF_SCRIPT esp-idf-template esp-idf-template
34    - export PATH="$IDF_PATH/tools:$PATH"
35    - export EXTRA_CFLAGS=${PEDANTIC_CFLAGS}
36    - export EXTRA_CXXFLAGS=${PEDANTIC_CXXFLAGS}
37    # Only do the default cmake build for each target, remaining part are done in the build_template_app job
38    - tools/ci/build_template_app.sh ${BUILD_COMMAND_ARGS}
39    # Check if there are any stray printf/ets_printf references in WiFi libs
40    - cd components/esp_wifi/lib
41    - for dir in esp32 esp32s2; do test $(xtensa-esp32-elf-nm $dir/*.a | grep -w printf | wc -l) -eq 0; done;
42    - for dir in esp32 esp32s2; do test $(xtensa-esp32-elf-nm $dir/*.a | grep -w ets_printf | wc -l) -eq 0; done;
43
44# build-related-pre-check-jobs ------------------------------------------------
45# Build at least one project for each target at earliest stage to reduce build cost for obvious failing commits
46fast_template_app:
47  extends:
48    - .build_template_app_template
49    - .rules:build_tests:target_test-weekend_test
50  stage: pre_check
51  variables:
52    BUILD_COMMAND_ARGS: "-p"
53
54check_docs_gh_links:
55  extends: .build_docs_template
56  stage: pre_check
57  variables:
58    SUBMODULES_TO_FETCH: "none"
59  script:
60    - cd docs
61    - ${IDF_PATH}/tools/ci/multirun_with_pyenv.sh -p 3.6.10 pip install -r requirements.txt
62    - ${IDF_PATH}/tools/ci/multirun_with_pyenv.sh -p 3.6.10 ./build_docs.py gh-linkcheck
63#------------------------------------------------------------------------------
64
65.build_ssc_template:
66  extends:
67    - .build_template
68    - .rules:build_tests:integration_test
69  artifacts:
70    paths:
71      - SSC/ssc_bin
72    expire_in: 1 week
73  script:
74    - retry_failed git clone $SSC_REPOSITORY
75    - python $CHECKOUT_REF_SCRIPT SSC SSC
76    - cd SSC
77    - MAKEFLAGS= ./ci_build_ssc.sh $TARGET_NAME
78
79build_ssc_esp32:
80  extends: .build_ssc_template
81  parallel: 3
82  variables:
83    TARGET_NAME: "ESP32"
84
85build_ssc_esp32s2:
86  extends: .build_ssc_template
87  parallel: 2
88  variables:
89    TARGET_NAME: "ESP32S2"
90
91build_ssc_esp32c3:
92  extends: .build_ssc_template
93  parallel: 3
94  variables:
95    TARGET_NAME: "ESP32C3"
96
97.build_esp_idf_tests_cmake:
98  extends:
99    - .build_template
100    - .rules:build_tests:unit_test
101  dependencies:  # set dependencies to null to avoid missing artifacts issue
102  needs:
103    - job: fast_template_app
104      artifacts: false
105    - scan_tests
106  artifacts:
107    paths:
108      - tools/unit-test-app/output/${IDF_TARGET}
109      - tools/unit-test-app/builds/*.json
110      - tools/unit-test-app/builds/${IDF_TARGET}/*/size.json
111      - components/idf_test/unit_test/*.yml
112      - $LOG_PATH
113      - $SIZE_INFO_LOCATION
114    when: always
115    expire_in: 4 days
116  variables:
117    LOG_PATH: "$CI_PROJECT_DIR/log_ut_cmake"
118    BUILD_PATH: ${CI_PROJECT_DIR}/tools/unit-test-app/builds
119    OUTPUT_PATH: ${CI_PROJECT_DIR}/tools/unit-test-app/output
120    BUILD_SYSTEM: "cmake"
121    TEST_TYPE: "unit_test"
122    PYTHON_VER: 3
123    LDGEN_CHECK_MAPPING: 1
124  script:
125    - ${IDF_PATH}/tools/ci/find_apps_build_apps.sh
126    - cd $CI_PROJECT_DIR/tools/unit-test-app
127    - python tools/UnitTestParser.py ${BUILD_PATH}
128
129build_esp_idf_tests_cmake_esp32:
130  extends: .build_esp_idf_tests_cmake
131  variables:
132    IDF_TARGET: esp32
133
134build_esp_idf_tests_cmake_esp32s2:
135  extends: .build_esp_idf_tests_cmake
136  variables:
137    IDF_TARGET: esp32s2
138
139build_esp_idf_tests_cmake_esp32s3:
140  extends: .build_esp_idf_tests_cmake
141  variables:
142    IDF_TARGET: esp32s3
143
144build_esp_idf_tests_cmake_esp32c3:
145  extends: .build_esp_idf_tests_cmake
146  variables:
147    IDF_TARGET: esp32c3
148
149.build_examples_template:
150  extends:
151    - .build_template
152    - .rules:build_tests:example_test-weekend_test
153  dependencies:  # set dependencies to null to avoid missing artifacts issue
154  needs:
155    - job: fast_template_app
156      artifacts: false
157    - scan_tests
158  variables:
159    TEST_PREFIX: examples
160    TEST_RELATIVE_DIR: examples
161    SCAN_TEST_JSON: ${CI_PROJECT_DIR}/${TEST_RELATIVE_DIR}/test_configs/scan_${IDF_TARGET}_${BUILD_SYSTEM}.json
162    TEST_TYPE: example_test
163    LOG_PATH: ${CI_PROJECT_DIR}/log_${TEST_PREFIX}
164    BUILD_PATH: ${CI_PROJECT_DIR}/build_${TEST_PREFIX}
165    PYTHON_VER: 3
166    LDGEN_CHECK_MAPPING: 1
167  script:
168    # it's not possible to build 100% out-of-tree and have the "artifacts"
169    # mechanism work, but this is the next best thing
170    - ${IDF_PATH}/tools/ci/find_apps_build_apps.sh
171
172build_examples_make:
173  extends:
174    - .build_examples_template
175  # This is a workaround for a rarely encountered issue with building examples in CI.
176  # Probably related to building of Kconfig in 'make clean' stage
177  retry: 1
178  parallel: 8
179  artifacts:
180    paths:
181      - $LOG_PATH
182      - build_${TEST_PREFIX}/*/*/*/build/size.json
183      - $SIZE_INFO_LOCATION
184    when: always
185    expire_in: 4 days
186  variables:
187    BUILD_SYSTEM: make
188    IDF_TARGET: esp32  # currently we only support esp32
189
190# same as above, but for CMake
191.build_examples_cmake:
192  extends: .build_examples_template
193  artifacts:
194    paths:
195      - build_${TEST_PREFIX}/list.json
196      - build_${TEST_PREFIX}/list_job_*.json
197      - build_${TEST_PREFIX}/*/*/*/sdkconfig
198      - build_${TEST_PREFIX}/*/*/*/build/size.json
199      - build_${TEST_PREFIX}/*/*/*/build/*.bin
200      - build_${TEST_PREFIX}/*/*/*/build/*.elf
201      - build_${TEST_PREFIX}/*/*/*/build/*.map
202      - build_${TEST_PREFIX}/*/*/*/build/flasher_args.json
203      - build_${TEST_PREFIX}/*/*/*/build/bootloader/*.bin
204      - build_${TEST_PREFIX}/*/*/*/build/partition_table/*.bin
205      - $LOG_PATH
206      - $SIZE_INFO_LOCATION
207    when: always
208    expire_in: 4 days
209  variables:
210    BUILD_SYSTEM: cmake
211
212build_examples_cmake_esp32:
213  extends: .build_examples_cmake
214  parallel: 10
215  variables:
216    IDF_TARGET: esp32
217
218build_examples_cmake_esp32s2:
219  extends: .build_examples_cmake
220  parallel: 8
221  variables:
222    IDF_TARGET: esp32s2
223
224build_examples_cmake_esp32c3:
225  extends: .build_examples_cmake
226  parallel: 8
227  variables:
228    IDF_TARGET: esp32c3
229
230.build_test_apps:
231  extends:
232    - .build_examples_cmake
233    - .rules:build_tests:custom_test-weekend_test
234  variables:
235    TEST_PREFIX: test_apps
236    TEST_RELATIVE_DIR: tools/test_apps
237    TEST_TYPE: custom_test
238  script:
239    - ${IDF_PATH}/tools/ci/find_apps_build_apps.sh
240
241build_test_apps_esp32:
242  extends: .build_test_apps
243  parallel: 8
244  variables:
245    IDF_TARGET: esp32
246
247build_test_apps_esp32s2:
248  extends: .build_test_apps
249  parallel: 8
250  variables:
251    IDF_TARGET: esp32s2
252
253build_test_apps_esp32s3:
254  extends: .build_test_apps
255  parallel: 8
256  variables:
257    IDF_TARGET: esp32s3
258
259build_test_apps_esp32c3:
260  extends: .build_test_apps
261  parallel: 8
262  variables:
263    IDF_TARGET: esp32c3
264
265.build_component_ut:
266  extends:
267    - .build_test_apps
268    - .rules:build_tests:unit_test
269  variables:
270    TEST_PREFIX: component_ut
271    TEST_RELATIVE_DIR: component_ut
272
273build_component_ut_esp32:
274  extends: .build_component_ut
275  variables:
276    IDF_TARGET: esp32
277
278build_component_ut_esp32s2:
279  extends: .build_component_ut
280  variables:
281    IDF_TARGET: esp32s2
282
283build_component_ut_esp32c3:
284  extends: .build_component_ut
285  variables:
286    IDF_TARGET: esp32c3
287
288.build_docs_template:
289  stage: build
290  image: $ESP_IDF_DOC_ENV_IMAGE
291  tags:
292    - build_docs
293  script:
294    - cd docs
295    - ${IDF_PATH}/tools/ci/multirun_with_pyenv.sh -p 3.6.10 pip install -r requirements.txt
296    - ${IDF_PATH}/tools/ci/multirun_with_pyenv.sh -p 3.6.10 ./build_docs.py -bs $DOC_BUILDERS -l $DOCLANG -t $DOCTGT build
297  parallel:
298    matrix:
299      - DOCLANG: [ "en", "zh_CN" ]
300        DOCTGT: [ "esp32", "esp32s2",  "esp32c3"]
301
302build_docs_html:
303  extends:
304    - .build_docs_template
305    - .rules:labels:build_docs
306  artifacts:
307    when: always
308    paths:
309      - docs/_build/*/*/*.txt
310      - docs/_build/*/*/html/*
311    expire_in: 4 days
312  variables:
313    DOC_BUILDERS: "html"
314
315build_docs_pdf:
316  extends:
317    - .build_docs_template
318    - .rules:labels:build_docs-slim
319  artifacts:
320    when: always
321    paths:
322      - docs/_build/*/*/latex/*
323    expire_in: 4 days
324  variables:
325    DOC_BUILDERS: "latex"
326
327.test_build_system_template:
328  extends:
329    - .build_template
330    - .rules:build_tests:weekend_test
331  dependencies:  # set dependencies to null to avoid missing artifacts issue
332  needs:
333    - job: fast_template_app
334      artifacts: false
335  script:
336    - ${IDF_PATH}/tools/ci/test_configure_ci_environment.sh
337    - rm -rf test_build_system
338    - mkdir test_build_system
339    - cd test_build_system
340    - ${IDF_PATH}/tools/ci/${SHELL_TEST_SCRIPT}
341
342test_build_system:
343  extends: .test_build_system_template
344  variables:
345    SHELL_TEST_SCRIPT: test_build_system.sh
346
347test_build_system_cmake:
348  extends: .test_build_system_template
349  variables:
350    SHELL_TEST_SCRIPT: test_build_system_cmake.sh
351
352test_build_system_cmake_macos:
353  extends:
354    - .test_build_system_template
355    - .before_script_macos
356    - .rules:os:mac_os
357  tags:
358    - macos_shell
359  variables:
360    SHELL_TEST_SCRIPT: test_build_system_cmake.sh
361
362build_docker:
363  extends:
364    - .before_script_slim
365    - .rules:protected-schedule
366  stage: build
367  image: espressif/docker-builder:1
368  tags:
369    - build_docker_amd64_brno
370  variables:
371    DOCKER_TMP_IMAGE_NAME: "idf_tmp_image"
372  script:
373    - export LOCAL_CI_REPOSITORY_URL=$CI_REPOSITORY_URL
374    - if [ -n "$LOCAL_GITLAB_HTTPS_HOST" ]; then export LOCAL_CI_REPOSITORY_URL="https://gitlab-ci-token:${CI_JOB_TOKEN}@${LOCAL_GITLAB_HTTPS_HOST}/${CI_PROJECT_PATH}"; fi
375    - echo "Using repository at $LOCAL_CI_REPOSITORY_URL"
376    - export DOCKER_BUILD_ARGS="--build-arg IDF_CLONE_URL=${LOCAL_CI_REPOSITORY_URL} --build-arg IDF_CLONE_BRANCH_OR_TAG=${CI_COMMIT_REF_NAME} --build-arg IDF_CHECKOUT_REF=${CI_COMMIT_TAG:-$CI_COMMIT_SHA}"
377    # Build
378    - docker build --tag ${DOCKER_TMP_IMAGE_NAME} ${DOCKER_BUILD_ARGS} tools/docker/
379    # We can't mount $PWD/examples/get-started/blink into the container, see https://gitlab.com/gitlab-org/gitlab-ce/issues/41227.
380    # The workaround mentioned there works, but leaves around directories which need to be cleaned up manually.
381    # Therefore, build a copy of the example located inside the container.
382    - docker run --rm --workdir /opt/esp/idf/examples/get-started/blink ${DOCKER_TMP_IMAGE_NAME} idf.py build
383
384.test-on-windows:
385  extends:
386    - .before_script_slim
387    - .rules:protected-schedule
388  stage: build
389  image: $CI_DOCKER_REGISTRY/esp32-toolchain-win-cross
390  tags:
391    - build
392  script:
393    - cd $TEST_DIR
394    - mkdir build
395    - cd build
396    - cmake -DCMAKE_TOOLCHAIN_FILE=../toolchain-i686-w64-mingw32.cmake -DCMAKE_BUILD_TYPE=Release ..
397    - cmake --build .
398
399build_idf_exe:
400  extends: .test-on-windows
401  artifacts:
402    paths:
403      - tools/windows/idf_exe/build/idf-exe-v*.zip
404    expire_in: 4 days
405  variables:
406    TEST_DIR: tools/windows/idf_exe
407
408build_cmdlinerunner:
409  extends: .test-on-windows
410  artifacts:
411    paths:
412      - tools/windows/tool_setup/cmdlinerunner/build/cmdlinerunner.dll
413    expire_in: 4 days
414  variables:
415    TEST_DIR: tools/windows/tool_setup/cmdlinerunner
416
417build_installer:
418  extends:
419    - .before_script_slim
420    - .rules:protected-schedule
421  # using a different stage here to be able to use artifacts from build_cmdlinerunner job
422  stage: host_test
423  image: $CI_DOCKER_REGISTRY/wine-innosetup:1
424  tags:
425    - build
426  dependencies:  # set dependencies to null to avoid missing artifacts issue
427  needs:
428    - build_cmdlinerunner
429  script:
430    - cd tools/windows/tool_setup/
431    - ./build_installer.sh
432
433# This job builds template app with permutations of targets and optimization levels
434build_template_app:
435  needs:
436    - job: fast_template_app
437      artifacts: false
438  extends: .build_template_app_template
439
440# Sonarqube related jobs put here for this reason:
441# Here we have two jobs. code_quality_check and code_quality_report.
442#
443# code_quality_check will analyze the code changes between your MR and
444# code repo stored in sonarqube server. The analysis result is only shown in
445# the comments under this MR and won't be transferred to the server.
446#
447# code_quality_report will analyze and transfer both of the newly added code
448# and the analysis result to the server.
449#
450# Put in the front to ensure that the newly merged code can be stored in
451# sonarqube server ASAP, in order to avoid reporting unrelated code issues
452.sonar_scan_template:
453  stage: build
454  image:
455    name: $CI_DOCKER_REGISTRY/sonarqube-scanner:2
456  before_script:
457    - source tools/ci/utils.sh
458    - export PYTHONPATH="$CI_PROJECT_DIR/tools:$CI_PROJECT_DIR/tools/ci/python_packages:$PYTHONPATH"
459    - fetch_submodules
460    # Exclude the submodules, all paths ends with /**
461    - export SUBMODULES=$(get_all_submodules)
462    # get all exclude paths specified in tools/ci/sonar_exclude_list.txt | ignore lines start with # | xargs | replace all <space> to <comma>
463    - export CUSTOM_EXCLUDES=$(cat $CI_PROJECT_DIR/tools/ci/sonar_exclude_list.txt | grep -v '^#' | xargs | sed -e 's/ /,/g')
464    # Exclude the report dir
465    - export EXCLUSIONS="$SUBMODULES,$REPORT_DIR/**,docs/_static/**,**/*.png,**/*.jpg"
466    - python $NORMALIZE_CLANGTIDY_PY $CI_PROJECT_DIR/$REPORT_DIR/warnings.txt $CI_PROJECT_DIR/$REPORT_DIR/clang_tidy_report.txt $CI_PROJECT_DIR
467  variables:
468    GIT_DEPTH: 0
469    NORMALIZE_CLANGTIDY_PY: $CI_PROJECT_DIR/tools/ci/normalize_clangtidy_path.py
470    REPORT_DIR: examples/get-started/hello_world/tidybuild/report
471  tags:
472    - host_test
473  dependencies:  # set dependencies to null to avoid missing artifacts issue
474  needs:
475    - clang_tidy_check_regular
476
477code_quality_check:
478  extends:
479    - .sonar_scan_template
480    - .rules:trigger
481  allow_failure: true
482  script:
483    - export CI_MR_IID=$(python ${CI_PROJECT_DIR}/tools/ci/ci_get_mr_info.py id ${CI_COMMIT_BRANCH})
484    - export CI_MR_COMMITS=$(python ${CI_PROJECT_DIR}/tools/ci/ci_get_mr_info.py commits ${CI_COMMIT_BRANCH} | tr '\n' ',')
485    # test if this branch have merge request, if not, exit 0
486    - test -n "$CI_MR_IID" || exit 0
487    - test -n "$CI_MR_COMMITS" || exit 0
488    - sonar-scanner
489      -Dsonar.analysis.mode=preview
490      -Dsonar.host.url=$SONAR_HOST_URL
491      -Dsonar.login=$SONAR_LOGIN
492      -Dsonar.sources=$CI_PROJECT_DIR
493      -Dsonar.sourceEncoding=UTF-8
494      -Dsonar.projectKey=esp-idf
495      -Dsonar.projectBaseDir=$CI_PROJECT_DIR
496      -Dsonar.exclusions=$EXCLUSIONS
497      -Dsonar.gitlab.project_id=$CI_PROJECT_ID
498      -Dsonar.gitlab.commit_sha=$CI_MR_COMMITS
499      -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME
500      -Dsonar.gitlab.failure_notification_mode=exit-code
501      -Dsonar.cxx.clangtidy.reportPath=$REPORT_DIR/clang_tidy_report.txt
502      -Dsonar.cxx.includeDirectories=components,/usr/include
503      -Dsonar.python.pylint_config=.pylintrc
504      -Dsonar.gitlab.ci_merge_request_iid=$CI_MR_IID
505      -Dsonar.gitlab.merge_request_discussion=true
506      -Dsonar.branch.name=$CI_COMMIT_REF_NAME
507
508code_quality_report:
509  extends:
510    - .sonar_scan_template
511    - .rules:protected-schedule
512  script:
513    - sonar-scanner
514      -Dsonar.host.url=$SONAR_HOST_URL
515      -Dsonar.login=$SONAR_LOGIN
516      -Dsonar.sources=$CI_PROJECT_DIR
517      -Dsonar.sourceEncoding=UTF-8
518      -Dsonar.projectKey=esp-idf
519      -Dsonar.projectBaseDir=$CI_PROJECT_DIR
520      -Dsonar.exclusions=$EXCLUSIONS
521      -Dsonar.gitlab.project_id=$CI_PROJECT_ID
522      -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA
523      -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME
524      -Dsonar.cxx.clangtidy.reportPath=$REPORT_DIR/clang_tidy_report.txt
525      -Dsonar.cxx.includeDirectories=components,/usr/include
526      -Dsonar.python.pylint_config=.pylintrc
527      -Dsonar.branch.name=$CI_COMMIT_REF_NAME
528