Skip to content

Commit 4c4d526

Browse files
authored
Allow specification of additional packages in workspaces (#66)
When cargo itself encounters a workspace, it inspects member directories for crates and does not search any other subdirectories of the workspace for packages. The workspace support in colcon behaves the same. It may be desirable to include additional packages in colcon's discovery which are not members of the workspace. This change adds a metadata value at `workspace.metadata.colcon.additional-packages` which behaves similarly to `workspace.members` so that packages under those paths are discovered by colcon. The packages need not be cargo packages themselves but if they are, they will not be treated as cargo workspace members but rather as independent packages.
1 parent ec2b28b commit 4c4d526

6 files changed

Lines changed: 24 additions & 1 deletion

File tree

colcon_cargo/package_identification/cargo_workspace.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ def identify(self, metadata): # noqa: D102
5050
)
5151
self.workspace_package_paths.update(ws_members)
5252

53+
workspace_metadata = content['workspace'].get('metadata', {})
54+
colcon_metadata = workspace_metadata.get('colcon', {})
55+
self.workspace_package_paths.update(
56+
member
57+
for pattern in colcon_metadata.get('additional-packages', ())
58+
for member in metadata.path.glob(pattern)
59+
)
60+
5361
if 'package' not in content:
5462
# Prevent any further attempts to discover packages in this
5563
# directory and let the workspace dictate where to look for

test/rust-workspace/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ edition = "2018"
77
[workspace]
88
members = ["workspace-mem*"]
99
default-members = ["workspace-mem*"]
10+
11+
[workspace.metadata.colcon]
12+
additional-packages = ["additional-pack*"]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[package]
2+
name = "additional-package"
3+
version = "0.1.0"
4+
authors = ["Test<test@test.com>"]
5+
edition = "2018"

test/rust-workspace/additional-package/src/lib.rs

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}

test/test_build.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,14 @@ def test_package_discovery():
9898
cpi.PRIORITY: {'cargo': cpi},
9999
})
100100

101-
assert len(descs) == 1
101+
assert len(descs) == 2
102+
descs = sorted(descs, key=lambda d: d.name)
102103
desc = descs.pop()
103104
assert desc.type == 'cargo'
104105
assert desc.name == 'workspace-member'
106+
desc = descs.pop()
107+
assert desc.type == 'cargo'
108+
assert desc.name == 'additional-package'
105109

106110

107111
# Ported from Python 3.13 implementation

0 commit comments

Comments
 (0)