public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Carlos O'Donell <carlos@redhat.com>
To: libc-alpha@sourceware.org,
	Noah Goldstein <goldstein.w.n@gmail.com>,
	Adhemerval Zanella <adhemerval.zanella@linaro.org>,
	Florian Weimer <fweimer@redhat.com>
Cc: Carlos O'Donell <carlos@redhat.com>
Subject: [PATCH 1/1] Add lint-makefiles Makefile linting test.
Date: Fri, 19 May 2023 08:13:54 -0400	[thread overview]
Message-ID: <20230519121354.704395-2-carlos@redhat.com> (raw)
In-Reply-To: <20230519121354.704395-1-carlos@redhat.com>

We add a `make check` test that lints all Makefiles in the source
directory of the glibc build. This linting test ensures that the
lines in all Makefiles will be sorted correctly as developers
creates patches.

The test adds ~3s to a test run.

No regressions on x86_64 and i686.
---
 Makefile                  |  6 +++++
 scripts/lint-makefiles.sh | 47 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+)
 create mode 100644 scripts/lint-makefiles.sh

diff --git a/Makefile b/Makefile
index 224c792185..93e5a60af9 100644
--- a/Makefile
+++ b/Makefile
@@ -564,6 +564,12 @@ $(objpfx)check-wrapper-headers.out: scripts/check-wrapper-headers.py $(headers)
 	  --generated $(common-generated) > $@; $(evaluate-test)
 endif # $(headers)
 
+# Lint all Makefiles including this one to check for correctly sorted lines.
+tests-special += $(objpfx)lint-makefiles.out
+$(objpfx)lint-makefiles.out: scripts/lint-makefiles.sh
+	$(SHELL) $< "$(PYTHON)" "$(srcdir)" > $@ ; \
+	$(evaluate-test)
+
 define summarize-tests
 @grep -E -v '^(PASS|XFAIL):' $(objpfx)$1 || true
 @echo "Summary of test results$2:"
diff --git a/scripts/lint-makefiles.sh b/scripts/lint-makefiles.sh
new file mode 100644
index 0000000000..cf63a4ab9f
--- /dev/null
+++ b/scripts/lint-makefiles.sh
@@ -0,0 +1,47 @@
+#!/bin/bash
+# Copyright (C) 2023 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+
+# The GNU C Library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+
+# The GNU C Library 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
+# Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public
+# License along with the GNU C Library; if not, see
+# <https://www.gnu.org/licenses/>.
+
+# This script checks to see that all Makefiles in the source tree
+# conform to the sorted variable rules as defined by:
+# scripts/sort-makefile-lines.py.
+# Any difference is an error and should be corrected e.g. the lines
+# reordered to sort correctly.
+# The intent with this check is to ensure that changes made by
+# developers match the expected format for the project.
+
+set -e
+export LC_ALL=C
+
+tmpfile="$(mktemp)"
+
+cleanup () {
+  rm -f -- "$tmpfile"
+}
+
+trap cleanup 0
+
+PYTHON=$1
+srcdir=$2
+
+echo "Linting Makefiles:"
+echo "Check: Are all lines sorted correctly?"
+for mfile in `find "$srcdir" -name Makefile`; do
+    echo "$mfile"
+    $PYTHON "${srcdir}scripts/sort-makefile-lines.py" < "$mfile" > "$tmpfile"
+    diff -q "$mfile" "$tmpfile"
+done
-- 
2.40.0


  reply	other threads:[~2023-05-19 12:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-19 12:13 [PATCH 0/1] Add linting checks to 'make check' Carlos O'Donell
2023-05-19 12:13 ` Carlos O'Donell [this message]
2023-05-19 12:35   ` [PATCH 1/1] Add lint-makefiles Makefile linting test Alejandro Colomar
2023-05-19 12:45     ` Florian Weimer
2023-05-23 14:05       ` Carlos O'Donell
2023-05-30 12:10       ` Carlos O'Donell
2023-05-19 16:55 ` [PATCH 0/1] Add linting checks to 'make check' Joseph Myers
2023-05-23 12:54   ` Carlos O'Donell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230519121354.704395-2-carlos@redhat.com \
    --to=carlos@redhat.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=fweimer@redhat.com \
    --cc=goldstein.w.n@gmail.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).