Skip to content

Commit 8650355

Browse files
committed
modules: rust: implement workspace.packages()
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent bcd94d8 commit 8650355

File tree

6 files changed

+26
-0
lines changed

6 files changed

+26
-0
lines changed

docs/markdown/Rust-module.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,14 @@ automatically included.
204204

205205
## Workspace object
206206

207+
### workspace.packages()
208+
209+
```meson
210+
packages = ws.packages()
211+
```
212+
213+
Returns a list of package names in the workspace.
214+
207215
### workspace.subproject()
208216

209217
```meson

mesonbuild/modules/rust.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,17 @@ def __init__(self, interpreter: Interpreter, ws: cargo.WorkspaceState) -> None:
100100
self.interpreter = interpreter
101101
self.ws = ws
102102
self.methods.update({
103+
'packages': self.packages_method,
103104
'subproject': self.subproject_method,
104105
})
105106

107+
@noPosargs
108+
@noKwargs
109+
def packages_method(self, state: ModuleState, args: T.List, kwargs: TYPE_kwargs) -> T.List[str]:
110+
"""Returns list of package names in workspace."""
111+
package_names = [pkg.manifest.package.name for pkg in self.ws.packages.values()]
112+
return sorted(package_names)
113+
106114
def _do_subproject(self, pkg: cargo.PackageState) -> None:
107115
kw: _kwargs.DoSubproject = {
108116
'required': True,

test cases/rust/31 rust.workspace package/meson.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ project('package test', 'rust', default_options: ['rust_std=2021'])
33
rust = import('rust')
44
cargo = rust.workspace()
55

6+
# Test workspace.packages() method
7+
assert(cargo.packages() == ['answer', 'hello', 'package_test'])
8+
69
hello_rs = cargo.subproject('hello')
710
answer_rs = cargo.subproject('answer', '2')
811

test cases/rust/31 rust.workspace package/subprojects/answer-2.1/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
project('answer', 'rust', default_options: ['rust_std=2021'])
22

33
rust = import('rust')
4+
cargo = rust.workspace()
5+
assert(cargo.packages() == ['answer'])
46

57
l = static_library('answer', 'src/lib.rs')
68
dep = declare_dependency(link_with: l)

test cases/rust/32 rust.workspace workspace/meson.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ project('workspace test', 'rust', default_options: ['rust_std=2021'])
33
rust = import('rust')
44
cargo = rust.workspace()
55

6+
# Test workspace.packages() method
7+
assert(cargo.packages() == ['answer', 'hello', 'workspace_test'])
8+
69
hello_rs = cargo.subproject('hello')
710
answer_rs = cargo.subproject('answer', '2')
811

test cases/rust/32 rust.workspace workspace/subprojects/answer-2.1/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
project('answer', 'rust', default_options: ['rust_std=2021'])
22

33
rust = import('rust')
4+
cargo = rust.workspace()
5+
assert(cargo.packages() == ['answer'])
46

57
l = static_library('answer', 'src/lib.rs')
68
dep = declare_dependency(link_with: l)

0 commit comments

Comments
 (0)