Skip to content

Commit

Permalink
Fix #83 - versioned crateRenames
Browse files Browse the repository at this point in the history
  • Loading branch information
kolloch committed May 29, 2020
1 parent 32ec34d commit 3063c47
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 12 deletions.
22 changes: 20 additions & 2 deletions crate2nix/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2431,9 +2431,27 @@ rec {
++ devDependencies
)
);
# Crate renames have the form:
#
# {
# crate_name = [
# { version = "1.2.3"; rename = "crate_name01"; }
# ];
# # ...
# }
crateRenames =
builtins.listToAttrs
(map (d: { name = d.name; value = d.rename; }) dependenciesWithRenames);
let
grouped =
lib.groupBy
(dependency: dependency.name)
dependenciesWithRenames;
versionAndRename = dep:
let
package = builtByPackageId."${dep.packageId}";
in
{ inherit (dep) rename; version = package.version; };
in
lib.mapAttrs (name: choices: builtins.map versionAndRename choices) grouped;
in
buildRustCrateFunc
(
Expand Down
22 changes: 20 additions & 2 deletions crate2nix/templates/nix/crate2nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,27 @@ rec {
++ devDependencies
)
);
# Crate renames have the form:
#
# {
# crate_name = [
# { version = "1.2.3"; rename = "crate_name01"; }
# ];
# # ...
# }
crateRenames =
builtins.listToAttrs
(map (d: { name = d.name; value = d.rename; }) dependenciesWithRenames);
let
grouped =
lib.groupBy
(dependency: dependency.name)
dependenciesWithRenames;
versionAndRename = dep:
let
package = builtByPackageId."${dep.packageId}";
in
{ inherit (dep) rename; version = package.version; };
in
lib.mapAttrs (name: choices: builtins.map versionAndRename choices) grouped;
in
buildRustCrateFunc
(
Expand Down
22 changes: 20 additions & 2 deletions sample_projects/bin_with_git_branch_dep/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,27 @@ rec {
++ devDependencies
)
);
# Crate renames have the form:
#
# {
# crate_name = [
# { version = "1.2.3"; rename = "crate_name01"; }
# ];
# # ...
# }
crateRenames =
builtins.listToAttrs
(map (d: { name = d.name; value = d.rename; }) dependenciesWithRenames);
let
grouped =
lib.groupBy
(dependency: dependency.name)
dependenciesWithRenames;
versionAndRename = dep:
let
package = builtByPackageId."${dep.packageId}";
in
{ inherit (dep) rename; version = package.version; };
in
lib.mapAttrs (name: choices: builtins.map versionAndRename choices) grouped;
in
buildRustCrateFunc
(
Expand Down
22 changes: 20 additions & 2 deletions sample_projects/bin_with_git_submodule_dep/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1555,9 +1555,27 @@ rec {
++ devDependencies
)
);
# Crate renames have the form:
#
# {
# crate_name = [
# { version = "1.2.3"; rename = "crate_name01"; }
# ];
# # ...
# }
crateRenames =
builtins.listToAttrs
(map (d: { name = d.name; value = d.rename; }) dependenciesWithRenames);
let
grouped =
lib.groupBy
(dependency: dependency.name)
dependenciesWithRenames;
versionAndRename = dep:
let
package = builtByPackageId."${dep.packageId}";
in
{ inherit (dep) rename; version = package.version; };
in
lib.mapAttrs (name: choices: builtins.map versionAndRename choices) grouped;
in
buildRustCrateFunc
(
Expand Down
22 changes: 20 additions & 2 deletions sample_projects/codegen/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -734,9 +734,27 @@ rec {
++ devDependencies
)
);
# Crate renames have the form:
#
# {
# crate_name = [
# { version = "1.2.3"; rename = "crate_name01"; }
# ];
# # ...
# }
crateRenames =
builtins.listToAttrs
(map (d: { name = d.name; value = d.rename; }) dependenciesWithRenames);
let
grouped =
lib.groupBy
(dependency: dependency.name)
dependenciesWithRenames;
versionAndRename = dep:
let
package = builtByPackageId."${dep.packageId}";
in
{ inherit (dep) rename; version = package.version; };
in
lib.mapAttrs (name: choices: builtins.map versionAndRename choices) grouped;
in
buildRustCrateFunc
(
Expand Down
22 changes: 20 additions & 2 deletions sample_projects/sub_dir_crates/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,27 @@ rec {
++ devDependencies
)
);
# Crate renames have the form:
#
# {
# crate_name = [
# { version = "1.2.3"; rename = "crate_name01"; }
# ];
# # ...
# }
crateRenames =
builtins.listToAttrs
(map (d: { name = d.name; value = d.rename; }) dependenciesWithRenames);
let
grouped =
lib.groupBy
(dependency: dependency.name)
dependenciesWithRenames;
versionAndRename = dep:
let
package = builtByPackageId."${dep.packageId}";
in
{ inherit (dep) rename; version = package.version; };
in
lib.mapAttrs (name: choices: builtins.map versionAndRename choices) grouped;
in
buildRustCrateFunc
(
Expand Down
7 changes: 7 additions & 0 deletions tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,13 @@ let
expectedOutput = "Hello, futures_compat!";
}

{
name = "futures_util_multiple_version";
src = ./sample_projects/futures_compat;
cargoToml = "Cargo.toml";
expectedOutput = "Hello, futures_compat!";
}

{
name = "numtest";
src = ./sample_projects/numtest;
Expand Down

0 comments on commit 3063c47

Please sign in to comment.