From aa6adfc324b44c840a488a4b0a5cd4c1c66f80c7 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 4 Jun 2018 22:29:22 -0400 Subject: [PATCH 1/4] fetchpatch: Add includes to compliment excludes, and require that both not be non-empty. This commit was originally introduced as part of #41420 and then reverted with the rest of that PR. However there was no reason to revert his particular commit. --- pkgs/build-support/fetchpatch/default.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/fetchpatch/default.nix b/pkgs/build-support/fetchpatch/default.nix index c185497e6913..16343d626ce7 100644 --- a/pkgs/build-support/fetchpatch/default.nix +++ b/pkgs/build-support/fetchpatch/default.nix @@ -5,7 +5,7 @@ # stripLen acts as the -p parameter when applying a patch. { lib, fetchurl, patchutils }: -{ stripLen ? 0, extraPrefix ? null, excludes ? [], ... }@args: +{ stripLen ? 0, extraPrefix ? null, excludes ? [], includes ? [], ... }@args: fetchurl ({ postFetch = '' @@ -24,7 +24,9 @@ fetchurl ({ ${patchutils}/bin/filterdiff \ -p1 \ ${builtins.toString (builtins.map (x: "-x ${x}") excludes)} \ + ${builtins.toString (builtins.map (x: "-i ${x}") includes)} \ "$tmpfile" > "$out" ${args.postFetch or ""} ''; -} // builtins.removeAttrs args ["stripLen" "extraPrefix" "excludes" "postFetch"]) + meta.broken = excludes != [] && includes != []; +} // builtins.removeAttrs args ["stripLen" "extraPrefix" "excludes" "includes" "postFetch"]) From 1ddab0efb1729a32fdea83cf757584a7ebf1e13a Mon Sep 17 00:00:00 2001 From: Timo Kaufmann Date: Sun, 15 Jul 2018 09:58:47 +0200 Subject: [PATCH 2/4] fetchpatch: escape excludes and includes Excludes and includes are implemented by passing the parameters to the respective flags of `filterdiff`. Those were passed unescaped until now. Since those flags expect patterns (similar to shell globs), something like `/some/path/*` might be used to exclude or include all files in some path. Without escaping the shell would expand the `*`, leading to unexpected behaviour. --- pkgs/build-support/fetchpatch/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/fetchpatch/default.nix b/pkgs/build-support/fetchpatch/default.nix index 16343d626ce7..c8004fb8743c 100644 --- a/pkgs/build-support/fetchpatch/default.nix +++ b/pkgs/build-support/fetchpatch/default.nix @@ -23,8 +23,8 @@ fetchurl ({ --clean "$out" > "$tmpfile" ${patchutils}/bin/filterdiff \ -p1 \ - ${builtins.toString (builtins.map (x: "-x ${x}") excludes)} \ - ${builtins.toString (builtins.map (x: "-i ${x}") includes)} \ + ${builtins.toString (builtins.map (x: "-x ${lib.escapeShellArg x}") excludes)} \ + ${builtins.toString (builtins.map (x: "-i ${lib.escapeShellArg x}") includes)} \ "$tmpfile" > "$out" ${args.postFetch or ""} ''; From 8f9b985e60de16883b2e67eaf2924144d647f31e Mon Sep 17 00:00:00 2001 From: Timo Kaufmann Date: Sun, 15 Jul 2018 13:57:37 +0200 Subject: [PATCH 3/4] fetchpatch: fail on empty patch Since this is probably never the desired case and has led to actual issues, see the comments at: https://github.com/NixOS/nixpkgs/commit/af1313e91552e42a4419b396b3026319c60fc17f This might also happen when pulling a patch from GitHub or a similar web interface without explicitly selecting the "raw" format. --- pkgs/build-support/fetchpatch/default.nix | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pkgs/build-support/fetchpatch/default.nix b/pkgs/build-support/fetchpatch/default.nix index c8004fb8743c..1e231d649b3e 100644 --- a/pkgs/build-support/fetchpatch/default.nix +++ b/pkgs/build-support/fetchpatch/default.nix @@ -10,6 +10,10 @@ fetchurl ({ postFetch = '' tmpfile="$TMPDIR/${args.sha256}" + if [ ! -s "$out" ]; then + echo "error: Fetched patch file '$out' is empty!" 1>&2 + exit 1 + fi "${patchutils}/bin/lsdiff" "$out" \ | sort -u | sed -e 's/[*?]/\\&/g' \ | xargs -I{} \ @@ -21,12 +25,26 @@ fetchurl ({ --addnewprefix=b/${extraPrefix} \ ''} \ --clean "$out" > "$tmpfile" + if [ ! -s "$tmpfile" ]; then + echo "error: Normalized patch '$tmpfile' is empty (while the fetched file was not)!" 1>&2 + echo "Did you maybe fetch a HTML representation of a patch instead of a raw patch?" 1>&2 + echo "Fetched file was:" 1>&2 + cat "$out" 1>&2 + exit 1 + fi ${patchutils}/bin/filterdiff \ -p1 \ ${builtins.toString (builtins.map (x: "-x ${lib.escapeShellArg x}") excludes)} \ ${builtins.toString (builtins.map (x: "-i ${lib.escapeShellArg x}") includes)} \ "$tmpfile" > "$out" ${args.postFetch or ""} + if [ ! -s "$out" ]; then + echo "error: Filtered patch '$out$' is empty (while the original patch file was not)!" 1>&2 + echo "Check your includes and excludes." 1>&2 + echo "Normalizd patch file was:" 1>&2 + cat "$tmpfile" 1>&2 + exit 1 + fi ''; meta.broken = excludes != [] && includes != []; } // builtins.removeAttrs args ["stripLen" "extraPrefix" "excludes" "includes" "postFetch"]) From 30585139410578e9cbf3091a3f930dcd22de1ebc Mon Sep 17 00:00:00 2001 From: Timo Kaufmann Date: Mon, 16 Jul 2018 22:45:07 +0200 Subject: [PATCH 4/4] fetchpatch: add option to revert a patch --- .../math/sage/patches/revert-269c1e1551285.patch | 14 -------------- pkgs/applications/science/math/sage/sage-src.nix | 7 ++++++- pkgs/build-support/fetchpatch/default.nix | 11 +++++++---- 3 files changed, 13 insertions(+), 19 deletions(-) delete mode 100644 pkgs/applications/science/math/sage/patches/revert-269c1e1551285.patch diff --git a/pkgs/applications/science/math/sage/patches/revert-269c1e1551285.patch b/pkgs/applications/science/math/sage/patches/revert-269c1e1551285.patch deleted file mode 100644 index b57e48b86dec..000000000000 --- a/pkgs/applications/science/math/sage/patches/revert-269c1e1551285.patch +++ /dev/null @@ -1,14 +0,0 @@ -reverted: ---- b/src/sage/geometry/polyhedron/backend_cdd.py -+++ a/src/sage/geometry/polyhedron/backend_cdd.py -@@ -154,7 +154,9 @@ - ... [0.62, -1.38, 0.38],[0.144, -1.04, 0.04], - ... [0.1309090909, -1.0290909091, 0.04]] - sage: Polyhedron(point_list) -+ Traceback (most recent call last): -+ ... -+ ValueError: *Error: Numerical inconsistency is found. Use the GMP exact arithmetic. -- A 3-dimensional polyhedron in RDF^3 defined as the convex hull of 14 vertices - sage: Polyhedron(point_list, base_ring=QQ) - A 3-dimensional polyhedron in QQ^3 defined as the convex hull of 14 vertices - """ diff --git a/pkgs/applications/science/math/sage/sage-src.nix b/pkgs/applications/science/math/sage/sage-src.nix index 348adf5d5095..a785c310bd3e 100644 --- a/pkgs/applications/science/math/sage/sage-src.nix +++ b/pkgs/applications/science/math/sage/sage-src.nix @@ -156,7 +156,12 @@ stdenv.mkDerivation rec { sha256 = "0fmw7pzbaxs2dshky6iw9pr8i23p9ih2y2lw661qypdrxh5xw03k"; stripLen = 1; }) - ./patches/revert-269c1e1551285.patch + (fetchpatch { + name = "revert-cddlib-doctest-changes.patch"; + url = "https://git.sagemath.org/sage.git/patch/?id=269c1e1551285566b8ba7a2b890989e5590e9f11"; + sha256 = "12bcjhq7hm2pmmj2bgjvcffjyls2x7q61ivlnaj5v5bsvhc183iy"; + revert = true; + }) # Only formatting changes. diff --git a/pkgs/build-support/fetchpatch/default.nix b/pkgs/build-support/fetchpatch/default.nix index 1e231d649b3e..40a7675b7ac5 100644 --- a/pkgs/build-support/fetchpatch/default.nix +++ b/pkgs/build-support/fetchpatch/default.nix @@ -5,7 +5,7 @@ # stripLen acts as the -p parameter when applying a patch. { lib, fetchurl, patchutils }: -{ stripLen ? 0, extraPrefix ? null, excludes ? [], includes ? [], ... }@args: +{ stripLen ? 0, extraPrefix ? null, excludes ? [], includes ? [], revert ? false, ... }@args: fetchurl ({ postFetch = '' @@ -37,7 +37,7 @@ fetchurl ({ ${builtins.toString (builtins.map (x: "-x ${lib.escapeShellArg x}") excludes)} \ ${builtins.toString (builtins.map (x: "-i ${lib.escapeShellArg x}") includes)} \ "$tmpfile" > "$out" - ${args.postFetch or ""} + if [ ! -s "$out" ]; then echo "error: Filtered patch '$out$' is empty (while the original patch file was not)!" 1>&2 echo "Check your includes and excludes." 1>&2 @@ -45,6 +45,9 @@ fetchurl ({ cat "$tmpfile" 1>&2 exit 1 fi - ''; + '' + lib.optionalString revert '' + ${patchutils}/bin/interdiff "$out" /dev/null > "$tmpfile" + mv "$tmpfile" "$out" + '' + (args.postFetch or ""); meta.broken = excludes != [] && includes != []; -} // builtins.removeAttrs args ["stripLen" "extraPrefix" "excludes" "includes" "postFetch"]) +} // builtins.removeAttrs args ["stripLen" "extraPrefix" "excludes" "includes" "revert" "postFetch"])