Skip to content

Commit 327e2cd

Browse files
authored
Arm backend: Update and enable ZephyrOS GitHub test (#16539)
### Summary This will test ZephyrOS by runing the commands in the README.md This verifies both the ZephyrOS support and make sure the instructions works. ### Test plan Include test in this PR cc @freddan80 @per @oscarandersson8218 @digantdesai --------- Signed-off-by: Zingo Andersen <Zingo.Andersen@arm.com>
1 parent b928496 commit 327e2cd

7 files changed

Lines changed: 403 additions & 153 deletions

File tree

.ci/scripts/zephyr-utils.sh

Lines changed: 165 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,175 @@
11
#!/bin/bash
22
# Copyright (c) Meta Platforms, Inc. and affiliates.
33
# All rights reserved.
4+
# Copyright 2026 Arm Limited and/or its affiliates.
45
#
56
# This source code is licensed under the BSD-style license found in the
67
# LICENSE file in the root directory of this source tree.
78

8-
download_arm_zephyr_sdk () {
9-
wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.17.2/zephyr-sdk-0.17.2_linux-x86_64.tar.xz
10-
tar -xf zephyr-sdk-0.17.2_linux-x86_64.tar.xz
11-
rm -f zephyr-sdk-0.17.2_linux-x86_64.tar.xz
9+
# Run instruction from zephyr/README.md
10+
#
11+
# This contains some CI helper runtime functions to dig out and run commands
12+
# from zephyr/README.md
13+
# It also try to verify that zephyr/executorch.yaml is in sync and the snippets
14+
# in the README are sane with various regexps.
15+
#
16+
# Main functions is run_command_block_from_zephyr_readme it will dig out the code between
17+
# the two ''' after a blockheader text and run it
18+
#
19+
# .e.g. from this README.md snippet
20+
#
21+
# Install requirements
22+
# ```
23+
# pip install something
24+
# pip install something_else
25+
# ```
26+
#
27+
# The blockheader is 'Install requirements' and the code block is 'pip install something ... \npip install something_else'
28+
# so if we run
29+
# run_command_block_from_zephyr_readme 'Install requirements' '^(pip|pip3)[[:space:]]+install([[:space:]].*)?$'
30+
# it will make sure each lite start with pip or pip3 and then run them one by one
31+
32+
33+
34+
# Resolve and cache this script's directory; if sourced, and remember it globally
35+
# So functions in this script can be used even after sourced and still find
36+
# the correct paths
37+
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
38+
if [[ "${BASH_SOURCE[0]}" != "$0" ]]; then
39+
export ZEPHYR_UTILS_DIR="${script_dir}"
40+
fi
41+
42+
# Internal utility functions
43+
_zephyr_utils_root_dir () {
44+
local script_dir resolved
45+
46+
if [[ -n "${ZEPHYR_UTILS_DIR:-}" ]]; then
47+
script_dir="${ZEPHYR_UTILS_DIR}"
48+
else
49+
resolved="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
50+
if [[ "${BASH_SOURCE[0]}" != "$0" ]]; then
51+
ZEPHYR_UTILS_DIR="${resolved}"
52+
fi
53+
script_dir="${resolved}"
54+
fi
55+
56+
(cd "${script_dir}/../.." && pwd)
57+
}
58+
59+
_zephyr_utils_readme_path () {
60+
local root_dir
61+
root_dir="$(_zephyr_utils_root_dir)"
62+
printf '%s/zephyr/README.md\n' "${root_dir}"
63+
}
64+
65+
_zephyr_utils_ensure_file () {
66+
local path="$1"
67+
local description="$2"
68+
if [[ ! -f "${path}" ]]; then
69+
echo "ERROR: ${description} not found at ${path}" >&2
70+
return 1
71+
fi
1272
}
1373

14-
setup_zephyr_et_module () {
15-
git clone --branch executorch-module-integration https://github.com/BujSet/zephyr.git
16-
west init -l zephyr
17-
west config manifest.project-filter -- +executorch
18-
west -v update
74+
_zephyr_utils_extract_block () {
75+
local readme_path="$1"
76+
local marker="$2"
77+
awk -v marker="${marker}" '
78+
$0 ~ marker { section=1; next }
79+
section && /^```/ {
80+
if (in_block) { exit }
81+
in_block=1
82+
next
83+
}
84+
in_block && /^```/ { exit }
85+
in_block { sub(/\r$/, ""); print }
86+
' "${readme_path}"
87+
}
88+
89+
_zephyr_utils_run_simple_commands () {
90+
local block="$1"
91+
local allowedpattern="$2"
92+
local description="$3"
93+
temp_dir="$(mktemp -d)"
94+
if [[ ! -d "${temp_dir}" ]]; then
95+
echo "ERROR: Failed to create temporary directory for west init" >&2
96+
return 1
97+
fi
98+
trap "rm -rf '${temp_dir}'; trap - RETURN" RETURN
99+
100+
local ran=0 cmd
101+
while IFS= read -r cmd; do
102+
cmd="${cmd#"${cmd%%[![:space:]]*}"}"
103+
cmd="${cmd%"${cmd##*[![:space:]]}"}"
104+
[[ -z "${cmd}" ]] && continue
105+
106+
if [[ ! "${cmd}" =~ ${allowedpattern} ]]; then
107+
echo "ERROR: Unexpected command in '${description}' readme block: ${cmd} must match pattern: ${allowedpattern}" >&2
108+
return 1
109+
fi
110+
111+
if [[ "${cmd}" == *";"* || "${cmd}" == *"&&"* || "${cmd}" == *"||"* || "${cmd}" == *"|"* ]]; then
112+
echo "ERROR: Command chaining is not allowed in '${description}' readme block: ${cmd}" >&2
113+
return 1
114+
fi
115+
116+
echo "Running: ${cmd}"
117+
if ! eval "${cmd}"; then
118+
return 1
119+
fi
120+
ran=1
121+
done <<< "${block}"
122+
123+
if [[ ${ran} -eq 0 ]]; then
124+
echo "ERROR: No commands found in block after ${description}" >&2
125+
return 1
126+
fi
127+
128+
return 0
129+
}
130+
131+
run_command_block_from_zephyr_readme () {
132+
local blockheader="$1"
133+
local allowedpattern="$2"
134+
135+
echo "Run block '${blockheader}' from zephyr/README.md"
136+
137+
readme_path="$(_zephyr_utils_readme_path)"
138+
_zephyr_utils_ensure_file "${readme_path}" "README.md" || return 1
139+
140+
block="$(_zephyr_utils_extract_block "${readme_path}" "${blockheader}")"
141+
142+
if [[ -z "${block}" ]]; then
143+
echo "ERROR: Failed to locate ${blockheader} block in ${readme_path}" >&2
144+
return 1
145+
fi
146+
_zephyr_utils_run_simple_commands "${block}" "${allowedpattern}" "${blockheader}"
147+
}
148+
149+
# Check that zephyr/executorch.yaml match zephyr/README.md
150+
verify_zephyr_readme () {
151+
local readme_path manifest_path snippet
152+
153+
readme_path="$(_zephyr_utils_readme_path)"
154+
manifest_path="$(_zephyr_utils_root_dir)/zephyr/executorch.yaml"
155+
156+
_zephyr_utils_ensure_file "${readme_path}" "README" || return 1
157+
_zephyr_utils_ensure_file "${manifest_path}" "Manifest" || return 1
158+
159+
snippet="$(
160+
_zephyr_utils_extract_block "${readme_path}" '<zephyr_build_root>/zephyr/submanifests/executorch\.yaml'
161+
)"
162+
163+
if [[ -z "${snippet}" ]]; then
164+
echo "ERROR: Failed to extract executorch.yaml snippet from ${readme_path}" >&2
165+
return 1
166+
fi
167+
168+
if diff -u <(printf '%s\n' "${snippet}") "${manifest_path}"; then
169+
echo "zephyr/README.md executorch.yaml snippet is in sync with zephyr/executorch.yaml" >&2
170+
return 0
171+
fi
172+
173+
echo "ERROR: ${readme_path} executorch.yaml snippet is out of sync with ${manifest_path}" >&2
174+
return 1
19175
}

0 commit comments

Comments
 (0)