diff --git a/colcon_cargo/package_discovery/cargo_workspace.py b/colcon_cargo/package_discovery/cargo_workspace.py index d4655ca..b2db78e 100644 --- a/colcon_cargo/package_discovery/cargo_workspace.py +++ b/colcon_cargo/package_discovery/cargo_workspace.py @@ -35,6 +35,7 @@ def discover(self, *, args, identification_extensions): # noqa: D102 for extension in extensions_same_prio.values(): if isinstance(extension, CargoWorkspaceIdentification): paths.update(extension.workspace_package_paths) + paths.update(extension.non_cargo_paths) extension.workspace_package_paths.clear() descs = set() diff --git a/colcon_cargo/package_identification/cargo_workspace.py b/colcon_cargo/package_identification/cargo_workspace.py index 823dfe8..f3d53a3 100644 --- a/colcon_cargo/package_identification/cargo_workspace.py +++ b/colcon_cargo/package_identification/cargo_workspace.py @@ -1,6 +1,8 @@ # Copyright 2025 Open Source Robotics Foundation, Inc. # Licensed under the Apache License, Version 2.0 +import pathlib + from colcon_cargo.package_identification.cargo import read_cargo_toml from colcon_core.package_identification import IgnoreLocationException from colcon_core.package_identification \ @@ -25,6 +27,7 @@ def __init__(self): # noqa: D107 PackageIdentificationExtensionPoint.EXTENSION_POINT_VERSION, '^1.0') self.workspace_package_paths = set() + self.non_cargo_paths = set() def identify(self, metadata): # noqa: D102 if metadata.type is not None and metadata.type != 'cargo': @@ -43,13 +46,26 @@ def identify(self, metadata): # noqa: D102 for pattern in content['workspace'].get('members', ()) for member in metadata.path.glob(pattern) } - ws_members.difference_update( + excluded_ws_members = { exclude for pattern in content['workspace'].get('exclude', ()) for exclude in metadata.path.glob(pattern) - ) + } + ws_members.difference_update(excluded_ws_members) self.workspace_package_paths.update(ws_members) + all_package_paths = { + p.parent + for p in pathlib.Path(metadata.path).rglob('package.xml') + if not pathlib.Path(p.parent / 'Cargo.toml').is_file() + } + + self.non_cargo_paths.update( + all_package_paths.difference( + self.workspace_package_paths, excluded_ws_members + ) + ) + if 'package' not in content: # Prevent any further attempts to discover packages in this # directory and let the workspace dictate where to look for