Skip to content

Commit 78eca94

Browse files
committed
xtensa-build-zephyr: do not clone a second version of sof.git
This script lives in a sof.git/ clone yet it was systematically cloning a second sof.git/. Besides the obvious confusion and risk of editing the wrong files, this meant it was not possible to build code that has not been merged yet! This was a problem for both CI and developers. Fixed by using symbolic links to ourselves instead. Note it is _still_ possible to build from another sof.git clone if desired, however this script will never git re-clone a second sof.git itself, that second clone has to be created (e.g.: by west) before this script runs. When cloning a brand new zephyrproject, use a shallow zephyr clone and download only the two zephyr modules we actually use. This speeds up automation considerably and makes it much faster for non-Zephyr developers to reproduce Zephyr issues. Developers can always git unshallow and west update once if they want to. Rename the default west top to "zephyrproject" to not just match the zephyr documentation but to also avoid creating a double zephyr/zephyr/ directory. See the new print_usage() for a few more implementation details. Signed-off-by: Marc Herbert <marc.herbert@intel.com>
1 parent bf74049 commit 78eca94

File tree

1 file changed

+53
-20
lines changed

1 file changed

+53
-20
lines changed

scripts/xtensa-build-zephyr.sh

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
# stop on most errors
66
set -e
77

8+
SOF_TOP=$(cd "$(dirname "$0")" && cd .. && pwd)
9+
810
SUPPORTED_PLATFORMS=(apl cnl icl tgl-h)
9-
# By default use "zephyr" in the current directory
10-
ZEPHYR_ROOT=zephyr
11+
# Default value, can be overridden on the command line
12+
WEST_TOP="${SOF_TOP}"/zephyrproject
1113
BUILD_JOBS=$(nproc --all)
1214
RIMAGE_KEY=modules/audio/sof/keys/otc_private_key.pem
1315
PLATFORMS=()
@@ -31,41 +33,43 @@ platform's _defconfig file.
3133
usage: $0 [options] platform(s)
3234
3335
-a Build all platforms.
34-
-c Clone the complete Zephyr and SOF trees before building.
3536
-j n Set number of make build jobs. Jobs=#cores by default.
3637
Infinite when not specified.
3738
-k Path to a non-default rimage signing key.
38-
-p Zephyr root directory.
39+
-c recursively clones Zephyr inside sof before building.
40+
Incompatible with -p.
41+
-p Existing Zephyr project directory. Incompatible with -c.
42+
If modules/audio/sof is missing there then a symbolic
43+
link pointing to ${SOF_TOP} will be added.
3944
4045
Supported platforms ${SUPPORTED_PLATFORMS[*]}
4146
4247
EOF
4348
}
4449

50+
# Downloads zephyrproject inside sof/ and create a ../../.. symbolic
51+
# link back to sof/
4552
clone()
4653
{
47-
# Check out Zephyr + SOF
48-
4954
type -p west || die "Install west and a west toolchain following https://docs.zephyrproject.org/latest/getting_started/index.html"
5055
type -p git || die "Install git"
5156

52-
[ -e "$ZEPHYR_ROOT" ] && die "$ZEPHYR_ROOT already exists"
53-
mkdir -p "$ZEPHYR_ROOT"
54-
cd "$ZEPHYR_ROOT"
55-
west init
56-
west update
57-
cd modules/audio/sof
58-
git remote add sof https://github.com/thesofproject/sof.git
59-
git remote update sof
60-
git checkout sof/main
61-
git clone --recurse-submodules https://github.com/thesofproject/rimage.git
62-
cd -
57+
[ -e "$WEST_TOP" ] && die "$WEST_TOP already exists"
58+
mkdir -p "$WEST_TOP"
59+
git clone --depth=5 https://github.com/zephyrproject-rtos/zephyr \
60+
"$WEST_TOP"/zephyr
61+
west init -l "${WEST_TOP}"/zephyr
62+
( cd "${WEST_TOP}"
63+
mkdir -p modules/audio
64+
ln -s ../../.. modules/audio/sof
65+
# Do NOT "west update sof"!!
66+
west update zephyr hal_xtensa
67+
)
6368
}
6469

6570
build()
6671
{
67-
[ -d "$ZEPHYR_ROOT" ] || die "$ZEPHYR_ROOT doesn't exists"
68-
cd "$ZEPHYR_ROOT"
72+
cd "$WEST_TOP"
6973

7074
# Build rimage
7175
RIMAGE_DIR=build-rimage
@@ -107,19 +111,37 @@ build()
107111

108112
main()
109113
{
114+
local zeproj
115+
110116
# parse the args
111117
while getopts "acj:k:p:" OPTION; do
112118
case "$OPTION" in
113119
a) PLATFORMS=("${SUPPORTED_PLATFORMS[@]}") ;;
114120
c) DO_CLONE=yes ;;
115121
j) BUILD_JOBS="$OPTARG" ;;
116122
k) RIMAGE_KEY="$OPTARG" ;;
117-
p) ZEPHYR_ROOT="$OPTARG" ;;
123+
p) zeproj="$OPTARG" ;;
118124
*) print_usage; exit 1 ;;
119125
esac
120126
done
121127
shift $((OPTIND-1))
122128

129+
if [ -n "$zeproj" ] && [ x"$DO_CLONE" = xyes ]; then
130+
die 'Cannot use -p with -c, -c supports %s only' "${WEST_TOP}"
131+
fi
132+
133+
if [ -n "$zeproj" ]; then
134+
135+
[ -d "$zeproj" ] ||
136+
die "$zeproj is not a directory, try -c instead of -p?"
137+
138+
( cd "$zeproj"
139+
test "$(realpath "$(west topdir)")" = "$(/bin/pwd)"
140+
) || die '%s is not a zephyrproject' "$WEST_TOP"
141+
142+
WEST_TOP="$zeproj"
143+
fi
144+
123145
# parse platform args
124146
for arg in "$@"; do
125147
platform=none
@@ -148,6 +170,17 @@ main()
148170

149171
if [ "x$DO_CLONE" == "xyes" ]; then
150172
clone
173+
else
174+
# Link to ourselves if no sof module yet
175+
test -e "${WEST_TOP}"/modules/audio/sof ||
176+
ln -s "$SOF_TOP" "${WEST_TOP}"/modules/audio/sof
177+
178+
# Support for submodules in west is too recent, cannot
179+
# rely on it
180+
test -d "${WEST_TOP}"/modules/audio/sof/rimage/CMakeLists.txt || (
181+
cd "${WEST_TOP}"/modules/audio/sof
182+
git submodule update --init --recursive
183+
)
151184
fi
152185

153186
build

0 commit comments

Comments
 (0)