summaryrefslogtreecommitdiff
path: root/.gitlab-ci.yml
blob: bd77d308cde73832e434ca991b60878150f453b4 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# Copyright 2021 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

image: jbettis/ubuntu-29sep21

# You can update that image using this repo:
#   https://gitlab.com/zephyr-ec/gitlab-ci-runner/-/tree/main

# Change pip's cache directory to be inside the project directory since we can
# only cache local items.
variables:
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"

# Pip's cache doesn't store the python packages
# https://pip.pypa.io/en/stable/reference/pip_install/#caching
#
# If you want to also cache the installed packages, you have to install
# them in a virtualenv and cache it as well.
cache:
  key: ${CI_COMMIT_SHA}
  policy: pull
  paths:
    - .cache/pip
    - venv/
    - modules/
    - zephyr/


# The directory structure is:
#
# /zephyr
# /builds/zephyr-ec/ec       EC_DIR
before_script:
  - export MODULES_DIR="$CI_PROJECT_DIR/modules"
  - mkdir -p "${MODULES_DIR}"
  - export ZEPHYR_BASE="${CI_PROJECT_DIR}/zephyr/main"
  - mkdir -p "${ZEPHYR_BASE}"
  - test -d "${ZEPHYR_BASE}/.git" || git clone --depth 1 -b chromeos-v2.7 https://chromium.googlesource.com/chromiumos/third_party/zephyr "${ZEPHYR_BASE}"
  - test -d "${MODULES_DIR}/cmsis" || git clone --depth 1 -b chromeos-main https://chromium.googlesource.com/chromiumos/third_party/zephyr/cmsis "${MODULES_DIR}/cmsis"
  - test -d "${MODULES_DIR}/hal_stm32" || git clone --depth 1 -b chromeos-main https://chromium.googlesource.com/chromiumos/third_party/zephyr/hal_stm32 "${MODULES_DIR}/hal_stm32"
  - test -d "${MODULES_DIR}/nanopb" || git clone --depth 1 -b main https://chromium.googlesource.com/chromiumos/third_party/zephyr/nanopb "${MODULES_DIR}/nanopb"
  - test -d "${MODULES_DIR}/cryptoc" || git clone --depth 1 -b main https://chromium.googlesource.com/chromiumos/third_party/cryptoc "${MODULES_DIR}/cryptoc"
  - ln -s "$(pwd)" "${MODULES_DIR}/ec"
  - python3 -V  # Print out python version for debugging
  - python3 -m pip install zephyr/zmake --user
  - python3 -m pip install pyyaml
  - export BUILD_DIR=build
  - export PATH="$PATH:$HOME/.local/bin"
  - export PYTHONIOENCODING=utf-8
  - export EC_DIR=/builds/zephyr-ec/ec

seed_cache:
  stage: build
  needs: []
  cache:
    key: ${CI_COMMIT_SHA}
    paths:
      - .cache/pip
      - venv/
      - modules/
      - zephyr/
    policy: push
  script:
    - ls "${MODULES_DIR}" "${ZEPHYR_BASE}"

# Users of this template must set:
# $PROJECT to the project to build. E.g., "lazor"
.build_template: &build_template
  stage: build
  needs: ["seed_cache"]
  script:
    - zmake --zephyr-base "${ZEPHYR_BASE}"
      --modules-dir "${MODULES_DIR}" -l DEBUG configure -b
      -B "${BUILD_DIR}/${PROJECT}" -t ${TOOLCHAIN:-zephyr}
      "${PROJECT}"
    - for b in "${BUILD_DIR}/${PROJECT}"/build-* ; do
      bdir=$(basename ${b}) ;
      ninja -C ${b} ram_report >"${BUILD_DIR}/${PROJECT}/output/${bdir}_ram_report.txt" ;
      cp ${b}/ram.json "${BUILD_DIR}/${PROJECT}/output/${bdir}_ram.json" ;
      ninja -C ${b} rom_report >"${BUILD_DIR}/${PROJECT}/output/${bdir}_rom_report.txt" ;
      cp ${b}/rom.json "${BUILD_DIR}/${PROJECT}/output/${bdir}_rom.json" ;
      done
    - ls "${BUILD_DIR}/${PROJECT}" "${BUILD_DIR}/${PROJECT}/output"
  artifacts:
    paths:
      - build/${PROJECT}/output/*
    expire_in: 1 week

# Users of this template must set:
# $PROJECT to the project to build. E.g., "lazor"
.coverage_template: &coverage_template
  stage: test
  needs: ["merged_coverage", "zephyr_coverage"]
  script:
    - grep "SF:" "build/zcoverage/${PROJECT}.info" | sort -u | sed -e 's|^SF:||' | xargs lcov -o build/no_zephyr_${PROJECT}.info -e build/merged_no_zephyr.info
    - /usr/bin/genhtml -q -o build/no_zephyr_${PROJECT}_rpt -t "${PROJECT} coverage w/o zephyr" -p ${EC_DIR} -s build/no_zephyr_${PROJECT}.info
  artifacts:
    paths:
      - build/*.info
      - build/*_rpt
    expire_in: 1 week
  coverage: '/lines\.*: \d+\.\d+%/'

delbin:
  variables:
    PROJECT: "delbin"
  <<: *build_template

hayato:
  variables:
    PROJECT: "hayato"
  <<: *build_template

hayato_coverage:
  variables:
    PROJECT: "hayato"
  <<: *coverage_template

herobrine_npcx9:
  variables:
    PROJECT: "herobrine_npcx9"
  <<: *build_template

herobrine_npcx9_coverage:
  variables:
    PROJECT: "herobrine_npcx9"
  <<: *coverage_template

it8xxx2_evb:
  variables:
    PROJECT: "it8xxx2_evb"
  <<: *build_template

lazor:
  variables:
    PROJECT: "lazor"
  <<: *build_template

native_posix:
  variables:
    PROJECT: "posix-ec"
    TOOLCHAIN: "host"
  <<: *build_template

volteer:
  variables:
    PROJECT: "volteer"
  <<: *build_template

ec_coverage:
  stage: test
  needs: ["seed_cache"]
  script:
    - make -j8 CRYPTOC_DIR="${MODULES_DIR}/cryptoc"
      HOSTGCOV='gcov'
      CROSS_COMPILE_arm=/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-
      test-coverage
  artifacts:
    paths:
      - build/coverage/coverage_rpt/*
      - build/coverage/lcov.info
    expire_in: 1 week
  coverage: '/lines\.*: \d+\.\d+%/'

zephyr_coverage:
  stage: test
  needs: ["seed_cache"]
  script:
    - zmake --zephyr-base "${ZEPHYR_BASE}"
      --modules-dir "${MODULES_DIR}" -l DEBUG coverage
      "${BUILD_DIR}/zcoverage"
  artifacts:
    paths:
      - build/zcoverage/coverage_rpt/*
      - build/zcoverage/*.info
    expire_in: 1 week
  coverage: '/lines\.*: \d+\.\d+%/'

merged_coverage:
  stage: test
  needs: ["ec_coverage", "zephyr_coverage"]
  script:
    - lcov -o build/merged.info -a build/coverage/lcov.info -a build/zcoverage/lcov.info
    - lcov -o build/merged_no_zephyr.info -r build/merged.info "${ZEPHYR_BASE}/*" "${MODULES_DIR}/*" "zephyr/drivers/*" '/usr/include/x86_64-linux-gnu/*'
  artifacts:
    paths:
      - build/*.info
      - build/*_rpt
    expire_in: 1 week
  coverage: '/lines\.*: \d+\.\d+%/'

testall:
  stage: test
  needs: ["seed_cache"]
  script:
    - zmake --zephyr-base "${ZEPHYR_BASE}"
      --modules-dir "${MODULES_DIR}" -l DEBUG testall