about summary refs log tree commit diff
path: root/pkgs/development/tools/clang-tools
diff options
context:
space:
mode:
authorPatryk Wychowaniec <pwychowaniec@pm.me>2022-06-04 16:29:16 +0200
committerBjørn Forsman <bjorn.forsman@gmail.com>2022-06-11 16:48:16 +0200
commit247763256c6ed9a637b0fa665f83e673dc8dba38 (patch)
treec0a5947e62497c13baec1002fe3eb56b0ff074f1 /pkgs/development/tools/clang-tools
parent6036dcbdb930177396012bbe39d8e31201289a14 (diff)
clang-tools: don't hardcode list of tools
Currently clang-tools' derivation uses a hardcoded list of names to
distinguish between what's a compiler-like binary and what's a tool-like
binary (so that e.g. clang-tidy is included in the derivation, but
clang-13 - not).

Because Clang's tools follow a common naming convention
(clang-somethingsomething), I think it's easier if we just used a simple
regular expression in place of the hardcoded list.
Diffstat (limited to 'pkgs/development/tools/clang-tools')
-rw-r--r--pkgs/development/tools/clang-tools/default.nix37
1 files changed, 25 insertions, 12 deletions
diff --git a/pkgs/development/tools/clang-tools/default.nix b/pkgs/development/tools/clang-tools/default.nix
index bfc00fb6e3d35..b259b683dde7b 100644
--- a/pkgs/development/tools/clang-tools/default.nix
+++ b/pkgs/development/tools/clang-tools/default.nix
@@ -4,31 +4,44 @@ let
   unwrapped = llvmPackages.clang-unwrapped;
 
 in stdenv.mkDerivation {
+  inherit unwrapped;
+
   pname = "clang-tools";
   version = lib.getVersion unwrapped;
-
   dontUnpack = true;
-
   clang = llvmPackages.clang;
-  inherit unwrapped;
 
   installPhase = ''
     runHook preInstall
 
     mkdir -p $out/bin
 
-    substituteAll ${./wrapper} $out/bin/clangd
-    chmod +x $out/bin/clangd
-    for tool in \
-      clang-apply-replacements \
-      clang-check \
-      clang-format \
-      clang-rename \
-      clang-tidy
-    do
+    for tool in $unwrapped/bin/clang-*; do
+      tool=$(basename "$tool")
+
+      # Compilers have their own derivation, no need to include them here:
+      if [[ $tool == "clang-cl" || $tool == "clang-cpp" ]]; then
+        continue
+      fi
+
+      # Clang's derivation produces a lot of binaries, but the tools we are
+      # interested in follow the `clang-something` naming convention - except
+      # for clang-$version (e.g. clang-13), which is the compiler again:
+      if [[ ! $tool =~ ^clang\-[a-zA-Z_\-]+$ ]]; then
+        continue
+      fi
+
       ln -s $out/bin/clangd $out/bin/$tool
     done
 
+    if [[ -z "$(ls -A $out/bin)" ]]; then
+      echo "Found no binaries - maybe their location or naming convention changed?"
+      exit 1
+    fi
+
+    substituteAll ${./wrapper} $out/bin/clangd
+    chmod +x $out/bin/clangd
+
     runHook postInstall
   '';