Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 51 additions & 36 deletions scripts/xtensa-build-zephyr.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __call__(self, parser, namespace, values, option_string=None):
def parse_args():
global args
global west_top
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter,
epilog=("This script supports XtensaTools but only when installed in a specific\n" +
"directory structure, example:\n" +
"myXtensa/\n" +
Expand Down Expand Up @@ -130,31 +130,41 @@ def parse_args():
help="URL to clone Zephyr from")
mode_group = parser.add_mutually_exclusive_group()
mode_group.add_argument("-p", "--west_path", required=False, type=pathlib.Path,
help="Points to existing Zephyr project directory. Incompatible with -c."
" Uses by default path used by -c mode: SOF_TOP/zephyrproject. "
" If zephyr-project/modules/audio/sof is missing then a"
" symbolic link pointing to SOF_TOP directory will automatically be"
" created and west will recognize it as its new sof module."
" If zephyr-project/modules/audio/sof already exists and is a"
" different copy than where this script is run from, then the"
" behavior is undefined."
" This -p option is always required_if the real (not symbolic)"
" sof/ and zephyr-project/ directories are not nested in one"
" another.")
help="""Points to existing Zephyr project directory. Incompatible with -c.
Uses by default path used by -c mode: SOF_TOP/zephyrproject.
If zephyr-project/modules/audio/sof is missing then a
symbolic link pointing to SOF_TOP directory will automatically be
created and west will recognize it as its new sof module.
If zephyr-project/modules/audio/sof already exists and is a
different copy than where this script is run from, then the
behavior is undefined.
This -p option is always required_if the real (not symbolic)
sof/ and zephyr-project/ directories are not nested in one
another.""",
)
mode_group.add_argument("-c", "--clone_mode", required=False, action="store_true",
help="Using west, downloads inside this sof clone a new Zephyr"
" project with the required git repos. Creates a"
" sof/zephyrproject/modules/audio/sof symbolic link pointing"
" back at this sof clone."
" Incompatible with -p. To stop after downloading Zephyr, do not"
" pass any platform or cmake argument.")
help="""Using west, downloads inside this sof clone a new Zephyr
project with the required git repos. Creates a
sof/zephyrproject/modules/audio/sof symbolic link pointing
back at this sof clone.
Incompatible with -p. To stop after downloading Zephyr, do not
pass any platform or cmake argument.""",
)
parser.add_argument('-v', '--verbose', default=0, action='count',
help="Verbosity level. Repetition of the flag increases verbosity."
" verbosity lvl 1: shows underlying build system commands,"
" verbosity lvl 2: lvl 1 + prints commands invoked by this script.")
parser.add_argument("-C", "--cmake-args", required=False,
help="Cmake arguments passed to cmake configure step without"
" '-D' prefix. Eg. CMAKE_GENERATOR='Ninja'. Preserves internal quotes.")
help="""Verbosity level. Repetition of the flag increases verbosity.
verbosity lvl 1: shows underlying build system commands,
verbosity lvl 2: lvl 1 + prints commands invoked by this script.""",
)
# Cannot use a standard -- delimiter because argparse deletes it.
parser.add_argument("-C", "--cmake-args", action='append', default=[],
help="""Cmake arguments passed as is to cmake configure step.
Can be passed multiple times; whitespace is preserved Example:

-C=--warn-uninitialized -C '-DEXTRA_FLAGS=-Werror -g0'

Note '-C --warn-uninitialized' is not supported by argparse, an equal
sign must be used (https://bugs.python.org/issue9334)""",
)

args = parser.parse_args()

Expand All @@ -176,17 +186,6 @@ def parse_args():
elif not args.clone_mode: # if neather -p nor -c provided, use -p
args.west_path = west_top

if args.verbose >= 1:
if not args.cmake_args:
args.cmake_args = "CMAKE_VERBOSE_MAKEFILE=ON"
else:
args.cmake_args = "CMAKE_VERBOSE_MAKEFILE=ON " + args.cmake_args

# split arguments by whitespaces and append -D prefix to match expected CMake format
if args.cmake_args:
arg_list = shlex.split(args.cmake_args)
arg_list = ["-D" + arg for arg in arg_list]
args.cmake_args = " ".join(arg_list)

def execute_command(command_args, stdin=None, input=None, stdout=None, stderr=None,
capture_output=False, shell=False, cwd=None, timeout=None, check=False, encoding=None,
Expand Down Expand Up @@ -329,15 +328,31 @@ def build_platforms():
print(f"XTENSA_SYSTEM={XTENSA_SYSTEM}")

platform_build_dir_name = f"build-{platform}"

# https://docs.zephyrproject.org/latest/guides/west/build-flash-debug.html#one-time-cmake-arguments
# https://github.com/zephyrproject-rtos/zephyr/pull/40431#issuecomment-975992951
abs_build_dir = pathlib.Path(west_top, platform_build_dir_name)
if (pathlib.Path(abs_build_dir, "build.ninja").is_file()
or pathlib.Path(abs_build_dir, "Makefile").is_file()):
if args.cmake_args:
print(args.cmake_args)
raise RuntimeError("Some CMake arguments are ignored in incremental builds, "
+ f"you must delete {abs_build_dir} first")

PLAT_CONFIG = platform_dict["PLAT_CONFIG"]
build_cmd = ["west"]
if args.verbose > 0:
build_cmd.append("-v")
build_cmd += ["build", "--build-dir", platform_build_dir_name]
source_dir = pathlib.Path(west_top, "zephyr", "samples", "subsys", "audio", "sof")
build_cmd += ["--board", PLAT_CONFIG, str(source_dir)]

build_cmd.append('--')
if args.cmake_args:
build_cmd += ["--", args.cmake_args]
build_cmd += args.cmake_args
if args.verbose >= 1:
build_cmd.append("-DCMAKE_VERBOSE_MAKEFILE=ON")

# Build
execute_command(build_cmd, check=True, cwd=west_top)
smex_executable = pathlib.Path(west_top, platform_build_dir_name, "zephyr", "smex_ep",
Expand Down