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>
This commit is contained in:
Marc Herbert 2021-04-28 16:44:02 -07:00 committed by Liam Girdwood
parent 831bb3755b
commit 33c5f5d38e
1 changed files with 53 additions and 20 deletions

View File

@ -5,9 +5,11 @@
# stop on most errors # stop on most errors
set -e set -e
SOF_TOP=$(cd "$(dirname "$0")" && cd .. && pwd)
SUPPORTED_PLATFORMS=(apl cnl icl tgl-h) SUPPORTED_PLATFORMS=(apl cnl icl tgl-h)
# By default use "zephyr" in the current directory # Default value, can be overridden on the command line
ZEPHYR_ROOT=zephyr WEST_TOP="${SOF_TOP}"/zephyrproject
BUILD_JOBS=$(nproc --all) BUILD_JOBS=$(nproc --all)
RIMAGE_KEY=modules/audio/sof/keys/otc_private_key.pem RIMAGE_KEY=modules/audio/sof/keys/otc_private_key.pem
PLATFORMS=() PLATFORMS=()
@ -31,41 +33,43 @@ platform's _defconfig file.
usage: $0 [options] platform(s) usage: $0 [options] platform(s)
-a Build all platforms. -a Build all platforms.
-c Clone the complete Zephyr and SOF trees before building.
-j n Set number of make build jobs. Jobs=#cores by default. -j n Set number of make build jobs. Jobs=#cores by default.
Infinite when not specified. Infinite when not specified.
-k Path to a non-default rimage signing key. -k Path to a non-default rimage signing key.
-p Zephyr root directory. -c recursively clones Zephyr inside sof before building.
Incompatible with -p.
-p Existing Zephyr project directory. Incompatible with -c.
If modules/audio/sof is missing there then a symbolic
link pointing to ${SOF_TOP} will be added.
Supported platforms ${SUPPORTED_PLATFORMS[*]} Supported platforms ${SUPPORTED_PLATFORMS[*]}
EOF EOF
} }
# Downloads zephyrproject inside sof/ and create a ../../.. symbolic
# link back to sof/
clone() clone()
{ {
# Check out Zephyr + SOF
type -p west || die "Install west and a west toolchain following https://docs.zephyrproject.org/latest/getting_started/index.html" type -p west || die "Install west and a west toolchain following https://docs.zephyrproject.org/latest/getting_started/index.html"
type -p git || die "Install git" type -p git || die "Install git"
[ -e "$ZEPHYR_ROOT" ] && die "$ZEPHYR_ROOT already exists" [ -e "$WEST_TOP" ] && die "$WEST_TOP already exists"
mkdir -p "$ZEPHYR_ROOT" mkdir -p "$WEST_TOP"
cd "$ZEPHYR_ROOT" git clone --depth=5 https://github.com/zephyrproject-rtos/zephyr \
west init "$WEST_TOP"/zephyr
west update west init -l "${WEST_TOP}"/zephyr
cd modules/audio/sof ( cd "${WEST_TOP}"
git remote add sof https://github.com/thesofproject/sof.git mkdir -p modules/audio
git remote update sof ln -s ../../.. modules/audio/sof
git checkout sof/main # Do NOT "west update sof"!!
git clone --recurse-submodules https://github.com/thesofproject/rimage.git west update zephyr hal_xtensa
cd - )
} }
build() build()
{ {
[ -d "$ZEPHYR_ROOT" ] || die "$ZEPHYR_ROOT doesn't exists" cd "$WEST_TOP"
cd "$ZEPHYR_ROOT"
# Build rimage # Build rimage
RIMAGE_DIR=build-rimage RIMAGE_DIR=build-rimage
@ -107,6 +111,8 @@ build()
main() main()
{ {
local zeproj
# parse the args # parse the args
while getopts "acj:k:p:" OPTION; do while getopts "acj:k:p:" OPTION; do
case "$OPTION" in case "$OPTION" in
@ -114,12 +120,28 @@ main()
c) DO_CLONE=yes ;; c) DO_CLONE=yes ;;
j) BUILD_JOBS="$OPTARG" ;; j) BUILD_JOBS="$OPTARG" ;;
k) RIMAGE_KEY="$OPTARG" ;; k) RIMAGE_KEY="$OPTARG" ;;
p) ZEPHYR_ROOT="$OPTARG" ;; p) zeproj="$OPTARG" ;;
*) print_usage; exit 1 ;; *) print_usage; exit 1 ;;
esac esac
done done
shift $((OPTIND-1)) shift $((OPTIND-1))
if [ -n "$zeproj" ] && [ x"$DO_CLONE" = xyes ]; then
die 'Cannot use -p with -c, -c supports %s only' "${WEST_TOP}"
fi
if [ -n "$zeproj" ]; then
[ -d "$zeproj" ] ||
die "$zeproj is not a directory, try -c instead of -p?"
( cd "$zeproj"
test "$(realpath "$(west topdir)")" = "$(/bin/pwd)"
) || die '%s is not a zephyrproject' "$WEST_TOP"
WEST_TOP="$zeproj"
fi
# parse platform args # parse platform args
for arg in "$@"; do for arg in "$@"; do
platform=none platform=none
@ -148,6 +170,17 @@ main()
if [ "x$DO_CLONE" == "xyes" ]; then if [ "x$DO_CLONE" == "xyes" ]; then
clone clone
else
# Link to ourselves if no sof module yet
test -e "${WEST_TOP}"/modules/audio/sof ||
ln -s "$SOF_TOP" "${WEST_TOP}"/modules/audio/sof
# Support for submodules in west is too recent, cannot
# rely on it
test -d "${WEST_TOP}"/modules/audio/sof/rimage/CMakeLists.txt || (
cd "${WEST_TOP}"/modules/audio/sof
git submodule update --init --recursive
)
fi fi
build build