mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-29 10:23:29 +00:00
7e8b3adb04
Sometimes patches start without a leading prefix. We default to strip one prefix or path component from patches (-p1) in the patchPhase in stdenv. As all patches should therefore be in this format, fetchpatch should have an option to normalize patch paths. This commit introduces a new argument to fetchpatch called addPrefixes that adds one patch prefix to the old and new paths in a patch before putting it into the store.
28 lines
924 B
Nix
28 lines
924 B
Nix
# This function downloads and normalizes a patch/diff file.
|
|
# This is primarily useful for dynamically generated patches,
|
|
# such as GitHub's or cgit's, where the non-significant content parts
|
|
# often change with updating of git or cgit.
|
|
# stripLen acts as the -p parameter when applying a patch.
|
|
|
|
{ lib, fetchurl, patchutils }:
|
|
{ stripLen ? 0, addPrefixes ? false, ... }@args:
|
|
|
|
fetchurl ({
|
|
postFetch = ''
|
|
tmpfile="$TMPDIR/${args.sha256}"
|
|
"${patchutils}/bin/lsdiff" "$out" \
|
|
| sort -u | sed -e 's/[*?]/\\&/g' \
|
|
| xargs -I{} \
|
|
"${patchutils}/bin/filterdiff" \
|
|
--include={} \
|
|
--strip=${toString stripLen} \
|
|
${lib.optionalString addPrefixes ''
|
|
--addoldprefix=a/ \
|
|
--addnewprefix=b/ \
|
|
''} \
|
|
--clean "$out" > "$tmpfile"
|
|
mv "$tmpfile" "$out"
|
|
${args.postFetch or ""}
|
|
'';
|
|
} // builtins.removeAttrs args ["stripLen" "addPrefixes"])
|