summaryrefslogtreecommitdiff
path: root/.circleci/config.yml
blob: 66799910d41b23356927659d44389f6b96cfedf8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
version: 2.1

setup: true
orbs:
  continuation: circleci/continuation@1

jobs:
  set-matrix:
    executor: continuation/default
    docker:
      - image: cimg/base:current
    resource_class: large
    steps:
      - checkout
      - run:
          name: Set matrix
          command: |
            MATRIX_JSON=$(python .github/workflows/ci_set_matrix.py)
            echo "MATRIX_JSON=$MATRIX_JSON"

            BUILDSYSTEM_LIST=(
              "cmake"
              "make"
            )

            TOOLCHAIN_LIST=(
              "aarch64-gcc"
              "arm-clang"
              "arm-gcc"
              "esp-idf"
              "ft9xx-gcc"
              "msp430-gcc"
              "riscv-gcc"
            )

            # only build IAR if not forked PR, since IAR token is not shared
            if [ -z $CIRCLE_PR_USERNAME ]; then
              TOOLCHAIN_LIST+=("arm-iar")
            fi

            gen_build_entry() {
              local build_system="$1"
              local toolchain="$2"
              local family="$3"
              local build_args=""

              if [[ "$toolchain" == "arm-iar" || "$build_system" == "make" ]]; then
                build_args="--one-random"
              fi

              if [[ "$toolchain" == "esp-idf" ]]; then
                echo "      - build-vm:" >> .circleci/config2.yml
              else
                echo "      - build:" >> .circleci/config2.yml
              fi
              echo "          matrix:" >> .circleci/config2.yml
              echo "            alias: build-${build_system}-${toolchain}" >> .circleci/config2.yml
              echo "            parameters:" >> .circleci/config2.yml
              echo "              build-system: ['$build_system']" >> .circleci/config2.yml
              echo "              toolchain: ['$toolchain']" >> .circleci/config2.yml
              echo "              family: $family" >> .circleci/config2.yml
              echo "              resource_class: ['large']" >> .circleci/config2.yml
              echo "              build-args: ['$build_args']" >> .circleci/config2.yml
            }

            # Collect all build aliases for code-metrics requires (cmake only, exclude esp-idf)
            BUILD_ALIASES=()

            for build_system in "${BUILDSYSTEM_LIST[@]}"; do
              for toolchain in "${TOOLCHAIN_LIST[@]}"; do
                # make does not support these toolchains
                if [ "$build_system" == "make" ] && { [ "$toolchain" == "arm-clang" ] || [ "$toolchain" == "arm-iar" ] || [ "$toolchain" == "esp-idf" ]; }; then
                  continue
                fi

                FAMILY=$(echo $MATRIX_JSON | jq -r ".\"$toolchain\"")
                echo "FAMILY_${toolchain}=$FAMILY"
                gen_build_entry "$build_system" "$toolchain" "$FAMILY"

                # Only add cmake builds: excluding esp-idf or build_args="--one-random" to metrics requirements
                if [ "$build_system" == "cmake" ] && [ "$toolchain" != "esp-idf" ] && [ "$toolchain" != "arm-iar" ]; then
                  BUILD_ALIASES+=("build-${build_system}-${toolchain}")
                fi
              done
            done

            # Add code-metrics job that requires all build jobs
            echo "      - code-metrics:" >> .circleci/config2.yml
            echo "          requires:" >> .circleci/config2.yml
            for alias in "${BUILD_ALIASES[@]}"; do
              echo "            - $alias" >> .circleci/config2.yml
            done

      - continuation/continue:
          configuration_path: .circleci/config2.yml

workflows:
  set-matrix:
    jobs:
      - set-matrix