at master 2.1 kB view raw
1{ 2 nixpkgsPath, 3 revision, 4 libsetsJSON, 5}: 6let 7 lib = import (nixpkgsPath + "/lib"); 8 libsets = builtins.fromJSON libsetsJSON; 9 10 libDefPos = 11 prefix: set: 12 builtins.concatMap ( 13 name: 14 [ 15 { 16 name = builtins.concatStringsSep "." (prefix ++ [ name ]); 17 location = builtins.unsafeGetAttrPos name set; 18 } 19 ] 20 ++ lib.optionals (builtins.length prefix == 0 && builtins.isAttrs set.${name}) ( 21 libDefPos (prefix ++ [ name ]) set.${name} 22 ) 23 ) (builtins.attrNames set); 24 25 libset = 26 toplib: 27 map (subsetname: { 28 subsetname = subsetname; 29 functions = libDefPos [ ] toplib.${subsetname}; 30 }) (map (x: x.name) libsets); 31 32 flattenedLibSubset = 33 { subsetname, functions }: 34 map (fn: { 35 name = "lib.${subsetname}.${fn.name}"; 36 value = fn.location; 37 }) functions; 38 39 locatedlibsets = libs: map flattenedLibSubset (libset libs); 40 removeFilenamePrefix = 41 prefix: filename: 42 let 43 prefixLen = (builtins.stringLength prefix) + 1; # +1 to remove the leading / 44 filenameLen = builtins.stringLength filename; 45 substr = builtins.substring prefixLen filenameLen filename; 46 in 47 substr; 48 49 removeNixpkgs = removeFilenamePrefix (toString nixpkgsPath); 50 51 liblocations = builtins.filter (elem: elem.value != null) (lib.lists.flatten (locatedlibsets lib)); 52 53 fnLocationRelative = 54 { name, value }: 55 { 56 inherit name; 57 value = value // { 58 file = removeNixpkgs value.file; 59 }; 60 }; 61 62 relativeLocs = (map fnLocationRelative liblocations); 63 sanitizeId = builtins.replaceStrings [ "'" ] [ "-prime" ]; 64 65 urlPrefix = "https://github.com/NixOS/nixpkgs/blob/${revision}"; 66 jsonLocs = builtins.listToAttrs ( 67 map ( 68 { name, value }: 69 { 70 name = sanitizeId name; 71 value = 72 let 73 text = "${value.file}:${toString value.line}"; 74 target = "${urlPrefix}/${value.file}#L${toString value.line}"; 75 in 76 "[${text}](${target}) in `<nixpkgs>`"; 77 } 78 ) relativeLocs 79 ); 80 81in 82jsonLocs