From 395fe681274f2b09b4f337c61760c1eda2771f66 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Thu, 20 Nov 2025 22:45:27 +0100 Subject: [PATCH] tests/clang-tidy: Run on all supported platforms Fixes #1013 Change-Id: I7388e4eb4728c34f2e21756438020e28b4f1cfca --- flake.nix | 16 +++++++++++----- lix/libexpr/attr-set.hh | 2 ++ lix/libexpr/nixexpr.cc | 2 ++ lix/libmain/shared.cc | 2 ++ lix/libstore/gc.cc | 1 + misc/rapidcheck-gen-hpp.patch | 13 +++++++++++++ package.nix | 8 ++++++-- 7 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 misc/rapidcheck-gen-hpp.patch diff --git a/flake.nix b/flake.nix index 9ea5dee76..01d2fd96c 100644 --- a/flake.nix +++ b/flake.nix @@ -222,7 +222,10 @@ busybox-sandbox-shell = final.busybox-sandbox-shell or final.default-busybox-sandbox-shell; }; - lix-clang-tidy = final.callPackage ./subprojects/lix-clang-tidy { }; + lix-clang-tidy = final.callPackage ./subprojects/lix-clang-tidy { + # FIXME: To be removed when switching to nixos-25.11-small + llvmPackages = final.llvmPackages_20; + }; nix-eval-jobs = final.callPackage ./subprojects/nix-eval-jobs { srcDir = ./subprojects/nix-eval-jobs; @@ -427,17 +430,20 @@ ''; # clang-tidy run against the Lix codebase using the Lix clang-tidy plugin - clang-tidy = + clang-tidy = forAllSystems ( + system: let - nixpkgs = nixpkgsFor.x86_64-linux.native; - inherit (nixpkgs) pkgs; + pkgs = nixpkgsFor.${system}.native; in pkgs.callPackage ./package.nix { # Required since we don't support gcc stdenv stdenv = pkgs.clangStdenv; + # FIXME: To be removed when switching to nixos-25.11-small + llvmPackages = pkgs.llvmPackages_20; versionSuffix = ""; lintInsteadOfBuild = true; - }; + } + ); # Make sure that nix-env still produces the exact same result # on a particular version of Nixpkgs. diff --git a/lix/libexpr/attr-set.hh b/lix/libexpr/attr-set.hh index 7fb4ac6e9..db128aae9 100644 --- a/lix/libexpr/attr-set.hh +++ b/lix/libexpr/attr-set.hh @@ -97,6 +97,8 @@ public: res.reserve(size_); for (Size n = 0; n < size_; n++) res.emplace_back(&attrs[n]); + // NOTE: this sort uses a total order, so the iteration over pointers is not an issue + // NOLINTNEXTLINE(bugprone-nondeterministic-pointer-iteration-order) std::sort(res.begin(), res.end(), [&](const Attr * a, const Attr * b) { std::string_view sa = symbols[a->name], sb = symbols[b->name]; return sa < sb; diff --git a/lix/libexpr/nixexpr.cc b/lix/libexpr/nixexpr.cc index 3c137bd94..abfb629d8 100644 --- a/lix/libexpr/nixexpr.cc +++ b/lix/libexpr/nixexpr.cc @@ -116,6 +116,8 @@ void ExprAttrs::addBindingsToJSON(JSON & out, const SymbolTable & symbols) const typedef const decltype(attrs)::value_type * Attr; std::vector sorted; for (auto & i : attrs) sorted.push_back(&i); + // NOTE: this sort uses a total order, so the iteration over pointers is not an issue + // NOLINTNEXTLINE(bugprone-nondeterministic-pointer-iteration-order) std::sort(sorted.begin(), sorted.end(), [&](Attr a, Attr b) { std::string_view sa = symbols[a->first], sb = symbols[b->first]; return sa < sb; diff --git a/lix/libmain/shared.cc b/lix/libmain/shared.cc index 28629bc3a..1474b5409 100644 --- a/lix/libmain/shared.cc +++ b/lix/libmain/shared.cc @@ -95,6 +95,8 @@ try { std::vector willSubstituteSorted = {}; std::for_each(willSubstitute.begin(), willSubstitute.end(), [&](const StorePath &p) { willSubstituteSorted.push_back(&p); }); + // NOTE: this sort uses a total order, so the iteration over pointers is not an issue + // NOLINTNEXTLINE(bugprone-nondeterministic-pointer-iteration-order) std::sort(willSubstituteSorted.begin(), willSubstituteSorted.end(), [](const StorePath *lhs, const StorePath *rhs) { if (lhs->name() == rhs->name()) diff --git a/lix/libstore/gc.cc b/lix/libstore/gc.cc index 9169efcc6..28c032c35 100644 --- a/lix/libstore/gc.cc +++ b/lix/libstore/gc.cc @@ -18,6 +18,7 @@ #include #include #include +#include #include #include diff --git a/misc/rapidcheck-gen-hpp.patch b/misc/rapidcheck-gen-hpp.patch new file mode 100644 index 000000000..c8bdc52fd --- /dev/null +++ b/misc/rapidcheck-gen-hpp.patch @@ -0,0 +1,13 @@ +diff --git i/include/rapidcheck/Gen.hpp w/include/rapidcheck/Gen.hpp +index 0c48004..2eb143f 100644 +--- i/include/rapidcheck/Gen.hpp ++++ w/include/rapidcheck/Gen.hpp +@@ -2,6 +2,8 @@ + + #include + ++#include ++ + #include "rapidcheck/detail/Any.h" + #include "rapidcheck/detail/ImplicitParam.h" + #include "rapidcheck/gen/detail/GenerationHandler.h" diff --git a/package.nix b/package.nix index fb86ce844..dc41050a3 100644 --- a/package.nix +++ b/package.nix @@ -287,7 +287,9 @@ stdenv.mkDerivation (finalAttrs: { # musl doesn't support fibers, and we can't detect this with meson alone. ++ lib.optional hostPlatform.isMusl "-Ddisable-fibers=true" ++ lib.optional (finalAttrs.dontBuild && !lintInsteadOfBuild) "-Denable-build=false" - ++ lib.optional lintInsteadOfBuild "-Dlix-clang-tidy-checks-path=${lix-clang-tidy}/lib/liblix-clang-tidy.so" + ++ lib.optional lintInsteadOfBuild "-Dlix-clang-tidy-checks-path=${lix-clang-tidy}/lib/liblix-clang-tidy.${ + if hostPlatform.isDarwin then "dylib" else "so" + }" ++ [ # mesonConfigurePhase automatically passes -Dauto_features=enabled, # so we must explicitly enable or disable features that we are not passing @@ -383,7 +385,9 @@ stdenv.mkDerivation (finalAttrs: { checkInputs = [ gtest - rapidcheck + (rapidcheck.overrideAttrs (old: { + patches = (old.patches or [ ]) ++ [ ./misc/rapidcheck-gen-hpp.patch ]; + })) ]; propagatedBuildInputs = lib.optionals (!finalAttrs.dontBuild) maybePropagatedInputs;