Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 6 additions & 3 deletions scripts/board_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
from infuse_iot.util.argparse import ValidDir


def board_copy(args):
input_base = args.input.name
output_base = args.output.name
def board_copy(args: argparse.Namespace):
input_base: str = args.input.name
output_base: str = args.output.name

# Copy the base files
shutil.copytree(args.input, args.output, dirs_exist_ok=True)

for filename in os.listdir(args.output):
if (args.output / filename).is_dir():
# Skip directories for now
continue
if input_base in filename:
# Replace the old board name in the file path
new_filename = filename.replace(input_base, output_base)
Expand Down
27 changes: 17 additions & 10 deletions scripts/west_commands/vscode.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
def author():
"""Get current git user configuration"""

def git_config(config):
def git_config(config: str):
proc = subprocess.run(
["git", "config", config], stdout=subprocess.PIPE, check=False
)
Expand Down Expand Up @@ -230,7 +230,12 @@ def do_add_parser(self, parser_adder):
parser.add_argument("--snr", type=str, help="JTAG serial number")
return parser

def cpp_properties(self, build_dir, cache, include_path=True):
def cpp_properties(
self,
build_dir: pathlib.Path,
cache: zcmake.CMakeCache,
include_path: bool = True,
):
c_cpp_properties["configurations"][0]["compilerPath"] = cache.get(
"CMAKE_C_COMPILER"
)
Expand All @@ -239,7 +244,7 @@ def cpp_properties(self, build_dir, cache, include_path=True):
str(build_dir / "zephyr" / "include" / "generated")
]

def _tfm_build(self, build_dir, cache):
def _tfm_build(self, build_dir: pathlib.Path, _cache: zcmake.CMakeCache):
launch["configurations"][0]["executable"] = str(build_dir / "bin" / "tfm_s.elf")
launch["configurations"][1]["executable"] = str(build_dir / "bin" / "tfm_s.elf")

Expand All @@ -255,7 +260,7 @@ def _tfm_build(self, build_dir, cache):
launch["configurations"][0]["gdbPath"] = parent_cache.get("CMAKE_GDB")
launch["configurations"][1]["gdbPath"] = parent_cache.get("CMAKE_GDB")

def _tfm_sub_image(self, build_dir):
def _tfm_sub_image(self, build_dir: pathlib.Path):
tfm_elfs = [
"bl2.elf",
"tfm_s.elf",
Expand All @@ -268,7 +273,7 @@ def _tfm_sub_image(self, build_dir):
f"add-symbol-file {str(path)}" for path in tfm_exists
]

def _zephyr_build(self, build_dir, cache):
def _zephyr_build(self, build_dir: pathlib.Path, cache: zcmake.CMakeCache):
self.cpp_properties(build_dir, cache)

launch["configurations"][0]["gdbPath"] = cache.get("CMAKE_GDB")
Expand All @@ -295,7 +300,7 @@ def _zephyr_build(self, build_dir, cache):
f"add-symbol-file {str(mcuboot_elf.resolve())}"
]

def _qemu(self, build_dir, cache):
def _qemu(self, build_dir: pathlib.Path, cache: zcmake.CMakeCache):
assert cache.get("QEMU", False)

self.cpp_properties(build_dir, cache)
Expand All @@ -321,7 +326,7 @@ def _qemu(self, build_dir, cache):
build_dir / "zephyr" / "zephyr.elf"
)

def _native(self, build_dir, cache):
def _native(self, build_dir: pathlib.Path, cache: zcmake.CMakeCache):
assert cache.get("BOARD")[:10] in [
"native_sim",
"nrf52_bsim",
Expand Down Expand Up @@ -365,7 +370,9 @@ def _jlink_device(self, runners_yaml):
launch["configurations"][0]["rtos"] = "Zephyr"
launch["configurations"][1]["rtos"] = "Zephyr"

def _jlink(self, snr, build_dir, cache, runners_yaml):
def _jlink(
self, snr, build_dir: pathlib.Path, cache: zcmake.CMakeCache, runners_yaml
):
self._jlink_device(runners_yaml)
if snr is not None:
launch["configurations"][0]["serialNumber"] = snr
Expand Down Expand Up @@ -420,7 +427,7 @@ def _openocd_svd_search(self, vscode_folder: pathlib.Path, device: str):

return str(svd_output)

def _openocd(self, build_dir, cache, runners_yaml, vscode_folder):
def _openocd(self, build_dir: pathlib.Path, cache, runners_yaml, vscode_folder):
board_dir = cache["BOARD_DIR"]
cfg_path = f"{board_dir}/support/openocd.cfg"

Expand All @@ -440,7 +447,7 @@ def _openocd(self, build_dir, cache, runners_yaml, vscode_folder):
launch["configurations"][0]["svdFile"] = svd_path
launch["configurations"][1]["svdFile"] = svd_path

def _physical_hardware(self, build_dir, cache):
def _physical_hardware(self, build_dir: pathlib.Path, cache: zcmake.CMakeCache):
if build_dir.parts[-1] == "tfm":
self._tfm_build(build_dir, cache)
else:
Expand Down
88 changes: 48 additions & 40 deletions scripts/west_commands/zcmake.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
# Copyright (c) 2018 Open Source Foundries Limited.
#
# SPDX-License-Identifier: Apache-2.0
'''Common definitions for building Zephyr applications with CMake.
"""Common definitions for building Zephyr applications with CMake.

This provides some default settings and convenience wrappers for
building Zephyr applications needed by multiple commands.

See build.py for the build command itself.
'''
"""

from __future__ import annotations

from collections import OrderedDict
from typing import final

import re
import os

DEFAULT_CACHE = 'CMakeCache.txt'
DEFAULT_CMAKE_GENERATOR = 'Ninja'
DEFAULT_CACHE = "CMakeCache.txt"
DEFAULT_CMAKE_GENERATOR = "Ninja"


@final
class CMakeCacheEntry:
'''Represents a CMake cache entry.
"""Represents a CMake cache entry.

This class understands the type system in a CMakeCache.txt, and
converts the following cache types to Python types:
Expand All @@ -33,7 +38,7 @@ class CMakeCacheEntry:
STATIC str OR list of str (if ';' is in the value)
UNINITIALIZED str OR list of str (if ';' is in the value)
---------- -------------------------------------------
'''
"""

# Regular expression for a cache entry.
#
Expand All @@ -43,13 +48,15 @@ class CMakeCacheEntry:
# the first colon (':'). This breaks if the variable name has a
# colon inside, but it's good enough.
CACHE_ENTRY = re.compile(
r'''(?P<name>.*?) # name
r"""(?P<name>.*?) # name
:(?P<type>FILEPATH|PATH|STRING|BOOL|INTERNAL|STATIC|UNINITIALIZED) # type
=(?P<value>.*) # value
''', re.X)
""",
re.X,
)

@classmethod
def _to_bool(cls, val):
def _to_bool(cls, val: str):
# Convert a CMake BOOL string into a Python bool.
#
# "True if the constant is 1, ON, YES, TRUE, Y, or a
Expand All @@ -61,26 +68,26 @@ def _to_bool(cls, val):
#
# https://cmake.org/cmake/help/v3.0/command/if.html
val = val.upper()
if val in ('ON', 'YES', 'TRUE', 'Y'):
if val in ("ON", "YES", "TRUE", "Y"):
return True
elif val in ('OFF', 'NO', 'FALSE', 'N', 'IGNORE', 'NOTFOUND', ''):
elif val in ("OFF", "NO", "FALSE", "N", "IGNORE", "NOTFOUND", ""):
return False
elif val.endswith('-NOTFOUND'):
elif val.endswith("-NOTFOUND"):
return False
elif val == 'NEVER':
elif val == "NEVER":
return False
else:
try:
v = int(val)
return v != 0
except ValueError as exc:
raise ValueError('invalid bool {}'.format(val)) from exc
raise ValueError("invalid bool {}".format(val)) from exc

@classmethod
def from_line(cls, line, line_no):
def from_line(cls, line: str, line_no: int) -> None | CMakeCacheEntry:
# Comments can only occur at the beginning of a line.
# (The value of an entry could contain a comment character).
if line.startswith('//') or line.startswith('#'):
if line.startswith("//") or line.startswith("#"):
return None

# Whitespace-only lines do not contain cache entries.
Expand All @@ -91,58 +98,62 @@ def from_line(cls, line, line_no):
if not m:
return None

name, type_, value = (m.group(g) for g in ('name', 'type', 'value'))
if type_ == 'BOOL':
name, type_, value = (m.group(g) for g in ("name", "type", "value"))
if type_ == "BOOL":
try:
value = cls._to_bool(value)
except ValueError as exc:
args = exc.args + ('on line {}: {}'.format(line_no, line),)
args = exc.args + ("on line {}: {}".format(line_no, line),)
raise ValueError(args) from exc
elif type_ in {'STRING', 'INTERNAL', 'STATIC', 'UNINITIALIZED'}:
elif type_ in {"STRING", "INTERNAL", "STATIC", "UNINITIALIZED"}:
# If the value is a CMake list (i.e. is a string which
# contains a ';'), convert to a Python list.
if ';' in value:
value = value.split(';')
if ";" in value:
value = value.split(";")

return CMakeCacheEntry(name, value)

def __init__(self, name, value):
def __init__(self, name: str, value: bool | str | list[str]):
self.name = name
self.value = value

def __str__(self):
fmt = 'CMakeCacheEntry(name={}, value={})'
fmt = "CMakeCacheEntry(name={}, value={})"
return fmt.format(self.name, self.value)


@final
class CMakeCache:
'''Parses and represents a CMake cache file.'''
"""Parses and represents a CMake cache file."""

@staticmethod
def from_build_dir(build_dir):
def from_build_dir(build_dir: str) -> CMakeCache:
return CMakeCache(os.path.join(build_dir, DEFAULT_CACHE))

def __init__(self, cache_file):
def __init__(self, cache_file: str):
self._entries: OrderedDict[str, CMakeCacheEntry]
self.cache_file = cache_file
self.load(cache_file)

def load(self, cache_file):
entries = []
with open(cache_file, 'r', encoding="utf-8") as cache:
def load(self, cache_file: str):
entries: list[CMakeCacheEntry] = []
with open(cache_file, "r", encoding="utf-8") as cache:
for line_no, line in enumerate(cache):
entry = CMakeCacheEntry.from_line(line, line_no)
if entry:
entries.append(entry)
self._entries = OrderedDict((e.name, e) for e in entries)

def get(self, name, default=None):
def get(
self, name: str, default: None | bool | str | list[str] = None
) -> None | bool | str | list[str]:
entry = self._entries.get(name)
if entry is not None:
return entry.value
else:
return default

def get_list(self, name, default=None):
def get_list(self, name: str, default: None | bool | str | list[str] = None):
if default is None:
default = []
entry = self._entries.get(name)
Expand All @@ -153,24 +164,21 @@ def get_list(self, name, default=None):
elif isinstance(value, str):
return [value] if value else []
else:
msg = 'invalid value {} type {}'
msg = "invalid value {} type {}"
raise RuntimeError(msg.format(value, type(value)))
else:
return default

def __contains__(self, name):
def __contains__(self, name: str):
return name in self._entries

def __getitem__(self, name):
def __getitem__(self, name: str):
return self._entries[name].value

def __setitem__(self, name, entry):
if not isinstance(entry, CMakeCacheEntry):
msg = 'improper type {} for value {}, expecting CMakeCacheEntry'
raise TypeError(msg.format(type(entry), entry))
def __setitem__(self, name: str, entry: CMakeCacheEntry):
self._entries[name] = entry

def __delitem__(self, name):
def __delitem__(self, name: str):
del self._entries[name]

def __iter__(self):
Expand Down
31 changes: 28 additions & 3 deletions scripts/west_commands/zed.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
use with the Embeint SDK.
"""

settings = {"lsp": {"clangd": {"binary": {"arguments": []}}}}


class zed(WestCommand):
def __init__(self):
Expand Down Expand Up @@ -57,6 +55,7 @@ def do_run(self, args, _):
zed_folder = pathlib.Path(args.workspace) / ".zed"
zed_folder.mkdir(exist_ok=True)

workspace_dir = pathlib.Path(args.workspace).absolute().resolve()
build_dir = pathlib.Path(args.dir).absolute().resolve()
cache = zcmake.CMakeCache.from_build_dir(build_dir)
runners_yaml = None
Expand All @@ -79,7 +78,33 @@ def do_run(self, args, _):
compiler_folder = pathlib.Path(cache.get("CMAKE_GDB")).parent
clangd_args.append(f"--query-driver={compiler_folder}/**")

settings["lsp"]["clangd"]["binary"]["arguments"] = clangd_args
settings = {
"lsp": {
"clangd": {
"binary": {
"arguments": clangd_args,
}
}
},
"languages": {
"C": {
"formatter": {
"external": {
"command": "clang-format",
"arguments": [
f"--style=file:{workspace_dir}/infuse-sdk/.clang-format",
"--assume-filename={buffer_path}",
],
}
},
"format_on_save": "on",
"tab_size": 8,
}
},
"file_types": {
"C": ["h"],
},
}

log.inf(f"Writing `settings.json` to {zed_folder}")

Expand Down
1 change: 1 addition & 0 deletions subsys/task_runner/tasks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ zephyr_library_sources_ifdef(CONFIG_TASK_RUNNER_TASK_TDF_LOGGER task_tdf_logger.
zephyr_library_sources_ifdef(CONFIG_TASK_RUNNER_TASK_GNSS task_gnss_common.c)
zephyr_library_sources_ifdef(CONFIG_TASK_RUNNER_TASK_GNSS_UBX task_gnss_ubx.c)
zephyr_library_sources_ifdef(CONFIG_TASK_RUNNER_TASK_GNSS_NRF9X task_gnss_nrf9x.c)
zephyr_library_sources_ifdef(CONFIG_TASK_RUNNER_TASK_GNSS_ZEPHYR task_gnss_zephyr.c)
zephyr_library_sources_ifdef(CONFIG_TASK_RUNNER_TASK_NETWORK_SCAN task_network_scan.c)
5 changes: 5 additions & 0 deletions subsys/task_runner/tasks/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ config TASK_RUNNER_TASK_GNSS_NRF9X
select INFUSE_ZBUS_CHAN_NRF9X_NAV_PVT
depends on (GNSS_NRF9X && LTE_LINK_CONTROL) || GNSS_NRF9X_EMUL

config TASK_RUNNER_TASK_GNSS_ZEPHYR
bool "Generic Zephyr GNSS device"
select TASK_RUNNER_TASK_GNSS_THREAD
depends on GNSS

endchoice

config TASK_RUNNER_TASK_GNSS_STACK_SIZE
Expand Down
Loading
Loading