From d64ead8fb2a4fc7f75adf4042313535e6d12bc83 Mon Sep 17 00:00:00 2001 From: Hugo McNally Date: Sat, 8 Jun 2024 09:17:39 +0100 Subject: [PATCH] Added nix helper for running clang lints --- .gitmodules | 3 ++- flake.nix | 39 +++++++++++++++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/.gitmodules b/.gitmodules index b4abde1..bc2d860 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,4 +4,5 @@ branch = sonata [submodule "display_drivers"] path = display_drivers - url = https://github.com/engdoreis/display_drivers.git + url = https://github.com/engdoreis/display_drivers + branch = main diff --git a/flake.nix b/flake.nix index 761a57b..b08d61b 100644 --- a/flake.nix +++ b/flake.nix @@ -1,3 +1,5 @@ +# Copyright lowRISC Contributors. +# SPDX-License-Identifier: Apache-2.0 { description = "Sonata Software"; inputs = { @@ -24,6 +26,32 @@ lrPkgs = lowrisc-nix.outputs.packages.${system}; sonataSystemPkgs = sonata-system.outputs.packages.${system}; cheriotPkgs = lowrisc-nix.outputs.devShells.${system}.cheriot.nativeBuildInputs; + + getExe = pkgs.lib.getExe; + + clang-lint = let + srcGlob = "{compartments,library}/*"; + in + pkgs.writeShellApplication { + name = "clang-lint"; + runtimeInputs = with lrPkgs; [llvm_cheriot]; + text = '' + set +u + case "$1" in + check) + clang-format --dry-run --Werror ${srcGlob} + clang-tidy -export-fixes=tidy_fixes -quiet ${srcGlob} + [ ! -f tidy_fixes ] # fail if the fixes file exists + echo "No warnings outside of dependancies." + ;; + fix) + clang-format -i ${srcGlob} + clang-tidy -fix ${srcGlob} + ;; + *) echo "Available subcommands are 'check' and 'fix'.";; + esac + ''; + }; in { formatter = pkgs.alejandra; devShells = rec { @@ -41,14 +69,17 @@ ''; }; }; + apps.clang-lint = { + type = "app"; + program = getExe clang-lint; + }; checks = { - clang-format = pkgs.stdenv.mkDerivation { - name = "clang-format-check"; + clang-checks = pkgs.stdenvNoCC.mkDerivation { + name = "clang-checks"; src = ./.; dontBuild = true; doCheck = true; - nativeBuildInputs = with lrPkgs; [llvm_cheriot]; - checkPhase = "clang-format --dry-run --Werror {compartments,library}/*"; + checkPhase = "${getExe clang-lint} check"; installPhase = "mkdir $out"; }; };