mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-12-18 20:11:33 +03:00
feat(rust): workaround git dependencies that are in a workspace by locating the crate source more accurately
fix(rust): copy over findCratePath to builder fix(rust): correct getAllFiles usage
This commit is contained in:
parent
f380a81016
commit
e5e88a03b5
@ -30,6 +30,26 @@ let
|
||||
direct ++ (l.map (dep: getAllTransitiveDependencies dep.name dep.version) direct)
|
||||
));
|
||||
|
||||
# TODO: this is shared between the translator and this builder
|
||||
# we should dedup this somehow (maybe put in a common library for Rust subsystem?)
|
||||
recurseFiles = path:
|
||||
l.flatten (
|
||||
l.mapAttrsToList
|
||||
(n: v: if v == "directory" then recurseFiles "${path}/${n}" else "${path}/${n}")
|
||||
(l.readDir path)
|
||||
);
|
||||
getAllFiles = dirs: l.flatten (l.map recurseFiles dirs);
|
||||
getCargoTomlPaths = l.filter (path: l.baseNameOf path == "Cargo.toml");
|
||||
getCargoTomls = l.map (path: { inherit path; value = l.fromTOML (l.readFile path); });
|
||||
getCargoPackages = l.filter (toml: l.hasAttrByPath [ "package" "name" ] toml.value);
|
||||
findCratePath = cargoPackages: name:
|
||||
l.dirOf (
|
||||
l.findFirst
|
||||
(toml: toml.value.package.name == name)
|
||||
(throw "could not find crate ${name}")
|
||||
cargoPackages
|
||||
).path;
|
||||
|
||||
# TODO: implement a user option that will make the vendoring
|
||||
# copy sources instead of symlinking them. This can be useful
|
||||
# for some Rust packages that modify their own dependencies
|
||||
@ -38,9 +58,18 @@ let
|
||||
let
|
||||
deps = getAllTransitiveDependencies pname version;
|
||||
|
||||
makeSource = dep: {
|
||||
makeSource = dep:
|
||||
let
|
||||
# These locate the actual path of the crate in the source...
|
||||
# This is important because git dependencies may or may not be in a
|
||||
# workspace with complex crate hierarchies. This can locate the crate
|
||||
# accurately using Cargo.toml files.
|
||||
srcPath = getSource dep.name dep.version;
|
||||
cargoPackages = l.pipe [ srcPath ] [ getAllFiles getCargoTomlPaths getCargoTomls getCargoPackages ];
|
||||
path = findCratePath cargoPackages dep.name;
|
||||
in {
|
||||
name = "${dep.name}-${dep.version}";
|
||||
path = getSource dep.name dep.version;
|
||||
inherit path;
|
||||
};
|
||||
sources = l.map makeSource deps;
|
||||
in
|
||||
|
@ -24,17 +24,19 @@
|
||||
(n: v: if v == "directory" then recurseFiles "${path}/${n}" else "${path}/${n}")
|
||||
(l.readDir path)
|
||||
);
|
||||
getAllFiles = dirs: l.flatten (l.map recurseFiles dirs);
|
||||
|
||||
getCargoTomlPaths = l.filter (path: l.baseNameOf path == "Cargo.toml");
|
||||
getCargoTomls = l.map (path: { inherit path; value = l.fromTOML (l.readFile path); });
|
||||
getCargoPackages = l.filter (toml: l.hasAttrByPath [ "package" "name" ] toml.value);
|
||||
|
||||
# Find all Cargo.toml files and parse them
|
||||
allFiles = l.flatten (l.map recurseFiles inputDirectories);
|
||||
cargoTomlPaths = l.filter (path: l.baseNameOf path == "Cargo.toml") allFiles;
|
||||
cargoTomls = l.map (path: { inherit path; value = l.fromTOML (l.readFile path); }) cargoTomlPaths;
|
||||
allFiles = getAllFiles inputDirectories;
|
||||
cargoTomlPaths = getCargoTomlPaths allFiles;
|
||||
cargoTomls = getCargoTomls cargoTomlPaths;
|
||||
|
||||
# Filter cargo-tomls to for files that actually contain packages
|
||||
cargoPackages =
|
||||
l.filter
|
||||
(toml: l.hasAttrByPath [ "package" "name" ] toml.value)
|
||||
cargoTomls;
|
||||
cargoPackages = getCargoPackages cargoTomls;
|
||||
|
||||
packageName =
|
||||
if args.packageName == "{automatic}"
|
||||
|
Loading…
Reference in New Issue
Block a user