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
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@
/scripts/hid_configurator/ @nrfconnect/ncs-si-bluebagel
/scripts/tools-versions-*.txt @nrfconnect/ncs-co-build-system @nrfconnect/ncs-ci
/scripts/requirements-*.txt @nrfconnect/ncs-co-build-system @nrfconnect/ncs-ci
/scripts/west_commands/utils/ @gmarull
/scripts/west_commands/create_board/ @gmarull
/scripts/west_commands/sbom/ @nrfconnect/ncs-si-muffin
/scripts/west_commands/thingy91x_dfu.py @nrfconnect/ncs-cia
Expand Down
25 changes: 18 additions & 7 deletions scripts/west_commands/create_board/ncs_create_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from pathlib import Path
import json
import shutil
import sys

from jinja2 import Environment, FileSystemLoader, TemplateNotFound
from west.commands import WestCommand
from west import log
from yaml import load
import jsonschema

Expand All @@ -16,6 +16,12 @@
except ImportError:
from yaml import Loader

sys.path.append(str(Path(__file__).parents[1]))
import utils


utils.install_json_excepthook()


SCRIPT_DIR = Path(__file__).absolute().parent
TEMPLATE_DIR = SCRIPT_DIR / "templates"
Expand Down Expand Up @@ -50,6 +56,11 @@ def do_run(self, args, unknown_args):
schema = json.loads(f.read())

if args.json_schema:
schema = {
"schema": schema,
"state": None,
}

print(json.dumps(schema))
return

Expand All @@ -62,7 +73,7 @@ def do_run(self, args, unknown_args):
try:
jsonschema.validate(input, schema)
except jsonschema.ValidationError as e:
raise Exception("Board configuration is not valid") from e
raise ValueError("Board configuration is not valid") from e

soc_parts = input["soc"].split("-")
req_soc = soc_parts[0].lower()
Expand All @@ -81,8 +92,7 @@ def do_run(self, args, unknown_args):
break

if not series:
log.err(f"Invalid/unsupported SoC: {req_soc}")
return
raise ValueError(f"Invalid/unsupported SoC: {req_soc}")

targets = []
for variant in soc["variants"]:
Expand Down Expand Up @@ -125,8 +135,7 @@ def do_run(self, args, unknown_args):
break

if not targets:
log.err(f"Invalid/unsupported variant: {req_variant}")
return
raise ValueError(f"Invalid/unsupported variant: {req_variant}")

# prepare Jinja environment
env = Environment(
Expand Down Expand Up @@ -211,4 +220,6 @@ def do_run(self, args, unknown_args):
with open(out_dir / f"{name}.yml", "w") as f:
f.write(tmpl.render(target=target))

print(f"Board {input['board']} created successfully")
# return post-commands
commands = []
print(json.dumps({"commands": commands}))
24 changes: 24 additions & 0 deletions scripts/west_commands/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) 2024 Nordic Semiconductor ASA
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause

import json
import sys
import traceback


def install_json_excepthook():
def excepthook(type, value, tb):
output = {
"errors": [
{
"type": type.__name__,
"message": str(value),
"traceback": "".join(traceback.format_tb(tb))
}
]
}

print(json.dumps(output, indent=2), file=sys.stderr)
sys.exit(1)

sys.excepthook = excepthook