bazel_7: improve lockfile parsing

+45 -27
+44 -26
pkgs/development/tools/build-managers/bazel/bazel_7/bazel-repository-cache.nix
··· 36 36 then builtins.substring 2 (-1) str 37 37 else str; 38 38 39 + # We take any "attributes" object that has a "sha256" field. Every value 40 + # under "attributes" is assumed to be an object, and all the "attributes" 41 + # with a "sha256" field are assumed to have either a "urls" or "url" field. 42 + # 43 + # We add them to the `acc`umulator: 44 + # 45 + # acc // { 46 + # "ffad2b06ef2e09d040...fc8e33706bb01634" = fetchurl { 47 + # name = "source"; 48 + # sha256 = "ffad2b06ef2e09d040...fc8e33706bb01634"; 49 + # urls = [ 50 + # "https://mirror.bazel.build/github.com/golang/library.zip", 51 + # "https://github.com/golang/library.zip" 52 + # ]; 53 + # }; 54 + # } 55 + # 56 + # !REMINDER! This works on a best-effort basis, so try to keep it from 57 + # failing loudly. Prefer warning traces. 39 58 extract_source = f: acc: value: 40 - # We take any "attributes" object that has a "sha256" field. Every value 41 - # under "attributes" is assumed to be an object, and all the "attributes" 42 - # with a "sha256" field are assumed to have either a "urls" or "url" field. 43 - # 44 - # We add them to the `acc`umulator: 45 - # 46 - # acc // { 47 - # "ffad2b06ef2e09d040...fc8e33706bb01634" = fetchurl { 48 - # name = "source"; 49 - # sha256 = "ffad2b06ef2e09d040...fc8e33706bb01634"; 50 - # urls = [ 51 - # "https://mirror.bazel.build/github.com/golang/library.zip", 52 - # "https://github.com/golang/library.zip" 53 - # ]; 54 - # }; 55 - # } 56 59 let 57 60 attrs = value.attributes; 58 61 entry = hash: urls: name: { ··· 65 68 passthru.urls = urls; 66 69 }; 67 70 }; 68 - insert = acc: hash: urls: name: 69 - acc // entry (sanitize hash) (map sanitize urls) (sanitize name); 70 - accWithRemotePatches = lib.foldlAttrs 71 - (acc: url: hash: insert acc hash [ url ] attrs.name) 71 + insert = acc: hash: urls: 72 + let 73 + validUrls = builtins.isList urls 74 + && builtins.all (url: builtins.isString url && builtins.substring 0 4 url == "http") urls; 75 + validName = builtins.isString attrs.name; 76 + validHash = builtins.isString hash; 77 + valid = validUrls && validName && validHash; 78 + in 79 + if valid then acc // entry hash urls attrs.name 80 + else acc; 81 + withToplevelValue = acc: insert acc 82 + (attrs.integrity or attrs.sha256) 83 + (attrs.urls or [ attrs.url ]); 84 + # for http_file patches 85 + withRemotePatches = acc: lib.foldlAttrs 86 + (acc: url: hash: insert acc hash [ url ]) 72 87 acc 73 88 (attrs.remote_patches or { }); 74 - accWithNewSource = insert 75 - accWithRemotePatches 76 - (attrs.integrity or attrs.sha256) 77 - (attrs.urls or [ attrs.url ]) 78 - attrs.name; 89 + # for _distdir_tar 90 + withArchives = acc: lib.foldl' 91 + (acc: archive: insert acc attrs.sha256.${archive} attrs.urls.${archive}) 92 + acc 93 + (attrs.archives or [ ]); 94 + addSources = acc: withToplevelValue (withRemotePatches (withArchives acc)); 79 95 in 80 96 if builtins.isAttrs value && value ? attributes 97 + && builtins.isAttrs attrs && attrs ? name 81 98 && (attrs ? sha256 || attrs ? integrity) 99 + && (attrs ? urls || attrs ? url) 82 100 && f attrs.name 83 - then accWithNewSource 101 + then addSources acc 84 102 else acc; 85 103 86 104 requiredSourcePredicate = n: requiredDepNamePredicate (sanitize n);
+1 -1
pkgs/development/tools/build-managers/bazel/bazel_7/default.nix
··· 579 579 }; 580 580 581 581 # For ease of debugging 582 - inherit distDir repoCache; 582 + inherit distDir repoCache lockfile; 583 583 }; 584 584 }