Skip to content

Commit

Permalink
Added nix helper for running clang lints
Browse files Browse the repository at this point in the history
  • Loading branch information
HU90m committed Jun 8, 2024
1 parent 3fc5201 commit d64ead8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
39 changes: 35 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright lowRISC Contributors.
# SPDX-License-Identifier: Apache-2.0
{
description = "Sonata Software";
inputs = {
Expand All @@ -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 {
Expand All @@ -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";
};
};
Expand Down

0 comments on commit d64ead8

Please sign in to comment.