Merge pull request #247527 from oxij/metrics/fetchzip

fetchzip: cleanup and improve metrics

authored by

Adam Joseph and committed by
GitHub
be547cb3 6c15f71a

+29 -40
+8 -6
pkgs/build-support/fetchurl/default.nix
··· 132 else throw "fetchurl requires a hash for fixed-output derivation: ${lib.concatStringsSep ", " urls_}"; 133 in 134 135 stdenvNoCC.mkDerivation (( 136 if (pname != "" && version != "") then 137 { inherit pname version; } ··· 161 162 outputHashMode = if (recursiveHash || executable) then "recursive" else "flat"; 163 164 - curlOpts = lib.warnIf (lib.isList curlOpts) '' 165 - fetchurl for ${toString (builtins.head urls_)}: curlOpts is a list (${lib.generators.toPretty { multiline = false; } curlOpts}), which is not supported anymore. 166 - - If you wish to get the same effect as before, for elements with spaces (even if escaped) to expand to multiple curl arguments, use a string argument instead: 167 - curlOpts = ${lib.strings.escapeNixString (toString curlOpts)}; 168 - - If you wish for each list element to be passed as a separate curl argument, allowing arguments to contain spaces, use curlOptsList instead: 169 - curlOptsList = [ ${lib.concatMapStringsSep " " lib.strings.escapeNixString curlOpts} ];'' curlOpts; 170 curlOptsList = lib.escapeShellArgs curlOptsList; 171 inherit showURLs mirrorsFile postFetch downloadToTemp executable; 172
··· 132 else throw "fetchurl requires a hash for fixed-output derivation: ${lib.concatStringsSep ", " urls_}"; 133 in 134 135 + assert (lib.isList curlOpts) -> lib.warn '' 136 + fetchurl for ${toString (builtins.head urls_)}: curlOpts is a list (${lib.generators.toPretty { multiline = false; } curlOpts}), which is not supported anymore. 137 + - If you wish to get the same effect as before, for elements with spaces (even if escaped) to expand to multiple curl arguments, use a string argument instead: 138 + curlOpts = ${lib.strings.escapeNixString (toString curlOpts)}; 139 + - If you wish for each list element to be passed as a separate curl argument, allowing arguments to contain spaces, use curlOptsList instead: 140 + curlOptsList = [ ${lib.concatMapStringsSep " " lib.strings.escapeNixString curlOpts} ];'' true; 141 + 142 stdenvNoCC.mkDerivation (( 143 if (pname != "" && version != "") then 144 { inherit pname version; } ··· 168 169 outputHashMode = if (recursiveHash || executable) then "recursive" else "flat"; 170 171 + inherit curlOpts; 172 curlOptsList = lib.escapeShellArgs curlOptsList; 173 inherit showURLs mirrorsFile postFetch downloadToTemp executable; 174
+21 -34
pkgs/build-support/fetchzip/default.nix
··· 7 8 { lib, fetchurl, unzip, glibcLocalesUtf8 }: 9 10 - { # Optionally move the contents of the unpacked tree up one level. 11 - stripRoot ? true 12 , url ? "" 13 , urls ? [] 14 - , extraPostFetch ? "" 15 , postFetch ? "" 16 - , name ? "source" 17 - , pname ? "" 18 - , version ? "" 19 - , nativeBuildInputs ? [ ] 20 - , # Allows to set the extension for the intermediate downloaded 21 - # file. This can be used as a hint for the unpackCmdHooks to select 22 - # an appropriate unpacking tool. 23 - extension ? null 24 - , ... } @ args: 25 26 27 - lib.warnIf (extraPostFetch != "") "use 'postFetch' instead of 'extraPostFetch' with 'fetchzip' and 'fetchFromGitHub'." 28 29 - (let 30 tmpFilename = 31 if extension != null 32 then "download.${extension}" 33 else baseNameOf (if url != "" then url else builtins.head urls); 34 in 35 36 - fetchurl (( 37 - if (pname != "" && version != "") then 38 - { 39 - name = "${pname}-${version}"; 40 - inherit pname version; 41 - } 42 - else 43 - { inherit name; } 44 - ) // { 45 recursiveHash = true; 46 47 downloadToTemp = true; ··· 61 mv "$downloadedFile" "$renamed" 62 unpackFile "$renamed" 63 chmod -R +w "$unpackDir" 64 - '' 65 - + (if stripRoot then '' 66 if [ $(ls -A "$unpackDir" | wc -l) != 1 ]; then 67 echo "error: zip file must contain a single file or directory." 68 echo "hint: Pass stripRoot=false; to fetchzip to assume flat list of files." ··· 75 mv "$unpackDir/$fn" "$out" 76 '' else '' 77 mv "$unpackDir" "$out" 78 - '') 79 - + '' 80 ${postFetch} 81 - '' + '' 82 ${extraPostFetch} 83 - '' 84 - 85 - # Remove non-owner write permissions 86 - # Fixes https://github.com/NixOS/nixpkgs/issues/38649 87 - + '' 88 chmod 755 "$out" 89 ''; 90 - } // removeAttrs args [ "stripRoot" "extraPostFetch" "postFetch" "extension" "nativeBuildInputs" ]))
··· 7 8 { lib, fetchurl, unzip, glibcLocalesUtf8 }: 9 10 + { name ? "source" 11 , url ? "" 12 , urls ? [] 13 + , nativeBuildInputs ? [] 14 , postFetch ? "" 15 + , extraPostFetch ? "" 16 17 + # Optionally move the contents of the unpacked tree up one level. 18 + , stripRoot ? true 19 + # Allows to set the extension for the intermediate downloaded 20 + # file. This can be used as a hint for the unpackCmdHooks to select 21 + # an appropriate unpacking tool. 22 + , extension ? null 23 24 + # the rest are given to fetchurl as is 25 + , ... } @ args: 26 + 27 + assert (extraPostFetch != "") -> lib.warn "use 'postFetch' instead of 'extraPostFetch' with 'fetchzip' and 'fetchFromGitHub'." true; 28 29 + let 30 tmpFilename = 31 if extension != null 32 then "download.${extension}" 33 else baseNameOf (if url != "" then url else builtins.head urls); 34 in 35 36 + fetchurl ({ 37 + inherit name; 38 recursiveHash = true; 39 40 downloadToTemp = true; ··· 54 mv "$downloadedFile" "$renamed" 55 unpackFile "$renamed" 56 chmod -R +w "$unpackDir" 57 + '' + (if stripRoot then '' 58 if [ $(ls -A "$unpackDir" | wc -l) != 1 ]; then 59 echo "error: zip file must contain a single file or directory." 60 echo "hint: Pass stripRoot=false; to fetchzip to assume flat list of files." ··· 67 mv "$unpackDir/$fn" "$out" 68 '' else '' 69 mv "$unpackDir" "$out" 70 + '') + '' 71 ${postFetch} 72 ${extraPostFetch} 73 chmod 755 "$out" 74 ''; 75 + # ^ Remove non-owner write permissions 76 + # Fixes https://github.com/NixOS/nixpkgs/issues/38649 77 + } // removeAttrs args [ "stripRoot" "extraPostFetch" "postFetch" "extension" "nativeBuildInputs" ])