mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-22 06:53:01 +00:00
fetchzip, fetchgit: cleanup handling of optional features and whitespace
No intended functional difference, just trying to polish to make this easier to extend and more aligned with other nix conventions.
This commit is contained in:
parent
8396961c9c
commit
caff183402
@ -1,4 +1,4 @@
|
||||
{stdenvNoCC, git, cacert}: let
|
||||
{ stdenvNoCC, git, cacert }: let
|
||||
urlToName = url: rev: let
|
||||
inherit (stdenvNoCC.lib) removeSuffix splitString last;
|
||||
base = last (splitString ":" (baseNameOf (removeSuffix "/" url)));
|
||||
|
@ -1,6 +1,5 @@
|
||||
#! /usr/bin/env bash
|
||||
|
||||
set -e -o pipefail
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail
|
||||
|
||||
url=
|
||||
rev=
|
||||
@ -40,9 +39,9 @@ usage(){
|
||||
Options:
|
||||
--out path Path where the output would be stored.
|
||||
--url url Any url understood by 'git clone'.
|
||||
--rev ref Any sha1 or references (such as refs/heads/master)
|
||||
--rev ref Any sha1 or references (such as refs/heads/master).
|
||||
--hash h Expected hash.
|
||||
--branch-name Branch name to check out into
|
||||
--branch-name Branch name to check out into.
|
||||
--deepClone Clone the entire repository.
|
||||
--no-deepClone Make a shallow clone of just the required ref.
|
||||
--leave-dotGit Keep the .git directories.
|
||||
|
@ -5,24 +5,22 @@
|
||||
# (e.g. due to minor changes in the compression algorithm, or changes
|
||||
# in timestamps).
|
||||
|
||||
{ fetchurl, unzip }:
|
||||
{ lib, fetchurl, unzip }:
|
||||
|
||||
{ # Optionally move the contents of the unpacked tree up one level.
|
||||
stripRoot ? true
|
||||
{ name ? "source"
|
||||
, url
|
||||
# Optionally move the contents of the unpacked tree up one level.
|
||||
, stripRoot ? true
|
||||
, extraPostFetch ? ""
|
||||
, name ? "source"
|
||||
, ... } @ args:
|
||||
|
||||
(fetchurl ({
|
||||
inherit name;
|
||||
|
||||
recursiveHash = true;
|
||||
|
||||
downloadToTemp = true;
|
||||
|
||||
postFetch =
|
||||
''
|
||||
postFetch = ''
|
||||
unpackDir="$TMPDIR/unpack"
|
||||
mkdir "$unpackDir"
|
||||
cd "$unpackDir"
|
||||
@ -30,22 +28,23 @@
|
||||
renamed="$TMPDIR/${baseNameOf url}"
|
||||
mv "$downloadedFile" "$renamed"
|
||||
unpackFile "$renamed"
|
||||
result=$unpackDir
|
||||
''
|
||||
+ (if stripRoot then ''
|
||||
# Most src disted tarballs have a parent directory like foo-1.2.3/ to strip
|
||||
+ lib.optionalString stripRoot ''
|
||||
if [ $(ls "$unpackDir" | wc -l) != 1 ]; then
|
||||
echo "error: zip file must contain a single file or directory."
|
||||
echo "hint: Pass stripRoot=false; to fetchzip to assume flat list of files."
|
||||
exit 1
|
||||
fi
|
||||
fn=$(cd "$unpackDir" && echo *)
|
||||
if [ -f "$unpackDir/$fn" ]; then
|
||||
result="$unpackDir/$fn"
|
||||
'' + ''
|
||||
mkdir $out
|
||||
fi
|
||||
mv "$unpackDir/$fn" "$out"
|
||||
'' else ''
|
||||
mv "$unpackDir" "$out"
|
||||
'') #*/
|
||||
mv "$result" "$out"
|
||||
''
|
||||
+ extraPostFetch;
|
||||
|
||||
} // removeAttrs args [ "stripRoot" "extraPostFetch" ])).overrideAttrs (x: {
|
||||
# Hackety-hack: we actually need unzip hooks, too
|
||||
nativeBuildInputs = x.nativeBuildInputs ++ [ unzip ];
|
||||
|
Loading…
Reference in New Issue
Block a user