bazel_7: improve lockfile parsing
This commit is contained in:
parent
bc3cba3845
commit
166e47c58b
2 changed files with 45 additions and 27 deletions
|
@ -36,23 +36,26 @@ let
|
||||||
then builtins.substring 2 (-1) str
|
then builtins.substring 2 (-1) str
|
||||||
else str;
|
else str;
|
||||||
|
|
||||||
|
# We take any "attributes" object that has a "sha256" field. Every value
|
||||||
|
# under "attributes" is assumed to be an object, and all the "attributes"
|
||||||
|
# with a "sha256" field are assumed to have either a "urls" or "url" field.
|
||||||
|
#
|
||||||
|
# We add them to the `acc`umulator:
|
||||||
|
#
|
||||||
|
# acc // {
|
||||||
|
# "ffad2b06ef2e09d040...fc8e33706bb01634" = fetchurl {
|
||||||
|
# name = "source";
|
||||||
|
# sha256 = "ffad2b06ef2e09d040...fc8e33706bb01634";
|
||||||
|
# urls = [
|
||||||
|
# "https://mirror.bazel.build/github.com/golang/library.zip",
|
||||||
|
# "https://github.com/golang/library.zip"
|
||||||
|
# ];
|
||||||
|
# };
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# !REMINDER! This works on a best-effort basis, so try to keep it from
|
||||||
|
# failing loudly. Prefer warning traces.
|
||||||
extract_source = f: acc: value:
|
extract_source = f: acc: value:
|
||||||
# We take any "attributes" object that has a "sha256" field. Every value
|
|
||||||
# under "attributes" is assumed to be an object, and all the "attributes"
|
|
||||||
# with a "sha256" field are assumed to have either a "urls" or "url" field.
|
|
||||||
#
|
|
||||||
# We add them to the `acc`umulator:
|
|
||||||
#
|
|
||||||
# acc // {
|
|
||||||
# "ffad2b06ef2e09d040...fc8e33706bb01634" = fetchurl {
|
|
||||||
# name = "source";
|
|
||||||
# sha256 = "ffad2b06ef2e09d040...fc8e33706bb01634";
|
|
||||||
# urls = [
|
|
||||||
# "https://mirror.bazel.build/github.com/golang/library.zip",
|
|
||||||
# "https://github.com/golang/library.zip"
|
|
||||||
# ];
|
|
||||||
# };
|
|
||||||
# }
|
|
||||||
let
|
let
|
||||||
attrs = value.attributes;
|
attrs = value.attributes;
|
||||||
entry = hash: urls: name: {
|
entry = hash: urls: name: {
|
||||||
|
@ -65,22 +68,37 @@ let
|
||||||
passthru.urls = urls;
|
passthru.urls = urls;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
insert = acc: hash: urls: name:
|
insert = acc: hash: urls:
|
||||||
acc // entry (sanitize hash) (map sanitize urls) (sanitize name);
|
let
|
||||||
accWithRemotePatches = lib.foldlAttrs
|
validUrls = builtins.isList urls
|
||||||
(acc: url: hash: insert acc hash [ url ] attrs.name)
|
&& builtins.all (url: builtins.isString url && builtins.substring 0 4 url == "http") urls;
|
||||||
|
validName = builtins.isString attrs.name;
|
||||||
|
validHash = builtins.isString hash;
|
||||||
|
valid = validUrls && validName && validHash;
|
||||||
|
in
|
||||||
|
if valid then acc // entry hash urls attrs.name
|
||||||
|
else acc;
|
||||||
|
withToplevelValue = acc: insert acc
|
||||||
|
(attrs.integrity or attrs.sha256)
|
||||||
|
(attrs.urls or [ attrs.url ]);
|
||||||
|
# for http_file patches
|
||||||
|
withRemotePatches = acc: lib.foldlAttrs
|
||||||
|
(acc: url: hash: insert acc hash [ url ])
|
||||||
acc
|
acc
|
||||||
(attrs.remote_patches or { });
|
(attrs.remote_patches or { });
|
||||||
accWithNewSource = insert
|
# for _distdir_tar
|
||||||
accWithRemotePatches
|
withArchives = acc: lib.foldl'
|
||||||
(attrs.integrity or attrs.sha256)
|
(acc: archive: insert acc attrs.sha256.${archive} attrs.urls.${archive})
|
||||||
(attrs.urls or [ attrs.url ])
|
acc
|
||||||
attrs.name;
|
(attrs.archives or [ ]);
|
||||||
|
addSources = acc: withToplevelValue (withRemotePatches (withArchives acc));
|
||||||
in
|
in
|
||||||
if builtins.isAttrs value && value ? attributes
|
if builtins.isAttrs value && value ? attributes
|
||||||
|
&& builtins.isAttrs attrs && attrs ? name
|
||||||
&& (attrs ? sha256 || attrs ? integrity)
|
&& (attrs ? sha256 || attrs ? integrity)
|
||||||
|
&& (attrs ? urls || attrs ? url)
|
||||||
&& f attrs.name
|
&& f attrs.name
|
||||||
then accWithNewSource
|
then addSources acc
|
||||||
else acc;
|
else acc;
|
||||||
|
|
||||||
requiredSourcePredicate = n: requiredDepNamePredicate (sanitize n);
|
requiredSourcePredicate = n: requiredDepNamePredicate (sanitize n);
|
||||||
|
|
|
@ -579,6 +579,6 @@ stdenv.mkDerivation rec {
|
||||||
};
|
};
|
||||||
|
|
||||||
# For ease of debugging
|
# For ease of debugging
|
||||||
inherit distDir repoCache;
|
inherit distDir repoCache lockfile;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue