@@ -2628,7 +2628,7 @@ def _import_path_from_project(self, project: Project, path: str) -> None:
26282628 return
26292629
26302630 for data in imported :
2631- self ._import_data_from_project (project , data , None )
2631+ self ._import_data_from_project (project , data , path )
26322632
26332633 _logger .debug (f'done resolving import { path } for { project } ' )
26342634
@@ -2647,16 +2647,21 @@ def _import_map_from_project(self, project: Project, imp: dict) -> None:
26472647 _logger .debug (f'done resolving import { imap } for { project } ' )
26482648
26492649 def _import_data_from_project (
2650- self , project : Project , data : Any , imap : _import_map | None
2650+ self , project : Project , data : Any , imap_or_path : _import_map | str
26512651 ) -> None :
26522652 # Destructively add the imported data into our 'projects' map.
2653-
2654- if imap is not None :
2655- imap_filter = _compose_imap_filters (self ._ctx .imap_filter , _imap_filter (imap ))
2656- imap_path_prefix = imap .path_prefix
2657- else :
2658- imap_filter = self ._ctx .imap_filter
2659- imap_path_prefix = '.'
2653+ match imap_or_path :
2654+ case _import_map ():
2655+ imap_filter = _compose_imap_filters (self ._ctx .imap_filter ,
2656+ _imap_filter (imap_or_path ))
2657+ imap_path_prefix = imap_or_path .path_prefix
2658+ path = imap_or_path .file
2659+ case str ():
2660+ imap_filter = self ._ctx .imap_filter
2661+ imap_path_prefix = '.'
2662+ path = imap_or_path
2663+ case _:
2664+ raise AssertionError (f'imap_or_path has unexpected type { type (imap_or_path )} ' )
26602665
26612666 child_ctx = self ._ctx ._replace (
26622667 imap_filter = imap_filter ,
@@ -2674,12 +2679,24 @@ def _import_data_from_project(
26742679 try :
26752680 submanifest = Manifest (topdir = self .topdir , internal_import_ctx = child_ctx )
26762681 except RecursionError as e :
2677- raise _ManifestImportDepth (None , imap . file if imap else None ) from e
2682+ raise _ManifestImportDepth (None , path ) from e
26782683
26792684 # Patch up any extension commands in the imported data
26802685 # by allocating them to the project.
2686+
2687+ # If the manifest was imported from a project subdirectory
2688+ # (manifest_path is a relative path within the project),
2689+ # we need to adjust the west_commands paths to be relative
2690+ # to the project root, not to the manifest subdirectory.
2691+ west_commands_to_merge = submanifest ._ctx .manifest_west_commands
2692+ manifest_dir = PurePosixPath (path ).parent
2693+ if manifest_dir != PurePosixPath ('.' ):
2694+ west_commands_to_merge = [
2695+ (manifest_dir / cmd ).as_posix () for cmd in west_commands_to_merge
2696+ ]
2697+
26812698 project .west_commands = _west_commands_merge (
2682- project .west_commands , submanifest . _ctx . manifest_west_commands
2699+ project .west_commands , west_commands_to_merge
26832700 )
26842701
26852702 def _import_content_from_project (self , project : Project , path : str ) -> ImportedContentType :
0 commit comments