From 3159732889795b0a89c6b9a0695fb9eaf54d7069 Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Tue, 2 Aug 2022 04:01:16 +0300 Subject: [PATCH] fix(rust): handle unhandled behaviour in recreating cargo lock --- src/subsystems/rust/builders/utils.nix | 55 ++++++++++++++++++-------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/src/subsystems/rust/builders/utils.nix b/src/subsystems/rust/builders/utils.nix index 2cb67cbe..cfe050fa 100644 --- a/src/subsystems/rust/builders/utils.nix +++ b/src/subsystems/rust/builders/utils.nix @@ -95,29 +95,52 @@ in rec { version, dependencies, }: let - sourceSpec = getSourceSpec name version; - source = + getSource = name: version: let + sourceSpec = getSourceSpec name version; + source = + if sourceSpec.type == "crates-io" + then "registry+https://github.com/rust-lang/crates.io-index" + else if sourceSpec.type == "git" + then let + gitSpec = + l.findFirst + (src: src.url == sourceSpec.url && src.sha == sourceSpec.rev) + (throw "no git source: ${sourceSpec.url}#${sourceSpec.rev}") + (subsystemAttrs.gitSources or {}); + refPart = + l.optionalString + (gitSpec ? type) + "?${gitSpec.type}=${gitSpec.value}"; + in "git+${sourceSpec.url}${refPart}#${sourceSpec.rev}" + else null; + in + source; + getDepSource = name: version: let + sourceSpec = getSourceSpec name version; + in if sourceSpec.type == "crates-io" - then "registry+https://github.com/rust-lang/crates.io-index" + then null else if sourceSpec.type == "git" - then let - gitSpec = - l.findFirst - (src: src.url == sourceSpec.url && src.sha == sourceSpec.rev) - (throw "no git source: ${sourceSpec.url}#${sourceSpec.rev}") - (subsystemAttrs.gitSources or {}); - refPart = - l.optionalString - (gitSpec ? type) - "?${gitSpec.type}=${gitSpec.value}"; - in "git+${sourceSpec.url}${refPart}#${sourceSpec.rev}" - else throw "source type '${sourceSpec.type}' not supported"; + then l.head (l.splitString "#" (getSource name version)) + else null; + sourceSpec = getSourceSpec name version; + source = let + src = getSource name version; + in + if src == null + then throw "source type '${sourceSpec.type}' not supported" + else src; in { inherit name version; dependencies = l.map - (dep: "${dep.name} ${dep.version}") + ( + dep: let + src = getDepSource dep.name dep.version; + srcString = l.optionalString (src != null) " (${src})"; + in "${dep.name} ${dep.version}${srcString}" + ) dependencies; } // (