From f334adcba0a4ca5c6363649a53082e5ddf459685 Mon Sep 17 00:00:00 2001 From: Esteve Fernandez Date: Fri, 8 Aug 2025 22:17:53 +0200 Subject: [PATCH 1/2] fix: discover non Cargo packages in a Cargo workspace Signed-off-by: Esteve Fernandez --- .../package_discovery/cargo_workspace.py | 1 + .../package_identification/cargo_workspace.py | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) 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..59408b1 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,24 @@ 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') + } + + 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 From 8b12840ec4a8ebac2e13f2177a2f2852e9c4cce1 Mon Sep 17 00:00:00 2001 From: Esteve Fernandez Date: Fri, 8 Aug 2025 23:57:41 +0200 Subject: [PATCH 2/2] fix: do not add packages that have a Cargo.toml Signed-off-by: Esteve Fernandez --- colcon_cargo/package_identification/cargo_workspace.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/colcon_cargo/package_identification/cargo_workspace.py b/colcon_cargo/package_identification/cargo_workspace.py index 59408b1..f3d53a3 100644 --- a/colcon_cargo/package_identification/cargo_workspace.py +++ b/colcon_cargo/package_identification/cargo_workspace.py @@ -55,7 +55,9 @@ def identify(self, metadata): # noqa: D102 self.workspace_package_paths.update(ws_members) all_package_paths = { - p.parent for p in pathlib.Path(metadata.path).rglob('package.xml') + 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(