scripts: west-commands: Updates needed when removing ZEPHYR_BASE env
This commit includes the following fixes in order to remove environment setting of ZEPHYR_BASE is west extension commands. - Build command west build --pristine will now use the ZEPHYR_BASE variable found in CMakeCache.txt in the build folder. This ensures that the pristine command is executed from the same Zephyr that was used for compilation. - Board command The west boards command no longer sets Zephyr base before invoking cmake -P cmake/boards.cmake Instead boards.cmake uses find_package(Zephyr) to ensure consistent behavior with Zephyr samples, so that the detection of Zephyr base is uniform across CMake commands. It also changes BOARD_ROOT_SPACE_SEPARATED to BOARD_ROOT in order to be consistent with existing user documentation. Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no> Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit is contained in:
parent
8e929fd20c
commit
e819fa46cd
5 changed files with 22 additions and 34 deletions
|
@ -95,18 +95,17 @@ if(CMAKE_SCRIPT_MODE_FILE AND NOT CMAKE_PARENT_LIST_FILE)
|
|||
# some other script
|
||||
|
||||
# The options available are:
|
||||
# BOARD_ROOT_SPACE_SEPARATED: Space-separated board roots
|
||||
# BOARD_ROOT: Semi-colon separated board roots
|
||||
# FILE_OUT: Set to a file path to save the boards to a file. If not defined the
|
||||
# the contents will be printed to stdout
|
||||
if(NOT DEFINED ZEPHYR_BASE)
|
||||
message(FATAL_ERROR "ZEPHYR_BASE not set")
|
||||
endif()
|
||||
cmake_minimum_required(VERSION 3.13.1)
|
||||
|
||||
if (NOT BOARD_ROOT_SPACE_SEPARATED)
|
||||
message(FATAL_ERROR "BOARD_ROOT_SPACE_SEPARATED not defined")
|
||||
endif()
|
||||
set(NO_BOILERPLATE TRUE)
|
||||
find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})
|
||||
|
||||
string(REPLACE " " ";" BOARD_ROOT "${BOARD_ROOT_SPACE_SEPARATED}")
|
||||
# Appending Zephyr base to list of board roots, as this is also done in boilerplate.cmake.
|
||||
# But as this file was executed in script mode, it must also be done here, to give same output.
|
||||
list(APPEND BOARD_ROOT ${ZEPHYR_BASE})
|
||||
|
||||
if (NOT FILE_OUT)
|
||||
set(FILE_OUT FALSE)
|
||||
|
|
|
@ -4,13 +4,14 @@
|
|||
|
||||
import argparse
|
||||
import collections
|
||||
import os
|
||||
import re
|
||||
import textwrap
|
||||
|
||||
from west import log
|
||||
from west.commands import WestCommand
|
||||
|
||||
from zcmake import run_cmake
|
||||
from zephyr_ext_common import ZEPHYR_CMAKE
|
||||
|
||||
class Boards(WestCommand):
|
||||
|
||||
|
@ -54,13 +55,7 @@ class Boards(WestCommand):
|
|||
return parser
|
||||
|
||||
def do_run(self, args, unknown_args):
|
||||
zb = os.environ.get('ZEPHYR_BASE')
|
||||
if not zb:
|
||||
log.die('Internal error: ZEPHYR_BASE not set in the environment, '
|
||||
'and should have been by the main script')
|
||||
|
||||
cmake_args = ['-DBOARD_ROOT_SPACE_SEPARATED={}'.format(zb),
|
||||
'-P', '{}/cmake/boards.cmake'.format(zb)]
|
||||
cmake_args = ['-P', f'{ZEPHYR_CMAKE}/boards.cmake']
|
||||
lines = run_cmake(cmake_args, capture_output=True)
|
||||
arch_re = re.compile(r'\s*([\w-]+)\:')
|
||||
board_re = re.compile(r'\s*([\w-]+)\s*')
|
||||
|
|
|
@ -400,17 +400,12 @@ class Build(Forceable):
|
|||
|
||||
def _run_pristine(self):
|
||||
_banner('making build dir {} pristine'.format(self.build_dir))
|
||||
|
||||
zb = os.environ.get('ZEPHYR_BASE')
|
||||
if not zb:
|
||||
log.die('Internal error: ZEPHYR_BASE not set in the environment, '
|
||||
'and should have been by the main script')
|
||||
|
||||
if not is_zephyr_build(self.build_dir):
|
||||
log.die('Refusing to run pristine on a folder that is not a '
|
||||
'Zephyr build system')
|
||||
|
||||
cmake_args = ['-P', '{}/cmake/pristine.cmake'.format(zb)]
|
||||
cache = CMakeCache.from_build_dir(self.build_dir)
|
||||
cmake_args = ['-P', cache['ZEPHYR_BASE'] + '/cmake/pristine.cmake']
|
||||
run_cmake(cmake_args, cwd=self.build_dir, dry_run=self.args.dry_run)
|
||||
|
||||
def _run_build(self, target):
|
||||
|
|
|
@ -18,9 +18,9 @@ from build_helpers import find_build_dir, is_zephyr_build, \
|
|||
from runners.core import BuildConfiguration
|
||||
from zcmake import CMakeCache
|
||||
from zephyr_ext_common import Forceable, cached_runner_config, \
|
||||
zephyr_scripts_path
|
||||
ZEPHYR_SCRIPTS
|
||||
|
||||
sys.path.append(os.path.join(zephyr_scripts_path(), 'dts'))
|
||||
sys.path.append(str(ZEPHYR_SCRIPTS / 'dts'))
|
||||
|
||||
import edtlib
|
||||
|
||||
|
|
|
@ -16,6 +16,14 @@ from west.commands import WestCommand
|
|||
|
||||
from runners.core import RunnerConfig
|
||||
|
||||
# This relies on this file being zephyr/scripts/foo/bar.py.
|
||||
# If you move this file, you'll break it, so be careful.
|
||||
THIS_ZEPHYR = Path(__file__).parent.parent.parent
|
||||
ZEPHYR_BASE = Path(os.environ.get('ZEPHYR_BASE', THIS_ZEPHYR))
|
||||
|
||||
# FIXME we need a nicer way to handle imports from scripts and cmake than this.
|
||||
ZEPHYR_SCRIPTS = ZEPHYR_BASE / 'scripts'
|
||||
ZEPHYR_CMAKE = ZEPHYR_BASE / 'cmake'
|
||||
|
||||
class Forceable(WestCommand):
|
||||
'''WestCommand subclass for commands with a --force option.'''
|
||||
|
@ -55,12 +63,3 @@ def cached_runner_config(build_dir, cache):
|
|||
elf_file, hex_file, bin_file,
|
||||
gdb=gdb, openocd=openocd,
|
||||
openocd_search=openocd_search)
|
||||
|
||||
# FIXME we should think of a nicer way to manage sys.path
|
||||
# for shared Zephyr code.
|
||||
def zephyr_scripts_path():
|
||||
# This relies on this file being zephyr/scripts/foo/bar.py.
|
||||
zephyr_base = Path(os.environ.get('ZEPHYR_BASE',
|
||||
Path(__file__).parent.parent.parent))
|
||||
|
||||
return str(zephyr_base / 'scripts')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue