From 77f6edfd59929ea35c08920ca19dd7bdc0d810a8 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Mon, 12 Aug 2024 20:50:07 -0700 Subject: [PATCH] llvmPackages: refactor patch matching --- .../compilers/llvm/common/default.nix | 316 +++++++++++++----- 1 file changed, 225 insertions(+), 91 deletions(-) diff --git a/pkgs/development/compilers/llvm/common/default.nix b/pkgs/development/compilers/llvm/common/default.nix index 6ae37502d47b..6b393cbbf556 100644 --- a/pkgs/development/compilers/llvm/common/default.nix +++ b/pkgs/development/compilers/llvm/common/default.nix @@ -75,97 +75,231 @@ let builtins.path { name = builtins.baseNameOf p; path = - if - (lib.versionOlder release_version "14" || lib.versionAtLeast release_version "19") - && p == "clang/gnu-install-dirs.patch" - then - (if lib.versionAtLeast release_version "19" then ../19/${p} else ../12/${p}) - else if - lib.versionAtLeast release_version "18" - && ( - p == "clang/purity.patch" - || p == "lld/gnu-install-dirs.patch" - || p == "llvm/gnu-install-dirs.patch" - || p == "llvm/gnu-install-dirs-polly.patch" - || p == "llvm/lit-shell-script-runner-set-dyld-library-path.patch" - || p == "libcxx/0001-darwin-10.12-mbstate_t-fix.patch" - ) - then - ../18/${p} - else if - lib.versionAtLeast release_version "15" - && lib.versionOlder release_version "17" - && ( - p == "clang/purity.patch" - || p == "libunwind/gnu-install-dirs.patch" - || p == "llvm/llvm-lit-cfg-add-libs-to-dylib-path.patch" - ) - then - ../15/${p} - else if p == "compiler-rt/X86-support-extension.patch" || p == "lldb/procfs.patch" then - (if lib.versionAtLeast release_version "15" then ../15/${p} else ../12/${p}) - else if - lib.versionAtLeast release_version "13" - && lib.versionOlder release_version "15" - && p == "compiler-rt/armv7l.patch" - then - ../13/${p} - else if p == "compiler-rt/gnu-install-dirs.patch" && lib.versionAtLeast release_version "15" then - (if lib.versionAtLeast release_version "15" then ../15/${p} else ../12/${p}) - else if - ( - p == "compiler-rt/darwin-targetconditionals.patch" - || p == "compiler-rt/codesign.patch" - || p == "lldb/cpu_subtype_arm64e_replacement.patch" - ) - && lib.versionAtLeast release_version "13" - then - ../13/${p} - else if - lib.versionAtLeast release_version "16" - && ( - p == "lld/add-table-base.patch" - || p == "compiler-rt/normalize-var.patch" - || p == "openmp/run-lit-directly.patch" - ) - then - ../16/${p} - else if - lib.versionOlder release_version "16" - && ( - p == "compiler-rt/normalize-var.patch" - || p == "lldb/resource-dir.patch" - || p == "clang/purity.patch" - ) - then - ../12/${p} - else if lib.versionOlder release_version "14" && p == "lld/gnu-install-dirs.patch" then - ../12/${p} - else if - lib.versionAtLeast release_version "14" - && ( - (lib.versionOlder release_version "18" && p == "llvm/gnu-install-dirs-polly.patch") - || (lib.versionOlder release_version "16" && p == "openmp/run-lit-directly.patch") - ) - then - ../14/${p} - else if - lib.versionAtLeast release_version "16" - && lib.versionOlder release_version "18" - && p == "llvm/lit-shell-script-runner-set-dyld-library-path.patch" - then - ../16/${p} - else if - lib.versionAtLeast release_version "17" - && (p == "llvm/llvm-lit-cfg-add-libs-to-dylib-path.patch" || p == "openmp/fix-find-tool.patch") - then - ../17/${p} - else if - lib.versionAtLeast release_version "15" && p == "llvm/polly-lit-cfg-add-libs-to-dylib-path.patch" - then - ../15/${p} - else - "${metadata.versionDir}/${p}"; + let + patches = { + "clang/gnu-install-dirs.patch" = [ + { + before = "14"; + path = ../12; + } + { + after = "19"; + path = ../19; + } + ]; + "clang/purity.patch" = [ + { + after = "18"; + path = ../18; + } + { + before = "17"; + after = "15"; + path = ../15; + } + { + before = "16"; + path = ../12; + } + ]; + "lld/add-table-base.patch" = [ + { + after = "16"; + path = ../16; + } + ]; + "lld/gnu-install-dirs.patch" = [ + { + after = "18"; + path = ../18; + } + { + before = "14"; + path = ../12; + } + ]; + "llvm/gnu-install-dirs.patch" = [ + { + after = "18"; + path = ../18; + } + ]; + "llvm/gnu-install-dirs-polly.patch" = [ + { + after = "18"; + path = ../18; + } + { + before = "18"; + after = "14"; + path = ../14; + } + ]; + "llvm/llvm-lit-cfg-add-libs-to-dylib-path.patch" = [ + { + before = "17"; + after = "15"; + path = ../15; + } + { + after = "17"; + path = ../17; + } + ]; + "llvm/lit-shell-script-runner-set-dyld-library-path.patch" = [ + { + after = "18"; + path = ../18; + } + { + after = "16"; + before = "18"; + path = ../16; + } + ]; + "llvm/polly-lit-cfg-add-libs-to-dylib-path.patch" = [ + { + after = "15"; + path = ../15; + } + ]; + "libcxx/0001-darwin-10.12-mbstate_t-fix.patch" = [ + { + after = "18"; + path = ../18; + } + ]; + "libunwind/gnu-install-dirs.patch" = [ + { + before = "17"; + after = "15"; + path = ../15; + } + ]; + "compiler-rt/X86-support-extension.patch" = [ + { + after = "15"; + path = ../15; + } + { + before = "15"; + path = ../12; + } + ]; + "compiler-rt/armv7l.patch" = [ + { + before = "15"; + after = "13"; + path = ../13; + } + ]; + "compiler-rt/gnu-install-dirs.patch" = [ + { + before = "14"; + path = ../12; + } + { + after = "13"; + before = "15"; + path = ../14; + } + { + after = "15"; + before = "17"; + path = ../15; + } + { + after = "16"; + path = ../17; + } + ]; + "compiler-rt/darwin-targetconditionals.patch" = [ + { + after = "13"; + path = ../13; + } + ]; + "compiler-rt/codesign.patch" = [ + { + after = "13"; + path = ../13; + } + ]; + "compiler-rt/normalize-var.patch" = [ + { + after = "16"; + path = ../16; + } + { + before = "16"; + path = ../12; + } + ]; + "lldb/procfs.patch" = [ + { + after = "15"; + path = ../15; + } + { + before = "15"; + path = ../12; + } + ]; + "lldb/cpu_subtype_arm64e_replacement.patch" = [ + { + after = "13"; + path = ../13; + } + ]; + "lldb/resource-dir.patch" = [ + { + before = "16"; + path = ../12; + } + ]; + "openmp/fix-find-tool.patch" = [ + { + after = "17"; + path = ../17; + } + ]; + "openmp/run-lit-directly.patch" = [ + { + after = "16"; + path = ../16; + } + { + after = "14"; + before = "16"; + path = ../14; + } + ]; + }; + + constraints = patches."${p}" or null; + matchConstraint = + { + before ? null, + after ? null, + path, + }: + let + check = fn: value: if value == null then true else fn release_version value; + matchBefore = check lib.versionOlder before; + matchAfter = check lib.versionAtLeast after; + in + matchBefore && matchAfter; + + patchDir = + toString + ( + if constraints == null then + { path = metadata.versionDir; } + else + (lib.findFirst matchConstraint { path = metadata.versionDir; } constraints) + ).path; + in + "${patchDir}/${p}"; }; };