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 Apr 3, 2020
1 parent 874272b commit 10d8de9
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 54 deletions.
34 changes: 25 additions & 9 deletions crate2nix/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2696,7 +2696,7 @@ rec {
)
)

# Filter out nix-build result symlinks
# Filter out nix-build result symlinks
|| (
type == "symlink" && lib.hasPrefix "result" baseName
)
Expand Down Expand Up @@ -2828,8 +2828,8 @@ rec {
)
{ inherit features crateOverrides runTests testCrateFlags testInputs; };

/* Returns an attr set with packageId mapped to the result of buildRustCrateFunc
for the corresponding crate.
/* Returns an attr set with packageId mapped to the result of buildRustCrateFunc
for the corresponding crate.
*/
builtRustCratesWithFeatures =
{ packageId
Expand Down Expand Up @@ -2895,10 +2895,26 @@ 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 (
crateConfig // {
Expand Down Expand Up @@ -2935,7 +2951,7 @@ rec {
map depDerivation enabledDependencies;

/* Returns a sanitized version of val with all values substituted that cannot
be serialized as JSON.
be serialized as JSON.
*/
sanitizeForJson = val:
if builtins.isAttrs val
Expand Down Expand Up @@ -2980,7 +2996,7 @@ rec {

/* Returns differences between cargo default features and crate2nix default
features.
This is useful for verifying the feature resolution in crate2nix.
*/
diffDefaultPackageFeatures =
Expand Down Expand Up @@ -3153,7 +3169,7 @@ rec {

/*
Returns the actual features for the given dependency.
features: The features of the crate that refers this dependency.
*/
dependencyFeatures = features: dependency:
Expand Down
34 changes: 25 additions & 9 deletions crate2nix/templates/nix/crate2nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ rec {
)
)

# Filter out nix-build result symlinks
# Filter out nix-build result symlinks
|| (
type == "symlink" && lib.hasPrefix "result" baseName
)
Expand Down Expand Up @@ -193,8 +193,8 @@ rec {
)
{ inherit features crateOverrides runTests testCrateFlags testInputs; };

/* Returns an attr set with packageId mapped to the result of buildRustCrateFunc
for the corresponding crate.
/* Returns an attr set with packageId mapped to the result of buildRustCrateFunc
for the corresponding crate.
*/
builtRustCratesWithFeatures =
{ packageId
Expand Down Expand Up @@ -260,10 +260,26 @@ 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 (
crateConfig // {
Expand Down Expand Up @@ -300,7 +316,7 @@ rec {
map depDerivation enabledDependencies;

/* Returns a sanitized version of val with all values substituted that cannot
be serialized as JSON.
be serialized as JSON.
*/
sanitizeForJson = val:
if builtins.isAttrs val
Expand Down Expand Up @@ -345,7 +361,7 @@ rec {

/* Returns differences between cargo default features and crate2nix default
features.
This is useful for verifying the feature resolution in crate2nix.
*/
diffDefaultPackageFeatures =
Expand Down Expand Up @@ -518,7 +534,7 @@ rec {

/*
Returns the actual features for the given dependency.
features: The features of the crate that refers this dependency.
*/
dependencyFeatures = features: dependency:
Expand Down
34 changes: 25 additions & 9 deletions sample_projects/bin_with_git_branch_dep/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ rec {
)
)

# Filter out nix-build result symlinks
# Filter out nix-build result symlinks
|| (
type == "symlink" && lib.hasPrefix "result" baseName
)
Expand Down Expand Up @@ -295,8 +295,8 @@ rec {
)
{ inherit features crateOverrides runTests testCrateFlags testInputs; };

/* Returns an attr set with packageId mapped to the result of buildRustCrateFunc
for the corresponding crate.
/* Returns an attr set with packageId mapped to the result of buildRustCrateFunc
for the corresponding crate.
*/
builtRustCratesWithFeatures =
{ packageId
Expand Down Expand Up @@ -362,10 +362,26 @@ 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 (
crateConfig // {
Expand Down Expand Up @@ -402,7 +418,7 @@ rec {
map depDerivation enabledDependencies;

/* Returns a sanitized version of val with all values substituted that cannot
be serialized as JSON.
be serialized as JSON.
*/
sanitizeForJson = val:
if builtins.isAttrs val
Expand Down Expand Up @@ -447,7 +463,7 @@ rec {

/* Returns differences between cargo default features and crate2nix default
features.
This is useful for verifying the feature resolution in crate2nix.
*/
diffDefaultPackageFeatures =
Expand Down Expand Up @@ -620,7 +636,7 @@ rec {

/*
Returns the actual features for the given dependency.
features: The features of the crate that refers this dependency.
*/
dependencyFeatures = features: dependency:
Expand Down
34 changes: 25 additions & 9 deletions sample_projects/bin_with_git_submodule_dep/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,7 @@ rec {
)
)

# Filter out nix-build result symlinks
# Filter out nix-build result symlinks
|| (
type == "symlink" && lib.hasPrefix "result" baseName
)
Expand Down Expand Up @@ -1468,8 +1468,8 @@ rec {
)
{ inherit features crateOverrides runTests testCrateFlags testInputs; };

/* Returns an attr set with packageId mapped to the result of buildRustCrateFunc
for the corresponding crate.
/* Returns an attr set with packageId mapped to the result of buildRustCrateFunc
for the corresponding crate.
*/
builtRustCratesWithFeatures =
{ packageId
Expand Down Expand Up @@ -1535,10 +1535,26 @@ 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 (
crateConfig // {
Expand Down Expand Up @@ -1575,7 +1591,7 @@ rec {
map depDerivation enabledDependencies;

/* Returns a sanitized version of val with all values substituted that cannot
be serialized as JSON.
be serialized as JSON.
*/
sanitizeForJson = val:
if builtins.isAttrs val
Expand Down Expand Up @@ -1620,7 +1636,7 @@ rec {

/* Returns differences between cargo default features and crate2nix default
features.
This is useful for verifying the feature resolution in crate2nix.
*/
diffDefaultPackageFeatures =
Expand Down Expand Up @@ -1793,7 +1809,7 @@ rec {

/*
Returns the actual features for the given dependency.
features: The features of the crate that refers this dependency.
*/
dependencyFeatures = features: dependency:
Expand Down
34 changes: 25 additions & 9 deletions sample_projects/codegen/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ rec {
)
)

# Filter out nix-build result symlinks
# Filter out nix-build result symlinks
|| (
type == "symlink" && lib.hasPrefix "result" baseName
)
Expand Down Expand Up @@ -647,8 +647,8 @@ rec {
)
{ inherit features crateOverrides runTests testCrateFlags testInputs; };

/* Returns an attr set with packageId mapped to the result of buildRustCrateFunc
for the corresponding crate.
/* Returns an attr set with packageId mapped to the result of buildRustCrateFunc
for the corresponding crate.
*/
builtRustCratesWithFeatures =
{ packageId
Expand Down Expand Up @@ -714,10 +714,26 @@ 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 (
crateConfig // {
Expand Down Expand Up @@ -754,7 +770,7 @@ rec {
map depDerivation enabledDependencies;

/* Returns a sanitized version of val with all values substituted that cannot
be serialized as JSON.
be serialized as JSON.
*/
sanitizeForJson = val:
if builtins.isAttrs val
Expand Down Expand Up @@ -799,7 +815,7 @@ rec {

/* Returns differences between cargo default features and crate2nix default
features.
This is useful for verifying the feature resolution in crate2nix.
*/
diffDefaultPackageFeatures =
Expand Down Expand Up @@ -972,7 +988,7 @@ rec {

/*
Returns the actual features for the given dependency.
features: The features of the crate that refers this dependency.
*/
dependencyFeatures = features: dependency:
Expand Down
Loading

0 comments on commit 10d8de9

Please sign in to comment.