mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-08-16 18:00:30 +03:00
fix: allow pname and version in crates-io source spec
This commit is contained in:
parent
82693fb714
commit
0d96a7249b
@ -161,7 +161,9 @@
|
||||
"then": {
|
||||
"properties": {
|
||||
"hash": { "type": "string" },
|
||||
"type": { "type": "string" }
|
||||
"type": { "type": "string" },
|
||||
"pname": { "type": "string" },
|
||||
"version": { "type": "string" }
|
||||
},
|
||||
"required": ["type"],
|
||||
"additionalProperties": false
|
||||
|
@ -119,6 +119,7 @@ in rec {
|
||||
version,
|
||||
...
|
||||
} @ args: let
|
||||
# constructs source string for dependency
|
||||
makeSource = sourceSpec: let
|
||||
source =
|
||||
if sourceSpec.type == "crates-io"
|
||||
@ -138,13 +139,20 @@ in rec {
|
||||
else null;
|
||||
in
|
||||
source;
|
||||
# constructs source string for dependency entry
|
||||
makeDepSource = sourceSpec:
|
||||
if sourceSpec.type == "crates-io"
|
||||
then makeSource sourceSpec
|
||||
else if sourceSpec.type == "git"
|
||||
then l.concatStringsSep "#" (l.init (l.splitString "#" (makeSource sourceSpec)))
|
||||
else null;
|
||||
# removes source type information from the version
|
||||
normalizeVersion = version: srcType: l.removeSuffix ("$" + srcType) version;
|
||||
|
||||
sourceSpec = getSourceSpec name version;
|
||||
|
||||
normalizedVersion = normalizeVersion version sourceSpec.type;
|
||||
|
||||
source = let
|
||||
src = makeSource sourceSpec;
|
||||
in
|
||||
@ -157,26 +165,30 @@ in rec {
|
||||
dep: let
|
||||
depSourceSpec = getSourceSpec dep.name dep.version;
|
||||
depSource = makeDepSource depSourceSpec;
|
||||
|
||||
normalizedDepVersion = normalizeVersion dep.version depSourceSpec.type;
|
||||
|
||||
hasMultipleVersions =
|
||||
l.length (l.attrValues dreamLock.sources.${dep.name}) > 1;
|
||||
hasDuplicateVersions =
|
||||
l.hasSuffix ("$" + depSourceSpec.type) dep.version;
|
||||
hasDuplicateVersions = dep.version != normalizedDepVersion;
|
||||
|
||||
# only put version if there are different versions of the dep
|
||||
versionString =
|
||||
l.optionalString hasMultipleVersions " ${depSourceSpec.version}";
|
||||
l.optionalString hasMultipleVersions " ${normalizedDepVersion}";
|
||||
# only put source if there are duplicate versions of the dep
|
||||
# cargo vendor does not support this anyway and so builds will fail
|
||||
# until https://github.com/rust-lang/cargo/issues/10310 is resolved.
|
||||
srcString =
|
||||
l.optionalString hasDuplicateVersions " (${depSource})";
|
||||
in "${depSourceSpec.pname}${versionString}${srcString}"
|
||||
in "${dep.name}${versionString}${srcString}"
|
||||
)
|
||||
args.dependencies;
|
||||
|
||||
isMainPackage = isInPackages name version;
|
||||
in
|
||||
{
|
||||
name = sourceSpec.pname;
|
||||
version = sourceSpec.version;
|
||||
name = sourceSpec.pname or name;
|
||||
version = sourceSpec.version or normalizedVersion;
|
||||
}
|
||||
# put dependencies like how cargo expects them
|
||||
// (
|
||||
|
@ -42,10 +42,10 @@ in rec {
|
||||
makeSource = dep: let
|
||||
path = getSource dep.name dep.version;
|
||||
spec = getSourceSpec dep.name dep.version;
|
||||
stripUniqSuffix = version: l.removeSuffix ("$" + spec.type) version;
|
||||
normalizeVersion = version: l.removeSuffix ("$" + spec.type) version;
|
||||
in {
|
||||
inherit path spec dep;
|
||||
name = "${dep.name}-${stripUniqSuffix dep.version}";
|
||||
name = "${dep.name}-${normalizeVersion dep.version}";
|
||||
};
|
||||
sources = l.map makeSource deps;
|
||||
|
||||
|
@ -429,7 +429,7 @@ in {
|
||||
}
|
||||
else throw "could not find crate '${dependencyObject.name}-${dependencyObject.version}'";
|
||||
in
|
||||
final // depNameVersion;
|
||||
final;
|
||||
|
||||
git = dependencyObject: let
|
||||
parsed = source.value;
|
||||
@ -441,7 +441,6 @@ in {
|
||||
else {};
|
||||
in
|
||||
maybeRef
|
||||
// depNameVersion
|
||||
// {
|
||||
type = "git";
|
||||
url = parsed.url;
|
||||
|
Loading…
Reference in New Issue
Block a user