Merge pull request #54 from nmattia/nm-rust-analyzer

Add support for wildcard members and int fields in manifests
This commit is contained in:
Nicolas Mattia 2020-01-14 20:27:23 +01:00 committed by GitHub
commit efafcff2c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 62 additions and 2 deletions

View file

@ -42,7 +42,7 @@ let
let
ty = tomlTy v;
in
if ty == "bool" then
if (ty == "bool" || ty == "int") then
builtins.toJSON v
else
if ty == "string" then

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!");
}