2020-07-07 23:29:56 +08:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2021-12-17 00:13:54 +08:00
|
|
|
include_guard(GLOBAL)
|
|
|
|
|
|
|
|
include(python)
|
|
|
|
|
2020-08-28 04:10:19 +08:00
|
|
|
# west is an optional dependency. We need to run west using the same
|
|
|
|
# Python interpreter as everything else, though, so we play some extra
|
|
|
|
# tricks.
|
|
|
|
|
|
|
|
# When west runs cmake, it sets WEST_PYTHON to its interpreter. If
|
|
|
|
# it's defined, we assume west is installed. We do these checks here
|
|
|
|
# instead of in the failure paths below to avoid CMake warnings about
|
|
|
|
# WEST_PYTHON not being used.
|
|
|
|
if(DEFINED WEST_PYTHON)
|
|
|
|
# Cut out any symbolic links, e.g. python3.x -> python
|
|
|
|
get_filename_component(west_realpath ${WEST_PYTHON} REALPATH)
|
|
|
|
get_filename_component(python_realpath ${PYTHON_EXECUTABLE} REALPATH)
|
|
|
|
|
|
|
|
# If realpaths differ from the variables we're using, add extra
|
|
|
|
# diagnostics.
|
|
|
|
if(NOT ("${west_realpath}" STREQUAL "${WEST_PYTHON}"))
|
|
|
|
set(west_realpath_msg " (real path ${west_realpath})")
|
|
|
|
else()
|
|
|
|
set(west_realpath_msg "")
|
|
|
|
endif()
|
|
|
|
if(NOT ("${python_realpath}" STREQUAL "${PYTHON_EXECUTABLE}"))
|
|
|
|
set(python_realpath_msg " (real path ${python_realpath})")
|
|
|
|
else()
|
|
|
|
set(python_realpath_msg "")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
execute_process(
|
|
|
|
COMMAND
|
|
|
|
${PYTHON_EXECUTABLE}
|
|
|
|
-c
|
|
|
|
"import west.version; print(west.version.__version__, end='')"
|
|
|
|
OUTPUT_VARIABLE west_version
|
|
|
|
ERROR_VARIABLE west_version_err
|
|
|
|
RESULT_VARIABLE west_version_output_result
|
2020-07-07 23:29:56 +08:00
|
|
|
)
|
|
|
|
|
2020-08-28 04:10:19 +08:00
|
|
|
if(west_version_output_result)
|
|
|
|
if(DEFINED WEST_PYTHON)
|
|
|
|
if(NOT (${west_realpath} STREQUAL ${python_realpath}))
|
|
|
|
set(PYTHON_EXECUTABLE_OUT_OF_SYNC "\nOr verify these installations:\n\
|
|
|
|
The Python version used by west is: ${WEST_PYTHON}${west_realpath_msg}\n\
|
|
|
|
The Python version used by CMake is: ${PYTHON_EXECUTABLE}${python_realpath_msg}")
|
2020-07-07 23:29:56 +08:00
|
|
|
endif()
|
|
|
|
|
2020-08-28 04:10:19 +08:00
|
|
|
message(FATAL_ERROR "Unable to import west.version from '${PYTHON_EXECUTABLE}':\n${west_version_err}\
|
|
|
|
Please install with:\n\
|
|
|
|
${PYTHON_EXECUTABLE} -m pip install west\
|
|
|
|
${PYTHON_EXECUTABLE_OUT_OF_SYNC}")
|
|
|
|
else()
|
|
|
|
# WEST_PYTHON is undefined and we couldn't import west. That's
|
|
|
|
# fine; it's optional.
|
2020-09-02 04:40:14 +08:00
|
|
|
set(WEST WEST-NOTFOUND CACHE INTERNAL "West")
|
2020-07-07 23:29:56 +08:00
|
|
|
endif()
|
2020-08-28 04:10:19 +08:00
|
|
|
else()
|
|
|
|
# We can import west from PYTHON_EXECUTABLE and have its version.
|
2020-07-07 23:29:56 +08:00
|
|
|
|
2020-08-28 04:10:19 +08:00
|
|
|
# Make sure its version matches the minimum required one.
|
west.cmake: make MIN_WEST_VERSION catch up with requirements-base.txt
Also add a comment in each file reminding to keep them the same.
Fixes 251f269e23f6 ("west: v0.14.0 is required now (and soon, v1.1")
Confusing error message before this commit:
```
-- Found west (found suitable version 0.13.1, minimum required is 0.7.1)
CMake Error at SOF/zephyr/cmake/modules/zephyr_module.cmake:77 (message):
Traceback (most recent call last):
File "SOF/zephyr/scripts/zephyr_module.py", line 733, in <module>
main()
File "SOF/zephyr/scripts/zephyr_module.py", line 678, in main
west_projs = west_projects()
^^^^^^^^^^^^^^^
File "SOF/zephyr/scripts/zephyr_module.py", line 536, in west_projects
from west.configuration import MalformedConfig
ImportError: cannot import name 'MalformedConfig'
from 'west.configuration'
(west/src/west/configuration.py)
```
Clearer error message after this commit:
```
CMake Error at SOF/zephyr/cmake/modules/west.cmake:68 (message):
The detected west version, 0.13.1, is unsupported.
The minimum supported version is 0.14.0.
Please upgrade with:
/usr/bin/python3.11 -m pip install --upgrade west
```
Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2023-05-20 05:28:14 +08:00
|
|
|
# Keep this version identical to the one in scripts/requirements-base.txt
|
|
|
|
set_ifndef(MIN_WEST_VERSION 0.14.0)
|
2020-07-07 23:29:56 +08:00
|
|
|
if(${west_version} VERSION_LESS ${MIN_WEST_VERSION})
|
2020-08-28 04:10:19 +08:00
|
|
|
message(FATAL_ERROR "The detected west version, ${west_version}, is unsupported.\n\
|
|
|
|
The minimum supported version is ${MIN_WEST_VERSION}.\n\
|
2020-07-07 23:29:56 +08:00
|
|
|
Please upgrade with:\n\
|
|
|
|
${PYTHON_EXECUTABLE} -m pip install --upgrade west\
|
2020-07-10 17:02:58 +08:00
|
|
|
${PYTHON_EXECUTABLE_OUT_OF_SYNC}\n")
|
2020-07-07 23:29:56 +08:00
|
|
|
endif()
|
|
|
|
|
2020-08-28 04:10:19 +08:00
|
|
|
# Set WEST to a COMMAND prefix as if it were a find_program()
|
|
|
|
# result.
|
|
|
|
#
|
|
|
|
# From west 0.8 forward, you can run 'python -m west' to run
|
|
|
|
# the command line application.
|
|
|
|
set(WEST_MODULE west)
|
|
|
|
if(${west_version} VERSION_LESS 0.8)
|
|
|
|
# In west 0.7.x, this wasn't supported yet, but it happens to be
|
|
|
|
# possible to run 'python -m west.app.main'.
|
|
|
|
string(APPEND WEST_MODULE .app.main)
|
|
|
|
endif()
|
2020-09-02 04:40:14 +08:00
|
|
|
|
|
|
|
# Need to cache this so the Zephyr Eclipse plugin knows
|
|
|
|
# how to invoke West.
|
|
|
|
set(WEST ${PYTHON_EXECUTABLE} -m ${WEST_MODULE} CACHE INTERNAL "West")
|
2020-08-28 04:10:19 +08:00
|
|
|
|
|
|
|
# Print information about the west module we're relying on. This
|
|
|
|
# will still work even after output is one line.
|
|
|
|
message(STATUS "Found west (found suitable version \"${west_version}\", minimum required is \"${MIN_WEST_VERSION}\")")
|
2020-07-07 23:29:56 +08:00
|
|
|
|
|
|
|
execute_process(
|
2020-08-28 04:10:19 +08:00
|
|
|
COMMAND ${WEST} topdir
|
|
|
|
OUTPUT_VARIABLE WEST_TOPDIR
|
2021-03-16 23:27:08 +08:00
|
|
|
ERROR_QUIET
|
|
|
|
RESULT_VARIABLE west_topdir_result
|
2020-07-07 23:29:56 +08:00
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
WORKING_DIRECTORY ${ZEPHYR_BASE}
|
|
|
|
)
|
2021-03-16 23:27:08 +08:00
|
|
|
|
|
|
|
if(west_topdir_result)
|
|
|
|
# west topdir is undefined.
|
|
|
|
# That's fine; west is optional, so could be custom Zephyr project.
|
|
|
|
set(WEST WEST-NOTFOUND CACHE INTERNAL "West")
|
|
|
|
endif()
|
2020-07-07 23:29:56 +08:00
|
|
|
endif()
|