Expand wildcard members in manifests

This commit is contained in:
Nicolas Mattia 2020-01-14 19:50:32 +01:00
parent be6d7bfe61
commit 560601e3ab
9 changed files with 61 additions and 1 deletions

View file

@ -176,10 +176,29 @@ let
value = readTOML (root + "/${member}/Cargo.toml");
}
)
(toplevelCargotoml.workspace.members or [])
members
)
);
# The cargo members
members =
let
# the members, as listed in the virtual manifest
listedMembers = toplevelCargotoml.workspace.members or [];
# this turns members like "foo/*" into [ "foo/bar" "foo/baz" ]
# as in https://github.com/rust-analyzer/rust-analyzer/blob/b2ed130ffd9c79de26249a1dfb2a8312d6af12b3/Cargo.toml#L2
expandMember = member:
if lib.hasSuffix "/*" member
then
let
rootDir = lib.removeSuffix "/*" member;
subdirs = builtins.attrNames (builtins.readDir (root + "/${rootDir}"));
in map (subdir: "${rootDir}/${subdir}") subdirs
else [ member ];
in lib.concatMap expandMember listedMembers;
patchedSources =
let
mkRelative = po:

View file

@ -128,6 +128,8 @@ rec
cargoOptions = [ "--locked" ];
};
cargo-wildcard = naersk.buildPackage ./test/cargo-wildcard;
workspace = naersk.buildPackage ./test/workspace;
workspace-patched = naersk.buildPackage ./test/workspace-patched;

10
test/cargo-wildcard/Cargo.lock generated Normal file
View file

@ -0,0 +1,10 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "crate-a"
version = "0.1.0"
[[package]]
name = "crate-b"
version = "0.1.0"

View file

@ -0,0 +1,2 @@
[workspace]
members = [ "crates/*" ]

View file

@ -0,0 +1,9 @@
[package]
name = "crate-a"
version = "0.1.0"
authors = ["Nicolas Mattia <nicolas@nmattia.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View file

@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

View file

@ -0,0 +1,9 @@
[package]
name = "crate-b"
version = "0.1.0"
authors = ["Nicolas Mattia <nicolas@nmattia.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View file

@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

View file

@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}