Skip to content
Open
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
18 changes: 11 additions & 7 deletions src/west/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ def extension_commands(config: Configuration, manifest: Manifest | None = None):

specs = OrderedDict()
for project in manifest.projects:
if project.west_commands:
if project.west_commands_entries:
specs[project.path] = _ext_specs(project)
return specs

Expand All @@ -672,10 +672,11 @@ def _ext_specs(project):

ret = []

for cmd in project.west_commands:
for entry in project.west_commands_entries:
cmd = entry.path
spec_file = os.path.join(project.abspath, cmd)

# Verify project.west_commands isn't trying a directory traversal
# Verify the entry's path isn't trying a directory traversal
# outside of the project.
if escapes_directory(spec_file, project.abspath):
raise ExtensionCommandError(
Expand All @@ -701,10 +702,13 @@ def _ext_specs(project):
except pykwalify.errors.SchemaError as e:
raise ExtensionCommandError from e

# Resolve west command extensions relative to the manifest root for
# import-derived west-commands entries, otherwise project root.
mfst_dir = project._west_commands_manifest_dirs.get(cmd)
base_dir = os.path.join(project.abspath, mfst_dir) if mfst_dir else project.abspath
# Each entry's `file:` paths inside the spec resolve against
# entry.base_dir (a subdirectory of the project root when the
# entry was promoted from a subdirectory submanifest) or the
# project root when base_dir is empty.
base_dir = (
os.path.join(project.abspath, entry.base_dir) if entry.base_dir else project.abspath
)

for commands_desc in commands_spec['west-commands']:
ret.extend(_ext_specs_from_desc(project, commands_desc, base_dir))
Expand Down
12 changes: 8 additions & 4 deletions src/west/manifest-schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#
# DO NOT CHANGE THIS FILE WITHOUT:
#
# - updating west.manifest.SCHEMA_VERSION and
# - updating west.manifest.SCHEMA_VERSION and
# west.manifest._VALID_SCHEMA_VERS
# - reviewing and updating sphinx documentation
#
Expand Down Expand Up @@ -120,10 +120,14 @@ mapping:
clone-depth:
required: false
type: int
# Path to a west-commands.yml inside the project.
# West commands declared by this project. May be a string
# (path to a west-commands.yml inside the project), a list of
# such strings, or a list of {file, base-dir} maps where
# base-dir is the project-relative root the spec's `file:`
# entries are resolved against. Validated in Python.
west-commands:
required: false
type: str
type: any
# Additional manifest data to import from the project.
import:
required: false
Expand Down Expand Up @@ -155,7 +159,7 @@ mapping:
# commands. See the above comment for details.
west-commands:
required: false
type: str
type: any
# Additional manifest data to import from the manifest
# repository.
import:
Expand Down
Loading
Loading