From 278529098918f2bdcf43526e584c102c78097b43 Mon Sep 17 00:00:00 2001 From: Patrick Georgi Date: Wed, 27 Feb 2019 22:02:04 +0100 Subject: util/lint: Fix clang-format test and enable it by default git diff needed to emit diffs without prefix (e.g. a/ and b/) for clang-format-diff to be able to work. Also require that the test succeeds, but note that it only runs on trees whitelisted in $(top)/.clang-format-scope. Change-Id: I7e9a32eb9281b5cb0b45506a206500fd1d315372 Signed-off-by: Patrick Georgi Reviewed-on: https://review.coreboot.org/c/coreboot/+/31654 Tested-by: build bot (Jenkins) Reviewed-by: Martin Roth --- util/lint/lint-022-clang-format | 34 ------------------------------ util/lint/lint-stable-022-clang-format | 38 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 34 deletions(-) delete mode 100755 util/lint/lint-022-clang-format create mode 100755 util/lint/lint-stable-022-clang-format (limited to 'util/lint') diff --git a/util/lint/lint-022-clang-format b/util/lint/lint-022-clang-format deleted file mode 100755 index 932d9c0d50..0000000000 --- a/util/lint/lint-022-clang-format +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/sh -# This file is part of the coreboot project. -# -# Copyright (C) 2018 Google Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; version 2 of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# -# DESCR: Run clang-format on white-listed directories - -LC_ALL=C export LC_ALL - -# until we require this by default, we need a list of opted-in directories -if [ ! -f .clang-format-scope ]; then - exit 0 -fi - -files_to_check=$(git log HEAD~..HEAD --format= --name-only $(cat .clang-format-scope) |grep "\.[ch]$") - -# nothing to do -if [ -z "$files_to_check" ]; then - exit 0 -fi - -if [ $(clang-format $files_to_check | wc -l) -gt 0 ]; then - git diff HEAD~..HEAD -- $files_to_check | clang-format-diff -fi diff --git a/util/lint/lint-stable-022-clang-format b/util/lint/lint-stable-022-clang-format new file mode 100755 index 0000000000..bd662e472f --- /dev/null +++ b/util/lint/lint-stable-022-clang-format @@ -0,0 +1,38 @@ +#!/bin/sh +# This file is part of the coreboot project. +# +# Copyright (C) 2018 Google Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# +# DESCR: Run clang-format on white-listed directories + +LC_ALL=C export LC_ALL + +# until we require this by default, we need a list of opted-in directories +if [ ! -f .clang-format-scope ]; then + exit 0 +fi + +files_to_check=$(git log HEAD~..HEAD --format= --name-only $(cat .clang-format-scope) |grep "\.[ch]$") + +# nothing to do +if [ -z "$files_to_check" ]; then + exit 0 +fi + +if [ $(clang-format $files_to_check | wc -l) -gt 0 ]; then + if [ "$(git diff --no-prefix HEAD~..HEAD -- $files_to_check | clang-format-diff)" != "" ]; then + echo "Coding style mismatch. The following patch fixes it:" + git diff --no-prefix HEAD~..HEAD -- $files_to_check | clang-format-diff + exit 1 + fi +fi -- cgit v1.2.3